Skip to content

Commit 958ae24

Browse files
committed
Swift: Update the qhelp and example.
1 parent e74eccd commit 958ae24

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

swift/ql/src/queries/Security/CWE-116/BadTagFilter.qhelp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
<overview>
77
<p>
8-
It is possible to match some single HTML tags using regular expressions (parsing general HTML using
9-
regular expressions is impossible). However, if the regular expression is not written well it might
8+
It is possible to match some single HTML tags using regular expressions (parsing general HTML using
9+
regular expressions is impossible). However, if the regular expression is not written well it might
1010
be possible to circumvent it, which can lead to cross-site scripting or other security issues.
1111
</p>
1212
<p>
1313
Some of these mistakes are caused by browsers having very forgiving HTML parsers, and
14-
will often render invalid HTML containing syntax errors.
14+
will often render invalid HTML containing syntax errors.
1515
Regular expressions that attempt to match HTML should also recognize tags containing such syntax errors.
1616
</p>
1717
</overview>
@@ -28,17 +28,17 @@ likely to handle corner cases correctly than a custom implementation.
2828
The following example attempts to filters out all <code>&lt;script&gt;</code> tags.
2929
</p>
3030

31-
<sample src="examples/BadTagFilter.rb" />
31+
<sample src="examples/BadTagFilterBad.swift" />
3232

3333
<p>
34-
The above sanitizer does not filter out all <code>&lt;script&gt;</code> tags.
34+
The above sanitizer does not filter out all <code>&lt;script&gt;</code> tags.
3535
Browsers will not only accept <code>&lt;/script&gt;</code> as script end tags, but also tags such as <code>&lt;/script foo="bar"&gt;</code> even though it is a parser error.
36-
This means that an attack string such as <code>&lt;script&gt;alert(1)&lt;/script foo="bar"&gt;</code> will not be filtered by
36+
This means that an attack string such as <code>&lt;script&gt;alert(1)&lt;/script foo="bar"&gt;</code> will not be filtered by
3737
the function, and <code>alert(1)</code> will be executed by a browser if the string is rendered as HTML.
3838
</p>
3939

4040
<p>
41-
Other corner cases include that HTML comments can end with <code>--!&gt;</code>,
41+
Other corner cases include that HTML comments can end with <code>--!&gt;</code>,
4242
and that HTML tag names can contain upper case characters.
4343
</p>
4444
</example>
@@ -50,5 +50,3 @@ and that HTML tag names can contain upper case characters.
5050
<li>stackoverflow.com: <a href="https://stackoverflow.com/questions/25559999/why-arent-browsers-strict-about-html">Why aren't browsers strict about HTML?</a>.</li>
5151
</references>
5252
</qhelp>
53-
54-

swift/ql/src/queries/Security/CWE-116/BadTagFilter.swift

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let script_tag_regex = /<script[^>]*>.*<\/script>/
2+
3+
var old_html = ""
4+
while (html != old_html) {
5+
old_html = html
6+
html.replace(script_tag_regex, with: "")
7+
}
8+
9+
...

0 commit comments

Comments
 (0)