Debian Codegraph @

dist/ext/hx-csp.min.js

raw symbols SCIP
1 (()=>{let t=null,e=null,n=null;function r(t){return n?.attributeValue(t,"hx-nonce")}function o(e){if(!t)return!1;let n=r(e);return(n===t||!function(t,e){let n=[];for(let e of[...t.attributes])(e.name.startsWith("hx-")||htmx.config.prefix&&e.name.startsWith(htmx.config.prefix))&&(n.push(e.name),t.removeAttribute(e.name));if(!n.length)return!1;let r=t.tagName?.toLowerCase(),o=t.id?`#${t.id}`:"",c=null==e?"missing-nonce":"nonce-mismatch";return console.error(`htmx: [hx-csp] blocked <${r}${o}> — ${null==e?"no hx-nonce attribute":"nonce mismatch (possible injection)"}`,{elt:t,reason:c}),htmx.trigger(t,"htmx:security:strip",{reason:c,stripped:n}),!0}(e,n))&&void 0}function c(t){return t?.match(/(?:script-src|default-src)[^;]*'nonce-([^']+)'/i)?.[1]??null}function i(e,n,r=t){let o=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return e.replace(new RegExp(`(nonce=)(["']?)${o}\\2`,"gi"),(t,e,n)=>r?`${e}${n}${r}${n}`:"")}htmx.registerExtension("hx-csp",{init:o=>{if(n=o,t=document.querySelector("script[nonce]")?.nonce||null,!t)return void console.error("htmx: [hx-csp] no page nonce found — blocking all htmx. Add a nonce to your script tags.");try{e="undefined"!=typeof trustedTypes?trustedTypes.createPolicy("htmx",{createHTML:t=>t,createScript:t=>t}):{createHTML:t=>t,createScript:t=>t}}catch(e){return console.error("htmx: [hx-csp] TrustedTypes policy 'htmx' blocked — add 'htmx' to trusted-types CSP directive. Blocking all htmx."),void(t=null)}let c=0,i=Function,l=Object.getPrototypeOf(async function(){}).constructor;function a(n){return function(...o){let a=o.pop();return{call:(s,...u)=>{if(r(s)!==t){let t=s?.tagName?.toLowerCase(),e=s?.id?`#${s.id}`:"";return console.error(`htmx: [hx-csp] blocked eval on <${t}${e}> — nonce mismatch`,{elt:s}),void htmx.trigger(s,"htmx:security:violation",{reason:"nonce-mismatch-at-eval"})}if(htmx.config.safeEval){let r="__htmx_eval_"+ ++c,i=document.createElement("script");i.nonce=t,i.textContent=e.createScript(`window.${r} = ${n?"async ":""}function(${o.join(",")}) { ${a} }`),document.head.appendChild(i),i.remove();let l=window[r].call(s,...u);return delete window[r],l}return new(n?l:i)(...o,a).call(s,...u)}}}}o.initSecurity(e,a(!1),a(!0))},htmx_before_init:o,htmx_before_on_init:o,htmx_after_request:(n,r)=>{if(!t)return!1;let o=r.ctx;o.text=i(o.text,t,"");let l=o?.response?.raw?.url;if(!l)return;try{if(new URL(l).origin!==location.origin)return}catch(t){return}let a=c(o?.response?.headers?.get("Content-Security-Policy"))??function(t){let n=Document.parseHTMLUnsafe(e.createHTML(t)),r=n.head?.querySelector('meta[http-equiv="Content-Security-Policy"]');return c(r?.content)}(o?.text);a&&a!==t&&(o.text=i(o.text,a))},htmx_config_request:(e,n)=>{if(!t)return!1;let o=n.ctx?.request?.action;if(o&&/^(js|javascript):/i.test(o))return console.error(`htmx: [hx-csp] blocked js:/javascript: action URL on <${e.tagName.toLowerCase()}${e.id?"#"+e.id:""}>`,{elt:e}),htmx.trigger(e,"htmx:security:violation",{reason:"javascript-url",action:o,ctx:n.ctx}),n.cancelled=!0,!1;let c=n.ctx?.sourceEvent?.submitter;if(e._htmx?.boosted&&c?.getAttribute("formaction")&&r(c)!==t){let t=c?.id?`#${c.id}`:"";return console.error(`htmx: [hx-csp] blocked boosted form — unnonced submitter${t} overrode formaction`),htmx.trigger(e,"htmx:security:violation",{reason:"unnonced-submitter",submitter:c,ctx:n.ctx}),n.cancelled=!0,!1}}})})();