Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cure53/DOMPurify
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3.0.1
Choose a base ref
...
head repository: cure53/DOMPurify
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3.0.2
Choose a head ref
  • 17 commits
  • 24 files changed
  • 8 contributors

Commits on Feb 26, 2023

  1. Merge pull request #775 from cure53/3.x

    Get main up to date from 3.x
    cure53 authored Feb 26, 2023
    Copy the full SHA
    ae8f7f7 View commit details

Commits on Mar 14, 2023

  1. build(deps): bump webpack from 5.68.0 to 5.76.1

    Bumps [webpack](https://github.com/webpack/webpack) from 5.68.0 to 5.76.1.
    - [Release notes](https://github.com/webpack/webpack/releases)
    - [Commits](webpack/webpack@v5.68.0...v5.76.1)
    
    ---
    updated-dependencies:
    - dependency-name: webpack
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Mar 14, 2023
    Copy the full SHA
    f6bf5f8 View commit details

Commits on Mar 15, 2023

  1. Merge pull request #781 from cure53/dependabot/npm_and_yarn/webpack-5…

    ….76.1
    
    build(deps): bump webpack from 5.68.0 to 5.76.1
    cure53 authored Mar 15, 2023
    Copy the full SHA
    bcb0f7f View commit details

Commits on Mar 18, 2023

  1. Add sms to default allowed URI

    Kiwka committed Mar 18, 2023
    Copy the full SHA
    7402282 View commit details

Commits on Mar 23, 2023

  1. Merge pull request #783 from Kiwka/main

    Add sms scheme to URI allowed by default
    cure53 authored Mar 23, 2023
    Copy the full SHA
    3c1e7ff View commit details

Commits on Mar 27, 2023

  1. Copy the full SHA
    45cba8c View commit details

Commits on Mar 30, 2023

  1. fix tests

    - remove unneeded rollup commonjs plugin
    - convert expect.js to ES Module and rename it to expect.mjs
    - dynamically import expect.mjs on NodeJS so it can run with JSDOM
    buzinas committed Mar 30, 2023
    Copy the full SHA
    e92ffcc View commit details

Commits on Apr 4, 2023

  1. Copy the full SHA
    0b2327d View commit details
  2. Merge pull request #786 from buzinas/bump-browsers-versions

    Bump browsers versions to support for…of and let/const
    cure53 authored Apr 4, 2023
    Copy the full SHA
    14ed0bb View commit details

Commits on Apr 5, 2023

  1. Update tags.js

    duyhai94 authored Apr 5, 2023
    Copy the full SHA
    972d449 View commit details
  2. Merge pull request #788 from duyhai94/haicd194

    add tag mprescripts to mathMl
    cure53 authored Apr 5, 2023
    Copy the full SHA
    dcb9ebe View commit details

Commits on Apr 13, 2023

  1. fix: ensure ALLOWED_URI_REGEXP is reset

    At 490c2ef, the `ALLOWED_URI_REGEXP` was set without properly resetting it for subsequent sanitize calls.
    mukilane committed Apr 13, 2023
    Copy the full SHA
    1c63c4b View commit details
  2. Merge pull request #790 from mukilane/main

    fix: ensure ALLOWED_URI_REGEXP is reset
    cure53 authored Apr 13, 2023
    Copy the full SHA
    7fa8b97 View commit details

Commits on Apr 14, 2023

  1. chore: preparing 3.0.2 release

    cure53 committed Apr 14, 2023
    Copy the full SHA
    5532856 View commit details
  2. Merge pull request #791 from cure53/main

    Merged main into 3.x for upcoming release
    cure53 authored Apr 14, 2023
    Copy the full SHA
    6b0b394 View commit details
  3. Copy the full SHA
    a3c3907 View commit details
  4. Merge pull request #793 from cure53/main

    chore: updated website version info
    cure53 authored Apr 14, 2023
    Copy the full SHA
    671167b View commit details
10 changes: 5 additions & 5 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -4,11 +4,11 @@
"@babel/preset-env",
{
"targets": {
"chrome": 22,
"firefox": 15,
"opera": 31,
"safari": 8,
"edge": 13
"chrome": 51,
"firefox": 53,
"opera": 38,
"safari": 11,
"edge": 51
},
"modules": false
}
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

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 3.0.1.
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 **v3.0.2**.

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.

@@ -271,13 +271,13 @@ var clean = DOMPurify.sanitize(dirty, {ADD_URI_SAFE_ATTR: ['my-attr']});
* Control permitted attribute values
*/
// allow external protocol handlers in URL attributes (default is false, be careful, XSS risk)
// by default only http, https, ftp, ftps, tel, mailto, callto, cid and xmpp are allowed.
// by default only http, https, ftp, ftps, tel, mailto, callto, sms, cid and xmpp are allowed.
var clean = DOMPurify.sanitize(dirty, {ALLOW_UNKNOWN_PROTOCOLS: true});

// allow specific protocols handlers in URL attributes via regex (default is false, be careful, XSS risk)
// by default only http, https, ftp, ftps, tel, mailto, callto, cid and xmpp are allowed.
// Default RegExp: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i;
var clean = DOMPurify.sanitize(dirty, {ALLOWED_URI_REGEXP: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp|xxx):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i;});
// by default only http, https, ftp, ftps, tel, mailto, callto, sms, cid and xmpp are allowed.
// Default RegExp: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i;
var clean = DOMPurify.sanitize(dirty, {ALLOWED_URI_REGEXP: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|xxx):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i;});

