Skip to content

Commit 8cca9b0

Browse files
authored
Merge pull request #2393 from max-schaefer/js/improve-incomplete-sanitization-docs
Approved by mchammer01
2 parents 53576a4 + cb20de8 commit 8cca9b0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

javascript/ql/src/Security/CWE-116/IncompleteSanitization.qhelp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ likely to handle corner cases correctly than a custom implementation.
3535
Otherwise, make sure to use a regular expression with the <code>g</code> flag to ensure that
3636
all occurrences are replaced, and remember to escape backslashes if applicable.
3737
</p>
38+
<p>
39+
Note, however, that this is generally <i>not</i> sufficient for replacing multi-character strings:
40+
the <code>String.prototype.replace</code> method only performs one pass over the input string,
41+
and will not replace further instances of the string that result from earlier replacements.
42+
</p>
43+
<p>
44+
For example, consider the code snippet <code>s.replace(/\/\.\.\//g, "")</code>, which attempts
45+
to strip out all occurences of <code>/../</code> from <code>s</code>. This will not work as
46+
expected: for the string <code>/./.././</code>, for example, it will remove the single
47+
occurrence of <code>/../</code> in the middle, but the remainder of the string then becomes
48+
<code>/../</code>, which is another instance of the substring we were trying to remove.
49+
</p>
3850
</recommendation>
3951

4052
<example>

0 commit comments

Comments
 (0)