Skip to content

Commit

Permalink
add test cases for sanitization hardening
Browse files Browse the repository at this point in the history
  • Loading branch information
koczkatamas committed Jun 26, 2019
1 parent 08389db commit 506704a
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/specs/run-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ function runSpecs(title, dir, showCompletionTable, options) {
spec.options = Object.assign({}, options, (spec.options || {}));
const example = (spec.example ? ' example ' + spec.example : '');
const passFail = (spec.shouldFail ? 'fail' : 'pass');
if (spec.options.sanitizerRemoveHtml)
spec.options.sanitizer = () => '';
(spec.only ? fit : it)('should ' + passFail + example, () => {
const before = process.hrtime();
if (spec.shouldFail) {
Expand All @@ -40,3 +42,4 @@ runSpecs('CommonMark', './commonmark', true, { headerIds: false });
runSpecs('Original', './original', false, { gfm: false });
runSpecs('New', './new');
runSpecs('ReDOS', './redos');
runSpecs('Security', './security', false, { silent: true /* no deprecation warnings */ });
6 changes: 6 additions & 0 deletions test/specs/security/sanitizer_bypass.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<p>AAA&lt;script&gt; &lt;img &lt;script&gt; src=x onerror=alert(1) /&gt;BBB</p>

<p>AAA&lt;sometag&gt; &lt;img &lt;sometag&gt; src=x onerror=alert(1)BBB</p>

<p>&lt;a&gt;a2&lt;a2t&gt;a2&lt;/a&gt; b &lt;c&gt;c&lt;/c&gt; d</p>
<h1 id="text"><img src="URL" alt="text"></h1>
9 changes: 9 additions & 0 deletions test/specs/security/sanitizer_bypass.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
sanitize: true
---
AAA<script> <img <script> src=x onerror=alert(1) />BBB

AAA<sometag> <img <sometag> src=x onerror=alert(1)BBB

<a>a2<a2t>a2</a> b <c>c</c> d
# ![text](URL)
2 changes: 2 additions & 0 deletions test/specs/security/sanitizer_bypass_remove_generic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<p>a2a2 b c d</p>
<h1 id="text"><img src="URL" alt="text"></h1>
6 changes: 6 additions & 0 deletions test/specs/security/sanitizer_bypass_remove_generic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
sanitize: true
sanitizerRemoveHtml: true
---
<a>a2<a2t>a2</a> b <c>c</c> d
# ![text](URL)
1 change: 1 addition & 0 deletions test/specs/security/sanitizer_bypass_remove_script.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>AAA</p>
5 changes: 5 additions & 0 deletions test/specs/security/sanitizer_bypass_remove_script.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
sanitize: true
sanitizerRemoveHtml: true
---
AAA<script> <img <script> src=x onerror=alert(1) />BBB
1 change: 1 addition & 0 deletions test/specs/security/sanitizer_bypass_remove_tag.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>AAA &lt;img src=x onerror=alert(1)BBB</p>
5 changes: 5 additions & 0 deletions test/specs/security/sanitizer_bypass_remove_tag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
sanitize: true
sanitizerRemoveHtml: true
---
AAA<sometag> <img <sometag> src=x onerror=alert(1)BBB

0 comments on commit 506704a

Please sign in to comment.