Skip to content

Commit a69d885

Browse files
committed
Implement stricter checks for xss on text fields
1 parent 53bca8e commit a69d885

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hmcts/ccd-case-ui-toolkit",
3-
"version": "7.2.46",
3+
"version": "7.2.46-2673",
44
"engines": {
55
"node": ">=18.19.0"
66
},

projects/ccd-case-ui-toolkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hmcts/ccd-case-ui-toolkit",
3-
"version": "7.2.46",
3+
"version": "7.2.46-2763",
44
"engines": {
55
"node": ">=18.19.0"
66
},

projects/ccd-case-ui-toolkit/src/lib/shared/services/form/form-validators.service.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export class FormValidatorsService {
1010
private static readonly CUSTOM_VALIDATED_TYPES: FieldTypeEnum[] = [
1111
'Date', 'MoneyGBP', 'Label', 'JudicialUser'
1212
];
13+
1314
private static readonly DEFAULT_INPUT_TEXT = 'text';
1415
private static readonly DEFAULT_INPUT_TEXTAREA = 'textAreas';
1516

@@ -62,11 +63,25 @@ export class FormValidatorsService {
6263
}
6364

6465
public static markDownPatternValidator(): ValidatorFn {
65-
const pattern = /(\[[^\]]{0,500}\]\([^)]{0,500}\)|!\[[^\]]{0,500}\]\([^)]{0,500}\)|<img[^>]{0,500}>|<a[^>]{0,500}>.*?<\/a>)/;
66+
const aTagPattern = /<a\b[^>]*(>|$)/i;
67+
const pattern = /(\[[^\]]{0,500}\]\([^)]{0,500}\)|!\[[^\]]{0,500}\]\([^)]{0,500}\)|<img\b[^>]{0,500}(?:>|$))/i;
68+
const hasDangerousAttrs = /\bon\w+\s*=/i;
69+
const hasJsProtocol = /(?:src|href)\s*=\s*["']?\s*javascript:/i;
6670

6771
return (control: AbstractControl): ValidationErrors | null => {
6872
const value = control?.value?.toString().trim();
69-
return (value && pattern.test(value)) ? { markDownPattern: {} } : null;
73+
if (
74+
value &&
75+
(
76+
pattern.test(value) ||
77+
aTagPattern.test(value) ||
78+
hasDangerousAttrs.test(value) ||
79+
hasJsProtocol.test(value)
80+
)
81+
) {
82+
return { markDownPattern: {} };
83+
}
84+
return null;
7085
};
7186
}
7287

0 commit comments

Comments
 (0)