url-sanitizer 1.0.2 → 2.0.0
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 +8 -27
- package/dist/url-sanitizer-wo-dompurify.min.js +1 -1
- package/dist/url-sanitizer-wo-dompurify.min.js.map +3 -3
- package/dist/url-sanitizer.min.js +3 -3
- package/dist/url-sanitizer.min.js.map +3 -3
- package/package.json +10 -10
- package/src/mjs/constant.js +0 -2
- package/src/mjs/sanitizer.js +9 -17
- package/types/mjs/constant.d.ts +0 -2
- package/types/mjs/sanitizer.d.ts +0 -4
package/package.json
CHANGED
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
},
|
|
22
22
|
"types": "types/index.d.ts",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"dompurify": "^3.0.
|
|
24
|
+
"dompurify": "^3.0.11",
|
|
25
25
|
"jsdom": "^24.0.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@babel/eslint-parser": "^7.
|
|
29
|
-
"@babel/plugin-syntax-import-assertions": "^7.
|
|
28
|
+
"@babel/eslint-parser": "^7.24.1",
|
|
29
|
+
"@babel/plugin-syntax-import-assertions": "^7.24.1",
|
|
30
30
|
"@types/dompurify": "^3.0.5",
|
|
31
31
|
"@types/jsdom": "^21.1.6",
|
|
32
32
|
"c8": "^9.1.0",
|
|
@@ -34,19 +34,19 @@
|
|
|
34
34
|
"commander": "^12.0.0",
|
|
35
35
|
"copyfiles": "^2.4.1",
|
|
36
36
|
"csvtojson": "^2.0.10",
|
|
37
|
-
"esbuild": "^0.20.
|
|
38
|
-
"eslint": "^8.
|
|
37
|
+
"esbuild": "^0.20.2",
|
|
38
|
+
"eslint": "^8.57.0",
|
|
39
39
|
"eslint-config-standard": "^17.1.0",
|
|
40
40
|
"eslint-plugin-import": "^2.29.1",
|
|
41
|
-
"eslint-plugin-jsdoc": "^48.2.
|
|
42
|
-
"eslint-plugin-regexp": "^2.
|
|
41
|
+
"eslint-plugin-jsdoc": "^48.2.1",
|
|
42
|
+
"eslint-plugin-regexp": "^2.3.0",
|
|
43
43
|
"eslint-plugin-unicorn": "^51.0.1",
|
|
44
44
|
"http-server": "^14.1.1",
|
|
45
45
|
"mocha": "^10.3.0",
|
|
46
46
|
"npm-run-all": "^4.1.5",
|
|
47
47
|
"sinon": "^17.0.1",
|
|
48
|
-
"typescript": "^5.
|
|
49
|
-
"undici": "^6.
|
|
48
|
+
"typescript": "^5.4.3",
|
|
49
|
+
"undici": "^6.10.1"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "npm run include && npm run tsc && npm run lint && npm test && npm run copy && npm run bundle",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"test-bdd": "http-server ./ -c-1 -o test/bdd/url-sanitizer.test.html",
|
|
66
66
|
"tsc": "node modules/index clean --dir=types -i && npx tsc"
|
|
67
67
|
},
|
|
68
|
-
"version": "
|
|
68
|
+
"version": "2.0.0"
|
|
69
69
|
}
|
package/src/mjs/constant.js
CHANGED
|
@@ -22,6 +22,4 @@ export const REG_SCHEME_EXT = /^(?:ext|web)\+[a-z]+$/;
|
|
|
22
22
|
export const REG_SCRIPT = /(?:java|vb)script/;
|
|
23
23
|
export const REG_SCRIPT_BLOB = /(?:java|vb)script|blob/;
|
|
24
24
|
export const REG_TAG_QUOT = /%(?:2[27]|3[CE])|[<>"']/;
|
|
25
|
-
export const REG_TAG_QUOT_ENC_G = /%(?:2[27]|3[CE])/g;
|
|
26
|
-
export const REG_TAG_QUOT_SPACE_G = /[<>"'\s]/g;
|
|
27
25
|
export const REG_URL_ENC = /^%[\dA-F]{2}$/i;
|
package/src/mjs/sanitizer.js
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
import { domPurify } from './dompurify.js';
|
|
7
7
|
import { getType, isString } from './common.js';
|
|
8
8
|
import {
|
|
9
|
-
createDataURLFromBlob, escapeURLEncodedHTMLChars,
|
|
10
|
-
|
|
9
|
+
createDataURLFromBlob, escapeURLEncodedHTMLChars, parseBase64,
|
|
10
|
+
parseURLEncodedNumCharRef, URISchemes
|
|
11
11
|
} from './uri-util.js';
|
|
12
12
|
import {
|
|
13
13
|
HEX, REG_DATA_URL, REG_DATA_URL_B64, REG_DATA_URL_G, REG_MIME_DOM,
|
|
14
|
-
REG_SCRIPT_BLOB, REG_TAG_QUOT
|
|
14
|
+
REG_SCRIPT_BLOB, REG_TAG_QUOT
|
|
15
15
|
} from './constant.js';
|
|
16
16
|
|
|
17
17
|
/* typedef */
|
|
@@ -119,7 +119,6 @@ export class URLSanitizer extends URISchemes {
|
|
|
119
119
|
* @param {Array.<string>} [opt.allow] - array of allowed schemes
|
|
120
120
|
* @param {Array.<string>} [opt.deny] - array of denied schemes
|
|
121
121
|
* @param {Array.<string>} [opt.only] - array of specific schemes to allow
|
|
122
|
-
* @param {boolean} [opt.remove] - remove tag and/or quote and the rest
|
|
123
122
|
* @returns {?string} - sanitized URL
|
|
124
123
|
*/
|
|
125
124
|
sanitize(url, opt) {
|
|
@@ -127,7 +126,7 @@ export class URLSanitizer extends URISchemes {
|
|
|
127
126
|
this.#nest = 0;
|
|
128
127
|
throw new Error('Data URLs nested too deeply.');
|
|
129
128
|
}
|
|
130
|
-
const { allow, deny, only
|
|
129
|
+
const { allow, deny, only } = opt ?? {};
|
|
131
130
|
const schemeMap = new Map([
|
|
132
131
|
['blob', false],
|
|
133
132
|
['data', false],
|
|
@@ -269,20 +268,16 @@ export class URLSanitizer extends URISchemes {
|
|
|
269
268
|
} else {
|
|
270
269
|
finalize = true;
|
|
271
270
|
}
|
|
272
|
-
if (!isDataUrl &&
|
|
271
|
+
if (!isDataUrl && REG_TAG_QUOT.test(urlToSanitize)) {
|
|
273
272
|
const item = REG_TAG_QUOT.exec(urlToSanitize);
|
|
274
273
|
const { index } = item;
|
|
275
|
-
urlToSanitize =
|
|
274
|
+
urlToSanitize =
|
|
275
|
+
urlToSanitize.substring(0, index).replace(/[?&]$/, '');
|
|
276
276
|
}
|
|
277
277
|
if (urlToSanitize) {
|
|
278
|
-
sanitizedUrl =
|
|
279
|
-
.replace(
|
|
280
|
-
.replace(/%26/g, escapeURLEncodedHTMLChars);
|
|
278
|
+
sanitizedUrl =
|
|
279
|
+
urlToSanitize.replace(/%26/g, escapeURLEncodedHTMLChars);
|
|
281
280
|
if (finalize) {
|
|
282
|
-
if (!isDataUrl) {
|
|
283
|
-
sanitizedUrl = sanitizedUrl
|
|
284
|
-
.replace(REG_TAG_QUOT_ENC_G, escapeURLEncodedHTMLChars);
|
|
285
|
-
}
|
|
286
281
|
this.#nest = 0;
|
|
287
282
|
}
|
|
288
283
|
} else {
|
|
@@ -305,7 +300,6 @@ export class URLSanitizer extends URISchemes {
|
|
|
305
300
|
* @param {Array.<string>} [opt.allow] - array of allowed schemes
|
|
306
301
|
* @param {Array.<string>} [opt.deny] - array of denied schemes
|
|
307
302
|
* @param {Array.<string>} [opt.only] - array of specific schemes to allow
|
|
308
|
-
* @param {boolean} [opt.remove] - remove tag and/or quote and the rest
|
|
309
303
|
* @returns {ParsedURL} - result with additional props based on URL API
|
|
310
304
|
*/
|
|
311
305
|
parse(url, opt) {
|
|
@@ -384,7 +378,6 @@ const urlSanitizer = new URLSanitizer();
|
|
|
384
378
|
* @param {Array.<string>} [opt.allow] - array of allowed schemes
|
|
385
379
|
* @param {Array.<string>} [opt.deny] - array of denied schemes
|
|
386
380
|
* @param {Array.<string>} [opt.only] - array of specific schemes to allow
|
|
387
|
-
* @param {boolean} [opt.remove] - remove tag and/or quote and the rest
|
|
388
381
|
* @returns {Promise.<?string>} - sanitized URL
|
|
389
382
|
*/
|
|
390
383
|
export const sanitizeURL = async (url, opt = {
|
|
@@ -447,7 +440,6 @@ export const sanitizeURL = async (url, opt = {
|
|
|
447
440
|
* @param {Array.<string>} [opt.allow] - array of allowed schemes
|
|
448
441
|
* @param {Array.<string>} [opt.deny] - array of denied schemes
|
|
449
442
|
* @param {Array.<string>} [opt.only] - array of specific schemes to allow
|
|
450
|
-
* @param {boolean} [opt.remove] - remove tag and/or quote and the rest
|
|
451
443
|
* @returns {?string} - sanitized URL
|
|
452
444
|
*/
|
|
453
445
|
export const sanitizeURLSync = (url, opt) => {
|
package/types/mjs/constant.d.ts
CHANGED
|
@@ -14,6 +14,4 @@ export const REG_SCHEME_EXT: RegExp;
|
|
|
14
14
|
export const REG_SCRIPT: RegExp;
|
|
15
15
|
export const REG_SCRIPT_BLOB: RegExp;
|
|
16
16
|
export const REG_TAG_QUOT: RegExp;
|
|
17
|
-
export const REG_TAG_QUOT_ENC_G: RegExp;
|
|
18
|
-
export const REG_TAG_QUOT_SPACE_G: RegExp;
|
|
19
17
|
export const REG_URL_ENC: RegExp;
|
package/types/mjs/sanitizer.d.ts
CHANGED
|
@@ -5,13 +5,11 @@ export class URLSanitizer extends URISchemes {
|
|
|
5
5
|
allow?: Array<string>;
|
|
6
6
|
deny?: Array<string>;
|
|
7
7
|
only?: Array<string>;
|
|
8
|
-
remove?: boolean;
|
|
9
8
|
}): string | null;
|
|
10
9
|
parse(url: string, opt?: {
|
|
11
10
|
allow?: Array<string>;
|
|
12
11
|
deny?: Array<string>;
|
|
13
12
|
only?: Array<string>;
|
|
14
|
-
remove?: boolean;
|
|
15
13
|
}): ParsedURL;
|
|
16
14
|
#private;
|
|
17
15
|
}
|
|
@@ -19,13 +17,11 @@ export function sanitizeURL(url: string, opt?: {
|
|
|
19
17
|
allow?: Array<string>;
|
|
20
18
|
deny?: Array<string>;
|
|
21
19
|
only?: Array<string>;
|
|
22
|
-
remove?: boolean;
|
|
23
20
|
}): Promise<string | null>;
|
|
24
21
|
export function sanitizeURLSync(url: string, opt?: {
|
|
25
22
|
allow?: Array<string>;
|
|
26
23
|
deny?: Array<string>;
|
|
27
24
|
only?: Array<string>;
|
|
28
|
-
remove?: boolean;
|
|
29
25
|
}): string | null;
|
|
30
26
|
export function parseURL(url: string): Promise<ParsedURL>;
|
|
31
27
|
export function parseURLSync(url: string): ParsedURL;
|