Skip to content

Commit

Permalink
Merge pull request #770 from cure53/3.x
Browse files Browse the repository at this point in the history
Merged 3.x into main
  • Loading branch information
cure53 committed Feb 13, 2023
2 parents baa1da9 + 5dcf2a0 commit 4fa50b7
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 18 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build-and-test.yml
Expand Up @@ -7,8 +7,6 @@ name: Build and Test
on:
push:
branches:
- main
- 2.x
- 3.x
pull_request:

Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -6,11 +6,11 @@

DOMPurify is a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG.

It's also very simple to use and get started with. DOMPurify was [started in February 2014](https://github.com/cure53/DOMPurify/commit/a630922616927373485e0e787ab19e73e3691b2b) and, meanwhile, has reached version 2.4.3 (and soon 3.0.0).
It's also very simple to use and get started with. DOMPurify was [started in February 2014](https://github.com/cure53/DOMPurify/commit/a630922616927373485e0e787ab19e73e3691b2b) and, meanwhile, has reached version 3.0.0.

DOMPurify is written in JavaScript and works in all modern browsers (Safari (10+), Opera (15+), Edge, Firefox and Chrome - as well as almost anything else using Blink, Gecko or WebKit). It doesn't break on MSIE or other legacy browsers. It simply does nothing.

**Note that [DOMPurify v2.4.3](https://github.com/cure53/DOMPurify/releases/tag/2.4.3) is the final version supporting MSIE. For important security updates compatible with MSIE, please use the [2.x branch](https://github.com/cure53/DOMPurify/tree/2.x).**
**Note that [DOMPurify v2.4.4](https://github.com/cure53/DOMPurify/releases/tag/2.4.4) is the final version supporting MSIE. For important security updates compatible with MSIE, please use the [2.x branch](https://github.com/cure53/DOMPurify/tree/2.x).**

Our automated tests cover [19 different browsers](https://github.com/cure53/DOMPurify/blob/main/test/karma.custom-launchers.config.js#L5) right now, more to come. We also cover Node.js v16.x, v17.x, v18.x and v19.x, running DOMPurify on [jsdom](https://github.com/jsdom/jsdom). Older Node versions are known to work as well, but hey... no guarantees.

Expand Down
10 changes: 8 additions & 2 deletions dist/purify.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.cjs.js.map

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions dist/purify.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.es.js.map

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions dist/purify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/purify.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/purify.min.js.map

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions src/purify.js
Expand Up @@ -235,6 +235,10 @@ function createDOMPurify(window = getGlobal()) {
/* Decide if unknown protocols are okay */
let ALLOW_UNKNOWN_PROTOCOLS = false;

/* Decide if self-closing tags in attributes are allowed.
* Usually removed due to a mXSS issue in jQuery 3.0 */
let ALLOW_SELF_CLOSE_IN_ATTR = true;

/* Output should be safe for common template engines.
* This means, DOMPurify removes data attributes, mustaches and ERB
*/
Expand Down Expand Up @@ -464,6 +468,7 @@ function createDOMPurify(window = getGlobal()) {
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
RETURN_DOM = cfg.RETURN_DOM || false; // Default false
Expand Down Expand Up @@ -1219,7 +1224,7 @@ function createDOMPurify(window = getGlobal()) {
}

/* Work around a security issue in jQuery 3.0 */
if (regExpTest(/\/>/i, value)) {
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
_removeAttribute(name, currentNode);
continue;
}
Expand Down Expand Up @@ -1462,7 +1467,7 @@ function createDOMPurify(window = getGlobal()) {
returnNode = body;
}

if (ALLOWED_ATTR.shadowroot) {
if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmod) {
/*
AdoptNode() is not used because internal state is not reset
(e.g. the past names map of a HTMLFormElement), this is safe
Expand Down
15 changes: 15 additions & 0 deletions test/test-suite.js
Expand Up @@ -133,6 +133,21 @@
);
}
);
QUnit.test('Config-Flag tests: ALLOW_SELF_CLOSE_IN_ATTR', function (assert) {
// ALLOW_SELF_CLOSE_IN_ATTR
assert.equal(
DOMPurify.sanitize('<a href="#" class="foo <br/>">abc</a>', {
ALLOW_SELF_CLOSE_IN_ATTR: false,
}),
'<a href="#">abc</a>'
);
assert.equal(
DOMPurify.sanitize('<a href="#" class="foo <br/>">abc</a>', {
ALLOW_SELF_CLOSE_IN_ATTR: true,
}),
'<a class="foo <br/>" href="#">abc</a>'
);
});
QUnit.test('Config-Flag tests: ALLOW_DATA_ATTR', function (assert) {
// ALLOW_DATA_ATTR
assert.equal(
Expand Down

0 comments on commit 4fa50b7

Please sign in to comment.