Skip to content

Commit

Permalink
Fix: addressed a bypass on jsdom 22 when noframes tag is allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
cure53 committed Jun 29, 2023
1 parent f464d95 commit a01c083
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 59 deletions.
33 changes: 20 additions & 13 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.

33 changes: 20 additions & 13 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.

33 changes: 20 additions & 13 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.

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.

34 changes: 20 additions & 14 deletions src/purify.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function createDOMPurify(window = getGlobal()) {
DOMPurify.isSupported =
typeof getParentNode === 'function' &&
implementation &&
typeof implementation.createHTMLDocument !== 'undefined' &&
implementation.createHTMLDocument !== undefined &&
documentMode !== 9;

const {
Expand Down Expand Up @@ -1051,9 +1051,12 @@ function createDOMPurify(window = getGlobal()) {
return true;
}

/* Make sure that older browsers don't get fallback-tag mXSS */
if (
(tagName === 'noscript' || tagName === 'noembed') &&
regExpTest(/<\/no(script|embed)/i, currentNode.innerHTML)
(tagName === 'noscript' ||
tagName === 'noembed' ||
tagName === 'noframes') &&
regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)
) {
_forceRemove(currentNode);
return true;
Expand Down Expand Up @@ -1165,12 +1168,11 @@ function createDOMPurify(window = getGlobal()) {
) {
// This attribute is safe
/* Check for binary attributes */
// eslint-disable-next-line no-negated-condition
} else if (!value) {
} else if (value) {
return false;
} else {
// Binary attributes are safe at this point
/* Anything else, presume unsafe, do not add it back */
} else {
return false;
}

return true;
Expand Down Expand Up @@ -1286,14 +1288,19 @@ function createDOMPurify(window = getGlobal()) {
/* Namespaces are not yet supported, see https://bugs.chromium.org/p/chromium/issues/detail?id=1305293 */
} else {
switch (trustedTypes.getAttributeType(lcTag, lcName)) {
case 'TrustedHTML':
case 'TrustedHTML': {
value = trustedTypesPolicy.createHTML(value);
break;
case 'TrustedScriptURL':
}

case 'TrustedScriptURL': {
value = trustedTypesPolicy.createScriptURL(value);
break;
default:
}

default: {
break;
}
}
}
}
Expand Down Expand Up @@ -1373,14 +1380,13 @@ function createDOMPurify(window = getGlobal()) {

/* Stringify, in case dirty is an object */
if (typeof dirty !== 'string' && !_isNode(dirty)) {
// eslint-disable-next-line no-negated-condition
if (typeof dirty.toString !== 'function') {
throw typeErrorCreate('toString is not a function');
} else {
if (typeof dirty.toString === 'function') {
dirty = dirty.toString();
if (typeof dirty !== 'string') {
throw typeErrorCreate('dirty is not a string, aborting');
}
} else {
throw typeErrorCreate('toString is not a function');
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function unconstruct(func) {

/* Add properties to a lookup table */
export function addToSet(set, array, transformCaseFunc) {
transformCaseFunc = transformCaseFunc ? transformCaseFunc : stringToLowerCase;
transformCaseFunc = transformCaseFunc ?? stringToLowerCase;
if (setPrototypeOf) {
// Make 'in' and truthy checks like Boolean(set.constructor)
// independent of any properties defined on Object.prototype.
Expand Down

0 comments on commit a01c083

Please sign in to comment.