| 1677 | `,O),j=w===-1?K.length:w;if(K.slice(O,j).trim().startsWith("#"))return d("tengu_bash_security_check_triggered",{checkId:t9.QUOTED_NEWLINE}),{behavior:"ask",message:"Command contains a quoted newline followed by a #-prefixed line, which can hide arguments from line-based permission checks"}}}return{behavior:"passthrough",message:"No quoted newline-hash pattern"}}function My4(q){let{originalCommand:K}=q,_=new Set(["command","builtin","noglob","nocorrect"]),z=K.trim(),Y=z.split(/\s+/),$="";for(let A of Y){if(/^[A-Za-z_]\w*=/.test(A))continue;if(_.has(A))continue;$=A;break}if(x_z.has($))return d("tengu_bash_security_check_triggered",{checkId:t9.ZSH_DANGEROUS_COMMANDS,subId:1}),{behavior:"ask",message:`Command uses Zsh-specific '${$}' which can bypass security checks`};if($==="fc"&&/\s-\S*e/.test(z))return d("tengu_bash_security_check_triggered",{checkId:t9.ZSH_DANGEROUS_COMMANDS,subId:2}),{behavior:"ask",message:"Command uses 'fc -e' which can execute arbitrary commands via editor"};return{behavior:"passthrough",message:"No Zsh dangerous commands"}}function Po6(q){if(Xy4.test(q))return d("tengu_bash_security_check_triggered",{checkId:t9.CONTROL_CHARACTERS}),{behavior:"ask",message:"Command contains non-printable control characters that could be used to bypass security checks",isBashSecurityCheckForMisparsing:!0};if(Oo6(q))return{behavior:"ask",message:"Command contains single-quoted backslash pattern that could bypass security checks",isBashSecurityCheckForMisparsing:!0};let{processedCommand:K}=Dq6(q,{quotedOnly:!0}),_=q.split(" ")[0]||"",{withDoubleQuotes:z,fullyUnquoted:Y,unquotedKeepQuoteChars:$}=dN4(K,_==="jq"),A={originalCommand:q,baseCommand:_,unquotedContent:z,fullyUnquotedContent:cN4(Y),fullyUnquotedPreStrip:Y,unquotedKeepQuoteChars:$},O=[lN4,nN4,rN4,oN4];for(let J of O){let M=J(A);if(M.behavior==="allow")return{behavior:"passthrough",message:M.decisionReason?.type==="other"||M.decisionReason?.type==="safetyCheck"?M.decisionReason.reason:"Command allowed"};if(M.behavior!=="passthrough")return M.behavior==="ask"?{...M,isBashSecurityCheckForMisparsing:!0}:M}let w=new Set([NN8,VN8]),j=[aN4,Yy4,sN4,tN4,Hy4,Jy4,qy4,NN8,Ky4,_y4,eN4,VN8,$y4,Ay4,wy4,jy4,Oy4,My4,zy4],H=null;for(let J of j){let M=J(A);if(M.behavior==="ask"){if(w.has(J)){if(H===null)H=M;continue}return{...M,isBashSecurityCheckForMisparsing:!0}}}if(H!==null)return H;return{behavior:"passthrough",message:"Command passed all security checks"}}async function yN8(q,K){let z=(await Aw6.parse(q))?.getTreeSitterAnalysis()??null;if(!z)return Po6(q);if(Xy4.test(q))return d("tengu_bash_security_check_triggered",{checkId:t9.CONTROL_CHARACTERS}),{behavior:"ask",message:"Command contains non-printable control characters that could be used to bypass security checks",isBashSecurityCheckForMisparsing:!0};if(Oo6(q))return{behavior:"ask",message:"Command contains single-quoted backslash pattern that could bypass security checks",isBashSecurityCheckForMisparsing:!0};let{processedCommand:Y}=Dq6(q,{quotedOnly:!0}),$=q.split(" ")[0]||"",A=z.quoteContext,O=dN4(Y,$==="jq"),w=A.withDoubleQuotes,j=A.fullyUnquoted,H=A.unquotedKeepQuoteChars,J={originalCommand:q,baseCommand:$,unquotedContent:w,fullyUnquotedContent:cN4(j),fullyUnquotedPreStrip:j,unquotedKeepQuoteChars:H,treeSitter:z};if(!z.dangerousPatterns.hasHeredoc){if(A.fullyUnquoted!==O.fullyUnquoted||A.withDoubleQuotes!==O.withDoubleQuotes)if(K)K();else d("tengu_tree_sitter_security_divergence",{quoteContextDivergence:!0})}let M=[lN4,nN4,rN4,oN4];for(let D of M){let f=D(J);if(f.behavior==="allow")return{behavior:"passthrough",message:f.decisionReason?.type==="other"||f.decisionReason?.type==="safetyCheck"?f.decisionReason.reason:"Command allowed"};if(f.behavior!=="passthrough")return f.behavior==="ask"?{...f,isBashSecurityCheckForMisparsing:!0}:f}let X=new Set([NN8,VN8]),P=[aN4,Yy4,sN4,tN4,Hy4,Jy4,qy4,NN8,Ky4,_y4,eN4,VN8,$y4,Ay4,wy4,jy4,Oy4,My4,zy4],W=null;for(let D of P){let f=D(J);if(f.behavior==="ask"){if(X.has(D)){if(W===null)W=f;continue}return{...f,isBashSecurityCheckForMisparsing:!0}}}if(W!==null)return W;return{behavior:"passthrough",message:"Command passed all security checks"}}var rm1,b_z,x_z,t9,p_z,g_z,Xy4;var EN8=y(()=>{k8();dm1();im1();NX();rm1=/\$\(.*<</,b_z=[{pattern:/<\(/,message:"process substitution <()"},{pattern:/>\(/,message:"process substitution >()"},{pattern:/=\(/,message:"Zsh process substitution =()"},{pattern:/(?:^|[\s;&|])=[a-zA-Z_]/,message:"Zsh equals expansion (=cmd)"},{pattern:/\$\(/,message:"$() command substitution"},{pattern:/\$\{/,message:"${} parameter substitution"},{pattern:/\$\[/,message:"$[] legacy arithmetic expansion"},{pattern:/~\[/,message:"Zsh-style parameter expansion"},{pattern:/\(e:/,message:"Zsh-style glob qualifiers"},{pattern:/\(\+/,message:"Zsh glob qualifier with command execution"},{pattern:/\}\s*always\s*\{/,message:"Zsh always block (try/always construct)"},{pattern:/<#/,message:"PowerShell comment syntax"}],x_z=new Set(["zmodload","emulate","sysopen","sysread","syswrite","sysseek","zpty","ztcp","zsocket","mapfile","zf_rm","zf_mv","zf_ln","zf_chmod","zf_chown","zf_mkdir","zf_rmdir","zf_chgrp"]),t9={INCOMPLETE_COMMANDS:1,JQ_SYSTEM_FUNCTION:2,JQ_FILE_ARGUMENTS:3,OBFUSCATED_FLAGS:4,SHELL_METACHARACTERS:5,DANGEROUS_VARIABLES:6,NEWLINES:7,DANGEROUS_PATTERNS_COMMAND_SUBSTITUTION:8,DANGEROUS_PATTERNS_INPUT_REDIRECTION:9,DANGEROUS_PATTERNS_OUTPUT_REDIRECTION:10,IFS_INJECTION:11,GIT_COMMIT_SUBSTITUTION:12,PROC_ENVIRON_ACCESS:13,MALFORMED_TOKEN_INJECTION:14,BACKSLASH_ESCAPED_WHITESPACE:15,BRACE_EXPANSION:16,CONTROL_CHARACTERS:17,UNICODE_WHITESPACE:18,MID_WORD_HASH:19,ZSH_DANGEROUS_COMMANDS:20,BACKSLASH_ESCAPED_OPERATORS:21,COMMENT_QUOTE_DESYNC:22,QUOTED_NEWLINE:23};p_z=new Set([";","|","&","<",">"]);g_z=/[\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]/;Xy4=/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/});function Wy4(q,K){for(let _ of q)if(_.startsWith("-")&&!_.startsWith("--")&&_.length>2)for(let z=1;z<_.length;z++){let Y="-"+_[z];if(!K.includes(Y))return!1}else if(!K.includes(_))return!1;return!0}function F_z(q,K){let _=q.match(/^\s*sed\s+/);if(!_)return!1;let z=q.slice(_[0].length),Y=o$(z);if(!Y.success)return!1;let $=Y.tokens,A=[];for(let j of $)if(typeof j==="string"&&j.startsWith("-")&&j!=="--")A.push(j);if(!Wy4(A,["-n","--quiet","--silent","-E","--regexp-extended","-r","-z","--zero-terminated","--posix"]))return!1;let w=!1;for(let j of A){if(j==="-n"||j==="--quiet"||j==="--silent"){w=!0;break}if(j.startsWith("-")&&!j.startsWith("--")&&j.includes("n")){w=!0;break}}if(!w)return!1;if(K.length===0)return!1;for(let j of K){let H=j.split(";");for(let J of H)if(!U_z(J.trim()))return!1}return!0}function U_z(q){if(!q)return!1;return/^(?:\d+|\d+,\d+)?p$/.test(q)}function Py4(q,K,_,z){let Y=z?.allowFileWrites??!1;if(!Y&&_)return!1;let $=q.match(/^\s*sed\s+/);if(!$)return!1;let A=q.slice($[0].length),O=o$(A);if(!O.success)return!1;let w=O.tokens,j=[];for(let Z of w)if(typeof Z==="string"&&Z.startsWith("-")&&Z!=="--")j.push(Z);let H=["-E","--regexp-extended","-r","--posix"];if(Y)H.push("-i","--in-place");if(!Wy4(j,H))return!1;if(K.length!==1)return!1;let J=K[0].trim();if(!J.startsWith("s"))return!1;let M=J.match(/^s\/(.*?)$/);if(!M)return!1;let X=M[1],P=0,W=-1,D=0;while(D<X.length){if(X[D]==="\\"){D+=2;continue}if(X[D]==="/")P++,W=D;D++}if(P!==2)return!1;let f=X.slice(W+1);if(!/^[gpimIM]*[1-9]?[gpimIM]*$/.test(f))return!1;return!0}function RV6(q,K){let _=K?.allowFileWrites??!1,z;try{z=d_z(q)}catch(O){return!1}let Y=Q_z(q),$=!1,A=!1;if(_)A=Py4(q,z,Y,{allowFileWrites:!0});else $=F_z(q,z),A=Py4(q,z,Y);if(!$&&!A)return!1;for(let O of z)if(A&&O.includes(";"))return!1;for(let O of z)if(c_z(O))return!1;return!0}function Q_z(q){let K=q.match(/^\s*sed\s+/);if(!K)return!1;let _=q.slice(K[0].length),z=o$(_);if(!z.success)return!0;let Y=z.tokens;try{let $=0,A=!1;for(let O=0;O<Y.length;O++){let w=Y[O];if(typeof w!=="string"&&typeof w!=="object")continue;if(typeof w==="object"&&w!==null&&"op"in w&&w.op==="glob")return!0;if(typeof w!=="string")continue;if((w==="-e"||w==="--expression")&&O+1<Y.length){A=!0,O++;continue}if(w.startsWith("--expression=")){A=!0;continue}if(w.startsWith("-e=")){A=!0;continue}if(w.startsWith("-"))continue;if($++,A)return!0;if($>1)return!0}return!1}catch($){return!0}}function d_z(q){let K=[],_=q.match(/^\s*sed\s+/);if(!_)return K;let z=q.slice(_[0].length);if(/-e[wWe]/.test(z)||/-w[eE]/.test(z))throw Error("Dangerous flag combination detected");let Y=o$(z);if(!Y.success)throw Error(`Malformed shell syntax: ${Y.error}`);let $=Y.tokens;try{let A=!1,O=!1;for(let w=0;w<$.length;w++){let j=$[w];if(typeof j!=="string")continue;if((j==="-e"||j==="--expression")&&w+1<$.length){A=!0;let H=$[w+1];if(typeof H==="string")K.push(H),w++;continue}if(j.startsWith("--expression=")){A=!0,K.push(j.slice(13));continue}if(j.startsWith("-e=")){A=!0,K.push(j.slice(3));continue}if(j.startsWith("-"))continue;if(!A&&!O){K.push(j),O=!0;continue}break}}catch(A){throw Error(`Failed to parse sed command: ${A instanceof Error?A.message:"Unknown error"}`)}return K}function c_z(q){let K=q.trim();if(!K)return!1;if(/[^\x01-\x7F]/.test(K))return!0;if(K.includes("{")||K.includes("}"))return!0;if(K.includes(` |