Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Support override of ALLOWED_URI_SCHEMES with html4.allowedUriSchemes #2033

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/com/google/caja/plugin/html-sanitizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,13 +812,17 @@ var html = (function(html4) {

var ALLOWED_URI_SCHEMES = /^(?:https?|geo|mailto|sms|tel)$/i;

function getAllowedUriSchemes() {
return html4.allowedUriSchemes || ALLOWED_URI_SCHEMES;
}

function safeUri(uri, effect, ltype, hints, naiveUriRewriter) {
if (!naiveUriRewriter) { return null; }
try {
var parsed = URI.parse('' + uri);
if (parsed) {
if (!parsed.hasScheme() ||
ALLOWED_URI_SCHEMES.test(parsed.getScheme())) {
getAllowedUriSchemes().test(parsed.getScheme())) {
var safe = naiveUriRewriter(parsed, effect, ltype, hints);
return safe ? safe.toString() : null;
}
Expand Down
6 changes: 5 additions & 1 deletion src/com/google/caja/plugin/sanitizecss.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ var sanitizeMediaQuery = undefined;

var ALLOWED_URI_SCHEMES = /^(?:https?|geo|mailto|sms|tel)$/i;

function getAllowedUriSchemes() {
return html4.allowedUriSchemes || ALLOWED_URI_SCHEMES;
}

function resolveUri(baseUri, uri) {
if (baseUri) {
return URI.utils.resolve(baseUri, uri);
Expand All @@ -102,7 +106,7 @@ var sanitizeMediaQuery = undefined;
function safeUri(uri, prop, naiveUriRewriter) {
if (!naiveUriRewriter) { return null; }
var parsed = ('' + uri).match(URI_SCHEME_RE);
if (parsed && (!parsed[1] || ALLOWED_URI_SCHEMES.test(parsed[1]))) {
if (parsed && (!parsed[1] || getAllowedUriSchemes().test(parsed[1]))) {
return naiveUriRewriter(uri, prop);
} else {
return null;
Expand Down