Skip to content

Commit 5f766bc

Browse files
committed
See #761
feat: added ALLOW_SELF_CLOSE_IN_ATTR tag test: added test case
1 parent 90326ef commit 5f766bc

10 files changed

Lines changed: 47 additions & 9 deletions

File tree

dist/purify.cjs.js

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.cjs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.es.js

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.js

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/purify.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ function createDOMPurify(window = getGlobal()) {
239239
/* Decide if unknown protocols are okay */
240240
let ALLOW_UNKNOWN_PROTOCOLS = false;
241241

242+
/* Decide if self-closing tags in attributes are allowed.
243+
* Usually removed due to a mXSS issue in jQuery 3.0 */
244+
let ALLOW_SELF_CLOSE_IN_ATTR = true;
245+
242246
/* Output should be safe for common template engines.
243247
* This means, DOMPurify removes data attributes, mustaches and ERB
244248
*/
@@ -468,6 +472,7 @@ function createDOMPurify(window = getGlobal()) {
468472
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
469473
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
470474
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
475+
ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
471476
SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
472477
WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
473478
RETURN_DOM = cfg.RETURN_DOM || false; // Default false
@@ -1241,7 +1246,7 @@ function createDOMPurify(window = getGlobal()) {
12411246
}
12421247

12431248
/* Work around a security issue in jQuery 3.0 */
1244-
if (regExpTest(/\/>/i, value)) {
1249+
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
12451250
_removeAttribute(name, currentNode);
12461251
continue;
12471252
}

test/test-suite.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,21 @@
133133
);
134134
}
135135
);
136+
QUnit.test('Config-Flag tests: ALLOW_SELF_CLOSE_IN_ATTR', function (assert) {
137+
// ALLOW_SELF_CLOSE_IN_ATTR
138+
assert.equal(
139+
DOMPurify.sanitize('<a href="#" class="foo <br/>">abc</a>', {
140+
ALLOW_SELF_CLOSE_IN_ATTR: false,
141+
}),
142+
'<a href="#">abc</a>'
143+
);
144+
assert.equal(
145+
DOMPurify.sanitize('<a href="#" class="foo <br/>">abc</a>', {
146+
ALLOW_SELF_CLOSE_IN_ATTR: true,
147+
}),
148+
'<a class="foo <br/>" href="#">abc</a>'
149+
);
150+
});
136151
QUnit.test('Config-Flag tests: ALLOW_DATA_ATTR', function (assert) {
137152
// ALLOW_DATA_ATTR
138153
assert.equal(

0 commit comments

Comments
 (0)