url-sanitizer 0.8.1 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/url-sanitizer.js +46 -33
- package/dist/url-sanitizer.js.map +2 -2
- package/dist/url-sanitizer.min.js +3 -3
- package/dist/url-sanitizer.min.js.map +2 -2
- package/package.json +1 -1
- package/src/mjs/uri-util.js +49 -35
package/README.md
CHANGED
package/dist/url-sanitizer.js
CHANGED
|
@@ -999,7 +999,7 @@ var require_purify = __commonJS({
|
|
|
999
999
|
});
|
|
1000
1000
|
|
|
1001
1001
|
// bundle/mjs/file-reader.js
|
|
1002
|
-
var FileReader = window
|
|
1002
|
+
var { FileReader } = window;
|
|
1003
1003
|
var fileReader = new FileReader();
|
|
1004
1004
|
|
|
1005
1005
|
// bundle/mjs/common.js
|
|
@@ -1976,8 +1976,8 @@ var URLSanitizer = class extends URISchemes {
|
|
|
1976
1976
|
parsedData = parseBase64(data);
|
|
1977
1977
|
}
|
|
1978
1978
|
try {
|
|
1979
|
-
const decodedData = parseURLEncodedNumCharRef(parsedData);
|
|
1980
|
-
const { protocol: dataScheme } = new URL(decodedData
|
|
1979
|
+
const decodedData = parseURLEncodedNumCharRef(parsedData).trim();
|
|
1980
|
+
const { protocol: dataScheme } = new URL(decodedData);
|
|
1981
1981
|
const dataSchemeParts = dataScheme.replace(REG_END_COLON, "").split("+");
|
|
1982
1982
|
if (dataSchemeParts.some((s) => REG_SCRIPT_BLOB.test(s))) {
|
|
1983
1983
|
urlToSanitize = "";
|
|
@@ -2117,46 +2117,59 @@ var parseURL = async (url) => {
|
|
|
2117
2117
|
const res = urlSanitizer.parse(url);
|
|
2118
2118
|
return res;
|
|
2119
2119
|
};
|
|
2120
|
-
var sanitizeURLSync = (url, opt) =>
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2120
|
+
var sanitizeURLSync = (url, opt) => {
|
|
2121
|
+
let res;
|
|
2122
|
+
if (urlSanitizer.verify(url)) {
|
|
2123
|
+
const { protocol } = new URL(url);
|
|
2124
|
+
if (protocol === "blob:") {
|
|
2125
|
+
URL.revokeObjectURL(url);
|
|
2126
|
+
} else {
|
|
2127
|
+
res = urlSanitizer.sanitize(url, opt ?? {
|
|
2128
|
+
allow: [],
|
|
2129
|
+
deny: [],
|
|
2130
|
+
only: []
|
|
2131
|
+
});
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
return res || null;
|
|
2135
|
+
};
|
|
2125
2136
|
var sanitizeURL = async (url, opt = {
|
|
2126
2137
|
allow: [],
|
|
2127
2138
|
deny: [],
|
|
2128
2139
|
only: []
|
|
2129
2140
|
}) => {
|
|
2130
|
-
const { protocol } = new URL(url);
|
|
2131
2141
|
let res;
|
|
2132
|
-
if (
|
|
2133
|
-
const {
|
|
2134
|
-
if (
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
data
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
if (
|
|
2143
|
-
if (
|
|
2144
|
-
only.
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
if (
|
|
2148
|
-
allow.
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2142
|
+
if (urlSanitizer.verify(url)) {
|
|
2143
|
+
const { protocol } = new URL(url);
|
|
2144
|
+
if (protocol === "blob:") {
|
|
2145
|
+
const { allow, deny, only } = opt;
|
|
2146
|
+
if (Array.isArray(allow) && allow.includes("blob") && !(Array.isArray(deny) && deny.includes("blob")) || Array.isArray(only) && only.includes("blob")) {
|
|
2147
|
+
let data;
|
|
2148
|
+
try {
|
|
2149
|
+
data = await fetch(url).then((r) => r.blob()).then(createDataURLFromBlob);
|
|
2150
|
+
} catch (e) {
|
|
2151
|
+
}
|
|
2152
|
+
if (data) {
|
|
2153
|
+
if (Array.isArray(only)) {
|
|
2154
|
+
if (!only.includes("data")) {
|
|
2155
|
+
only.push("data");
|
|
2156
|
+
}
|
|
2157
|
+
} else if (Array.isArray(allow)) {
|
|
2158
|
+
if (!allow.includes("data")) {
|
|
2159
|
+
allow.push("data");
|
|
2160
|
+
}
|
|
2161
|
+
if (Array.isArray(deny) && deny.includes("data")) {
|
|
2162
|
+
const i = deny.indexOf("data");
|
|
2163
|
+
deny.splice(i, 1);
|
|
2164
|
+
}
|
|
2153
2165
|
}
|
|
2166
|
+
res = urlSanitizer.sanitize(data, opt);
|
|
2154
2167
|
}
|
|
2155
|
-
res = urlSanitizer.sanitize(data, opt);
|
|
2156
2168
|
}
|
|
2169
|
+
URL.revokeObjectURL(url);
|
|
2170
|
+
} else {
|
|
2171
|
+
res = urlSanitizer.sanitize(url, opt);
|
|
2157
2172
|
}
|
|
2158
|
-
} else {
|
|
2159
|
-
res = urlSanitizer.sanitize(url, opt);
|
|
2160
2173
|
}
|
|
2161
2174
|
return res || null;
|
|
2162
2175
|
};
|