url-sanitizer 0.7.5 → 0.7.6

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 CHANGED
@@ -35,7 +35,9 @@ import urlSanitizer, {
35
35
  ## sanitizeURL(url, opt)
36
36
 
37
37
  Sanitize the given URL.
38
- * `blob`, `data` and `file` schemes must be explicitly allowed.
38
+ * `data` and `file` schemes must be explicitly allowed.
39
+ * `blob` URLs are not currently allowed and will return `null`.
40
+ See [Figure out how to sanitize the blob URL · Issue #4](https://github.com/asamuzaK/urlSanitizer/issues/4)
39
41
 
40
42
  ### Parameters
41
43
 
@@ -61,7 +63,7 @@ console.log(decodeURIComponent(res1));
61
63
  const res2 = await sanitizeURL('data:text/html,<div><script>alert(1);</script></div><p onclick="alert(2)"></p>', {
62
64
  allow: ['data']
63
65
  })
64
- // -> 'data:text/html,%3Cdiv%3E%3C/div%3E%3Cp%3E%3C/p%3E'
66
+ // => 'data:text/html,%3Cdiv%3E%3C/div%3E%3Cp%3E%3C/p%3E'
65
67
 
66
68
  console.log(decodeURIComponent(res2));
67
69
  // => 'data:text/html,<div></div><p></p>'
@@ -1613,6 +1613,7 @@ var REG_NUM_REF = /&#(x(?:00)?[\dA-F]{2}|0?\d{1,3});?/ig;
1613
1613
  var REG_SCHEME = /^[a-z][\da-z+\-.]*$/;
1614
1614
  var REG_SCHEME_CUSTOM = /^(?:ext|web)\+[a-z]+$/;
1615
1615
  var REG_SCRIPT = /(?:java|vb)script/;
1616
+ var REG_SCRIPT_BLOB = /(?:java|vb)script|blob/;
1616
1617
  var REG_URL_ENC = /^%[\dA-F]{2}$/i;
1617
1618
  var REG_URL_ENC_AMP = /%26/g;
1618
1619
  var getURLEncodedString = (str) => {
@@ -1881,7 +1882,7 @@ var URLSanitizer = class extends URISchemes {
1881
1882
  for (let item of items) {
1882
1883
  if (isString(item)) {
1883
1884
  item = item.trim();
1884
- if (!REG_SCRIPT.test(item)) {
1885
+ if (!REG_SCRIPT_BLOB.test(item)) {
1885
1886
  if (super.has(item)) {
1886
1887
  schemeMap.set(item, true);
1887
1888
  } else {
@@ -1905,7 +1906,7 @@ var URLSanitizer = class extends URISchemes {
1905
1906
  for (let item of items) {
1906
1907
  if (isString(item)) {
1907
1908
  item = item.trim();
1908
- if (!REG_SCRIPT.test(item)) {
1909
+ if (!REG_SCRIPT_BLOB.test(item)) {
1909
1910
  if (super.has(item)) {
1910
1911
  schemeMap.set(item, true);
1911
1912
  } else {
@@ -1966,7 +1967,7 @@ var URLSanitizer = class extends URISchemes {
1966
1967
  const decodedData = parseURLEncodedNumCharRef(parsedData);
1967
1968
  const { protocol: dataScheme } = new URL(decodedData.trim());
1968
1969
  const dataSchemeParts = dataScheme.replace(REG_END_COLON, "").split("+");
1969
- if (dataSchemeParts.some((s) => REG_SCRIPT.test(s))) {
1970
+ if (dataSchemeParts.some((s) => REG_SCRIPT_BLOB.test(s))) {
1970
1971
  urlToSanitize = "";
1971
1972
  }
1972
1973
  } catch (e) {
@@ -2047,7 +2048,7 @@ var URLSanitizer = class extends URISchemes {
2047
2048
  *
2048
2049
  * @param {string} url - URL
2049
2050
  * @param {object} opt - options
2050
- * @returns {ParsedURL} - result with enhanced props based on URL API
2051
+ * @returns {ParsedURL} - result with additional props based on URL API
2051
2052
  */
2052
2053
  parse(url, opt) {
2053
2054
  if (!isString(url)) {