From 58877119d3607a3a93903c426d47e69f9fc1eb74 Mon Sep 17 00:00:00 2001 From: Glauber Date: Mon, 22 Jul 2019 17:57:30 -0300 Subject: [PATCH 1/3] Added URI restriction whitelist --- HtmlSanitizer.js | 29 ++++++++++++++++++++++------- tests.html | 4 ++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/HtmlSanitizer.js b/HtmlSanitizer.js index b696c23..ed37291 100644 --- a/HtmlSanitizer.js +++ b/HtmlSanitizer.js @@ -22,7 +22,9 @@ var HtmlSanitizer = new (function () { var schemaWhiteList_ = [ 'http:', 'https:', 'data:', 'm-files:', 'file:', 'ftp:' ]; //which "protocols" are allowed in "href", "src" etc - var uriAttributes_ = { 'href': true, 'action': true }; + var uriAttributes_ = { 'href': true, 'action': true, 'src': true }; + + var uriContainsWhiteList_ = [ ]; this.SanitizeHtml = function(input) { input = input.trim(); @@ -71,7 +73,7 @@ var HtmlSanitizer = new (function () { } else { if (uriAttributes_[attr.name]) { //if this is a "uri" attribute, that can have "javascript:" or something - if (attr.value.indexOf(":") > -1 && !startsWithAny(attr.value, schemaWhiteList_)) + if (attr.value.indexOf(":") > -1 && !URIstartsWithAndContains(attr.value)) continue; } newNode.setAttribute(attr.name, attr.value); @@ -95,17 +97,30 @@ var HtmlSanitizer = new (function () { .replace(/div>
\n