@stacksjs/sanitizer 0.2.413 → 0.2.415
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/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
2
|
+
var T={allowedTags:["p","br","strong","em","u","span","h1","h2","h3","h4","h5","h6","ul","ol","li","code","pre"],allowedAttributes:{"*":["class","id"]},allowedSchemes:["http","https","mailto"],allowDataAttributes:!1,allowAriaAttributes:!0,stripTags:!0,allowComments:!1},g={allowedTags:["p","br","strong","em","u","span","div","h1","h2","h3","h4","h5","h6","ul","ol","li","a","img","code","pre","blockquote","table","thead","tbody","tr","th","td"],allowedAttributes:{"*":["class","id"],a:["class","id","href","title","target","rel"],img:["class","id","src","alt","title","width","height"],td:["class","id","colspan","rowspan","align"],th:["class","id","colspan","rowspan","align","scope"]},allowedSchemes:["http","https","mailto","tel"],allowDataAttributes:!1,allowAriaAttributes:!0,stripTags:!0,allowComments:!1},z={allowedTags:["p","br","strong","em","u","span","div","section","article","aside","h1","h2","h3","h4","h5","h6","ul","ol","li","dl","dt","dd","a","img","figure","figcaption","code","pre","kbd","samp","var","blockquote","q","cite","table","thead","tbody","tfoot","tr","th","td","caption","del","ins","sub","sup","abbr","address","time","hr","video","audio","source","track"],allowedAttributes:{"*":["class","id","title"],a:["class","id","href","title","target","rel"],img:["class","id","src","srcset","alt","title","width","height","loading"],video:["class","id","src","width","height","controls","preload","poster"],audio:["class","id","src","controls","preload"],source:["src","type"],track:["src","kind","srclang","label"],td:["class","id","colspan","rowspan","align"],th:["class","id","colspan","rowspan","align","scope"],time:["class","id","datetime"],abbr:["class","id","title"]},allowedSchemes:["http","https","mailto","tel","data"],allowDataAttributes:!0,allowAriaAttributes:!0,stripTags:!0,allowComments:!1},x={allowedTags:["p","br","strong","em","span","h1","h2","h3","h4","h5","h6","ul","ol","li","a","img","code","pre","blockquote","table","thead","tbody","tr","th","td","del","ins","hr","input"],allowedAttributes:{"*":["class","id"],a:["class","id","href","title"],img:["class","id","src","alt","title"],code:["class"],td:["align"],th:["align","scope"],input:["type","checked","disabled"]},allowedSchemes:["http","https","mailto"],allowDataAttributes:!1,allowAriaAttributes:!1,stripTags:!0,allowComments:!1};function p(e){switch(e){case"strict":return T;case"basic":return g;case"relaxed":return z;case"markdown":return x;default:return g}}var k={allowedTags:[],allowedAttributes:{},allowedSchemes:["http","https","mailto"],allowDataAttributes:!1,allowAriaAttributes:!0,stripTags:!0,allowComments:!1},v=["script","iframe","object","embed","applet","base","link","meta","style"],C=["href","src","action","formaction","data","poster","cite","background","longdesc"],P=/^on\w+/i;function h(e,s){return m(e,s).html}function m(e,s){let r=typeof s==="string"?p(s):{...k,...s},t=[],a=[],i=e,l=!1;if(!r.allowComments){let n=/<!--[\s\S]*?-->/g;if(n.test(i))i=i.replace(n,""),l=!0}let c=/<(\/?)([a-zA-Z][\w-]*)([^>]*)>/g;return i=i.replace(c,(n,R,w,b)=>{let o=w.toLowerCase();if(v.includes(o)){if(!t.includes(o))t.push(o);return l=!0,r.stripTags?"":f(n)}let S=r.allowedTags||[];if(S.length>0&&!S.includes(o)){if(!t.includes(o))t.push(o);return l=!0,r.stripTags?"":f(n)}if(R)return n;let d=D(b,o,r,a);if(d!==b)l=!0;if(r.transformTag){let A=O(d),u=r.transformTag(o,A);if(u===null){if(!t.includes(o))t.push(o);return l=!0,""}if(u.tagName!==o||JSON.stringify(u.attributes)!==JSON.stringify(A))return l=!0,q(u.tagName,u.attributes)}return`<${w}${d}>`}),{html:i,modified:l,removedTags:t.length>0?t:void 0,removedAttributes:a.length>0?a:void 0}}function D(e,s,r,t){if(!e.trim())return e;let a=O(e),i={};for(let[l,c]of Object.entries(a)){let n=l.toLowerCase();if(P.test(n)){if(!t.includes(n))t.push(n);continue}if(!E(n,s,r)){if(!t.includes(n))t.push(n);continue}if(C.includes(n)){if(!L(c,r)){if(!t.includes(n))t.push(n);continue}}if(n==="style"&&r.allowedStyles)i[l]=j(c,r.allowedStyles);else i[l]=c}return y(i)}function E(e,s,r){let t=r.allowedAttributes;if(!t)return!1;if(e.startsWith("data-"))return r.allowDataAttributes||!1;if(e.startsWith("aria-"))return r.allowAriaAttributes||!1;if(Array.isArray(t))return t.includes(e);if(t[s]?.includes(e))return!0;if(t["*"]?.includes(e))return!0;return!1}function L(e,s){if(s.urlValidator)return s.urlValidator(e);let t=e.trim().toLowerCase().replace(/[\s\x00-\x1F]/g,""),a=["javascript:","data:text/html","vbscript:","file:"];for(let i of a)if(t.startsWith(i))return!1;if(s.allowedSchemes&&s.allowedSchemes.length>0){if(!t.includes(":"))return!0;if(!s.allowedSchemes.some((l)=>t.startsWith(`${l}:`)))return!1}return!0}function j(e,s){let r=e.split(";").filter((a)=>a.trim()),t=[];for(let a of r){let i=a.indexOf(":");if(i===-1)continue;let l=a.substring(0,i).trim().toLowerCase(),c=a.substring(i+1).trim();if(s.includes(l)){if(!c.toLowerCase().includes("javascript:")&&!c.toLowerCase().includes("expression("))t.push(`${l}: ${c}`)}}return t.join("; ")}function O(e){let s={},r=/([\w-]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s>]+)))?/g,t;while(t=r.exec(e)){let a=t[1],i=t[2]||t[3]||t[4]||"";s[a]=i}return s}function y(e){let s=[];for(let[r,t]of Object.entries(e))if(t==="")s.push(r);else{let a=t.replace(/"/g,""");s.push(`${r}="${a}"`)}return s.length>0?` ${s.join(" ")}`:""}function q(e,s){return`<${e}${y(s)}>`}function f(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function I(e,s){return!m(e,s).modified}function U(e){return e.replace(/<[^>]*>/g,"")}function W(e){return f(e)}var K=h;export{g as basic,K as default,W as escape,p as getPreset,I as isSafe,x as markdown,z as relaxed,h as sanitize,m as sanitizeWithInfo,T as strict,U as stripTags};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/sanitizer",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.415",
|
|
5
5
|
"description": "A fast, native Bun-powered HTML sanitizer with DOMPurify-like features. Protection against XSS and malicious content.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|