/**
* Influence the return-type
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "DOMPurify",
"version": "3.0.1",
"version": "3.0.2",
"homepage": "https://github.com/cure53/DOMPurify",
"author": "Cure53 <info@cure53.de>",
"description": "A DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG",
665 changes: 250 additions & 415 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.

667 changes: 251 additions & 416 deletions dist/purify.es.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

665 changes: 250 additions & 415 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.

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.

183 changes: 62 additions & 121 deletions package-lock.json
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -64,7 +64,6 @@
"@babel/core": "^7.17.8",
"@babel/preset-env": "^7.16.11",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^21.0.3",
"@rollup/plugin-node-resolve": "^13.1.3",
"@rollup/plugin-replace": "^4.0.0",
"@types/dompurify": "^2.3.3",
@@ -98,7 +97,7 @@
},
"name": "dompurify",
"description": "DOMPurify is a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. It's written in JavaScript and works in all modern browsers (Safari, Opera (15+), Internet Explorer (10+), Firefox and Chrome - as well as almost anything else using Blink or WebKit). DOMPurify is written by security people who have vast background in web attacks and XSS. Fear not.",
"version": "3.0.1",
"version": "3.0.2",
"directories": {
"test": "test"
},
2 changes: 1 addition & 1 deletion src/purify.js
Original file line number Diff line number Diff line change
@@ -479,7 +479,7 @@ function createDOMPurify(window = getGlobal()) {
SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
IN_PLACE = cfg.IN_PLACE || false; // Default false
IS_ALLOWED_URI = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
IS_ALLOWED_URI = cfg.ALLOWED_URI_REGEXP || EXPRESSIONS.IS_ALLOWED_URI;
NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
if (
2 changes: 1 addition & 1 deletion src/regexp.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ 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(
/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
);
export const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
export const ATTR_WHITESPACE = seal(
1 change: 1 addition & 0 deletions src/tags.js
Original file line number Diff line number Diff line change
@@ -254,6 +254,7 @@ export const mathMl = freeze([
'mtr',
'munder',
'munderover',
'mprescripts',
]);

// Similarly to SVG, we want to know all MathML elements,
2 changes: 1 addition & 1 deletion test/fixtures/expect.js → test/fixtures/expect.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [
export default [
{
"title": "Don't remove data URIs from SVG images (see #205)",
"payload": "<svg><image id=\"v-146\" width=\"500\" height=\"500\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:href=\"data:image/svg+xml;utf8,%3Csvg%20viewBox%3D%220%200%20100%20100%22%20height%3D%22100%22%20width%3D%22100%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20data-name%3D%22Layer%201%22%20id%3D%22Layer_1%22%3E%0A%20%20%3Ctitle%3ECompute%3C%2Ftitle%3E%0A%20%20%3Cg%3E%0A%20%20%20%20%3Crect%20fill%3D%22%239d5025%22%20ry%3D%229.12%22%20rx%3D%229.12%22%20height%3D%2253%22%20width%3D%2253%22%20y%3D%2224.74%22%20x%3D%2223.5%22%3E%3C%2Frect%3E%0A%20%20%20%20%3Crect%20fill%3D%22%23f58536%22%20ry%3D%229.12%22%20rx%3D%229.12%22%20height%3D%2253%22%20width%3D%2253%22%20y%3D%2222.26%22%20x%3D%2223.5%22%3E%3C%2Frect%3E%0A%20%20%3C%2Fg%3E%0A%3C%2Fsvg%3E\" preserveratio=\"true\" style=\"border-color: rgb(51, 51, 51); box-sizing: border-box; color: rgb(51, 51, 51); cursor: move; font-family: sans-serif; font-size: 14px; line-height: 20px; outline-color: rgb(51, 51, 51); text-size-adjust: 100%; column-rule-color: rgb(51, 51, 51); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); -webkit-text-emphasis-color: rgb(51, 51, 51); -webkit-text-fill-color: rgb(51, 51, 51); -webkit-text-stroke-color: rgb(51, 51, 51); user-select: none; vector-effect: non-scaling-stroke;\"></image></svg>",
5 changes: 2 additions & 3 deletions test/jsdom-node-runner.js
Original file line number Diff line number Diff line change
@@ -20,6 +20,5 @@ qunitTap(QUnit, (line) => {
console.log(line);
});

require('./jsdom-node');

QUnit.load();
const startQUnit = require('./jsdom-node');
startQUnit().then(() => QUnit.load());
61 changes: 33 additions & 28 deletions test/jsdom-node.js
Original file line number Diff line number Diff line change
@@ -15,39 +15,44 @@ require('jquery')(window);

const sanitizeTestSuite = require('./test-suite');
const bootstrapTestSuite = require('./bootstrap-test-suite');
const tests = require('./fixtures/expect');
const xssTests = tests.filter((element) => /alert/.test(element.payload));

QUnit.assert.contains = function (actual, expected, message) {
const result = expected.indexOf(actual) > -1;
// Ref: https://api.qunitjs.com/assert/pushResult/
this.pushResult({
result: result,
actual: actual,
expected: expected,
message: message,
});
};
async function startQUnit() {
const { default: tests } = await import('./fixtures/expect.mjs');
const xssTests = tests.filter((element) => /alert/.test(element.payload));

QUnit.config.autostart = false;
QUnit.assert.contains = function (actual, expected, message) {
const result = expected.indexOf(actual) > -1;
// Ref: https://api.qunitjs.com/assert/pushResult/
this.pushResult({
result: result,
actual: actual,
expected: expected,
message: message,
});
};

QUnit.module('DOMPurify - bootstrap', bootstrapTestSuite(JSDOM));
QUnit.config.autostart = false;

QUnit.module('DOMPurify in jsdom');
QUnit.module('DOMPurify - bootstrap', bootstrapTestSuite(JSDOM));

if (!window.jQuery) {
console.warn('Unable to load jQuery');
}
QUnit.module('DOMPurify in jsdom');

const DOMPurify = createDOMPurify(window);
if (!DOMPurify.isSupported) {
console.error('Unexpected error returned by jsdom.env():', err, err.stack);
process.exit(1);
}
if (!window.jQuery) {
console.warn('Unable to load jQuery');
}

const DOMPurify = createDOMPurify(window);
if (!DOMPurify.isSupported) {
console.error('Unexpected error returned by jsdom.env():', err, err.stack);
process.exit(1);
}

window.alert = () => {
window.xssed = true;
};
window.alert = () => {
window.xssed = true;
};

sanitizeTestSuite(DOMPurify, window, tests, xssTests);
QUnit.start();
}

sanitizeTestSuite(DOMPurify, window, tests, xssTests);
QUnit.start();
module.exports = startQUnit;
2 changes: 0 additions & 2 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
const commonjs = require('@rollup/plugin-commonjs');
const includePaths = require('rollup-plugin-includepaths');
const rollupConfig = require('../rollup.config.js');
const customLaunchers =
require('./karma.custom-launchers.config.js').customLaunchers;
const browsers = require('./karma.custom-launchers.config.js').browsers;

rollupConfig.plugins.push(
commonjs(),
includePaths({
include: {
purify: 'dist/purify.js',
2 changes: 1 addition & 1 deletion test/purify.min.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'purify.min';
import './test-suite';
import tests from './fixtures/expect';
import tests from './fixtures/expect.mjs';

const xssTests = tests.filter(function (element) {
if (/alert/.test(element.payload)) {
2 changes: 1 addition & 1 deletion test/purify.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'purify';
import './test-suite';
import tests from './fixtures/expect';
import tests from './fixtures/expect.mjs';

const xssTests = tests.filter(function (element) {
if (/alert/.test(element.payload)) {
18 changes: 18 additions & 0 deletions test/test-suite.js
Original file line number Diff line number Diff line change
@@ -1416,6 +1416,21 @@
assert.equal(str, test.expected);
});
});
QUnit.test('Ensure ALLOWED_URI_REGEXP is not cached', function(assert) {
const
dirty = '<img src="https://different.com">',
expected = '<img src="https://different.com">';

assert.equal(DOMPurify.sanitize(dirty), expected);

// sanitize with a custom URI regexp
assert.equal(DOMPurify.sanitize('<img src="https://test.com">', {
ALLOWED_URI_REGEXP: /test\.com/i
}), '<img src="https://test.com">');

// ensure that the previous regexp does not affect future santize calls
assert.equal(DOMPurify.sanitize(dirty), expected);
});
QUnit.test(
'Avoid freeze when using tables and ALLOW_TAGS',
function (assert) {
@@ -2059,6 +2074,9 @@
// set the same hook
DOMPurify.addHook(entryPoint, hookFunction);
assert.equal(DOMPurify.sanitize(dirty), expected);

// cleanup hook
DOMPurify.removeHook(entryPoint);
});
};
});
4 changes: 2 additions & 2 deletions website/index.html
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>DOMPurify 3.0.1 "Lemon Juice"</title>
<title>DOMPurify 3.0.2 "Green Island"</title>
<script src="../dist/purify.min.js"></script>
<!-- we don't actually need it - just to demo and test the $(html) sanitation -->
<script src="//code.jquery.com/jquery-3.2.0.min.js"></script>
@@ -23,7 +23,7 @@
</script>
</head>
<body>
<h4>DOMPurify 3.0.1 "Lemon Juice"</h4>
<h4>DOMPurify 3.0.2 "Green Island"</h4>
<p>
<a href="http://badge.fury.io/js/dompurify" rel="nofollow"><img alt="npm version" src="https://badge.fury.io/js/dompurify.svg"></a>
<a target="_blank" rel="noopener noreferrer" href="https://github.com/cure53/DOMPurify/workflows/Build%20and%20Test/badge.svg?branch=main"><img src="https://github.com/cure53/DOMPurify/workflows/Build%20and%20Test/badge.svg?branch=main" alt="Build and Test"></a>