Skip to content

Commit

Permalink
fix(xss): test xss against original form (#200)
Browse files Browse the repository at this point in the history
fixes #183
  • Loading branch information
tripodsan authored Jun 30, 2020
1 parent ddc849c commit 56f6733
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/runtime/xss_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ function escapeJSToken(input) {

function sanitizeURL(url) {
try {
const decodedUrl = decodeURIComponent(url);
if (XRegExp(RELATIVE_REF).test(decodedUrl) || XRegExp(URI).test(decodedUrl)) {
if (XRegExp(RELATIVE_REF).test(url) || XRegExp(URI).test(url)) {
return url;
}
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions test/runtime_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const GLOBALS = {
url4: 'javascript:alert(String.fromCharCode(48))', // avoiding quotes
url5: '/foo', // rel part
url6: 'https://www.primordialsoup.life/image.png', // absolute url
url7: 'https://via.placeholder.com/1280x550&text=desktop%201280x550', // escaped url
breakAttr: '"><script>alert(0);</script>', // break out of html tag
eventHandler: 'alert(0)',
imgTag1: '<img src="javascript:alert(0)"/>',
Expand Down
9 changes: 5 additions & 4 deletions test/templates/xss.htl
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
<li>${xss.imgTag5}</li>
<li><img src="fake.jpg" onerror="${xss.eventHandler}"/></li>
</ul>
${xss.scriptTag1}
${xss.scriptTag2}
${xss.scriptTag3}
${xss.scriptTag1}
${xss.scriptTag2}
${xss.scriptTag3}
<form action="${xss.breakAttr}" onsubmit="${xss.eventHandler}">
<input name="test" value="${xss.breakAttr}"/>
</form>
<img src="${xss.url5}/bla.jpg" />
<img src="${xss.url6}" />
<img src="${xss.url7}" />
</body>
</html>
</html>
9 changes: 5 additions & 4 deletions test/templates/xss.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
<li><img></li>
<li><img src="fake.jpg" onerror="alert&#x28;0&#x29;"/></li>
</ul>



<form action="&quot;&gt;&lt;script&gt;alert&#x28;0&#x29;&#x3b;&lt;&#x2f;script&gt;" onsubmit="alert&#x28;0&#x29;">
<input name="test" value="&quot;&gt;&lt;script&gt;alert&#x28;0&#x29;&#x3b;&lt;&#x2f;script&gt;"/>
</form>
<img src="/foo/bla.jpg"/>
<img src="https://www.primordialsoup.life/image.png"/>
<img src="https://via.placeholder.com/1280x550&text=desktop%201280x550"/>
</body>
</html>
</html>
7 changes: 4 additions & 3 deletions test/templates/xss_unsafe.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
<li><img src="java&#x0A;script:alert(0)"/></li>
<li><img src="fake.jpg" onerror="alert&#x28;0&#x29;"/></li>
</ul>
<script>alert(0);</script>
<script src="http://do.not.serve/this.js"></script>
<script src="//do.not.serve/this.js"></script>
<script>alert(0);</script>
<script src="http://do.not.serve/this.js"></script>
<script src="//do.not.serve/this.js"></script>
<form action="&quot;&gt;&lt;script&gt;alert&#x28;0&#x29;&#x3b;&lt;&#x2f;script&gt;" onsubmit="alert&#x28;0&#x29;">
<input name="test" value="&quot;&gt;&lt;script&gt;alert&#x28;0&#x29;&#x3b;&lt;&#x2f;script&gt;"/>
</form>
<img src="/foo/bla.jpg"/>
<img src="https://www.primordialsoup.life/image.png"/>
<img src="https://via.placeholder.com/1280x550&text=desktop%201280x550"/>
</body>
</html>

0 comments on commit 56f6733

Please sign in to comment.