Skip to content

Commit

Permalink
fix: Addressed a conditional bypass pattern spotted by @Ry0taK
Browse files Browse the repository at this point in the history
fix: Addressed a conditional ReDoS issue spotted by @Ry0taK
  • Loading branch information
cure53 committed Mar 20, 2024
1 parent 51eea81 commit dce81a5
Show file tree
Hide file tree
Showing 11 changed files with 1,185 additions and 597 deletions.
586 changes: 390 additions & 196 deletions dist/purify.cjs.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

586 changes: 390 additions & 196 deletions dist/purify.es.mjs

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

586 changes: 390 additions & 196 deletions dist/purify.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 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.

6 changes: 6 additions & 0 deletions src/purify.js
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,12 @@ function createDOMPurify(window = getGlobal()) {
return true;
}

/* Remove any ocurrence of processing instructions */
if (currentNode.nodeType === 7) {
_forceRemove(currentNode);
return true;
}

/* Remove element if anything forbids its presence */
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
/* Check if we have a custom element to handle */
Expand Down
6 changes: 3 additions & 3 deletions src/regexp.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { seal } from './utils.js';

// eslint-disable-next-line unicorn/better-regex
export const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
export const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
export const TMPLIT_EXPR = seal(/\${[\w\W]*}/gm);
export const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*?\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
export const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*?%>/gm);
export const TMPLIT_EXPR = seal(/\${[\w\W]*?}/gm);
export const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/); // eslint-disable-line no-useless-escape
export const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
export const IS_ALLOWED_URI = seal(
Expand Down
2 changes: 1 addition & 1 deletion test/test-suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@
'<a>123{{45}}6}}<b><style><% <%alert(1) %></style>456</b></a>',
{ SAFE_FOR_TEMPLATES: true }
),
'<a> <b><style> </style>456</b></a>'
'<a> <b><style> </style>456</b></a>'
);
assert.equal(
DOMPurify.sanitize(
Expand Down

0 comments on commit dce81a5

Please sign in to comment.