This repository has been archived by the owner on Mar 23, 2022. It is now read-only.
Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix XSS on term-detailed web client view.
Previous behavior would render unencoded HTML in the view based on the term's definition-data. New behavior encodes HTML-tags in the DB-module via a separate sanitize module. However, be aware this functionality should be called prior to any markdown-related conversion in the future. Otherwise, the resulting HTML will be encoded. Related to #49. Also added a new gulp task for running TDD-style tests. And, incorporated this into the existing test-task.
- Loading branch information
1 parent
e008cdd
commit b31a022
Showing
4 changed files
with
46 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| export default class Sanitize { | ||
| constructor() { | ||
| } | ||
|
|
||
| /** | ||
| * This function replaces all instances of lt and gt with their | ||
| * HTML entity. | ||
| */ | ||
| htmlSanitize(html) { | ||
| html = html.replace(/</g, '<'); | ||
| html = html.replace(/>/g, '>'); | ||
|
|
||
| return html; | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import assert from 'assert' | ||
| import sut from './sanitize' | ||
|
|
||
| suite('Sanitize', function() { | ||
| suite('#htmlSanitize()', function() { | ||
| test('should encode all lt and gt-symbols', function() { | ||
| var result = new sut() | ||
| .htmlSanitize('<test></test>'); | ||
|
|
||
| assert.equal('<test></test>', result); | ||
| }); | ||
| }); | ||
| }); |