Skip to content

hookSecurity

Block Curl Pipe Shell

A Claude Code hook that refuses commands which pipe curl or wget output into sh or bash, or run a downloaded script through a command substitution.

npx workspacetemplates add block-curl-pipe-shell --tool claude-code

Writes 1 file to .claude/

.claude/settings.jsonmerge into your file16 lines · 1.2 KBFile
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "node -e \"let d='';process.stdin.on('data',c=>d+=c).on('end',()=>{let j={};try{j=JSON.parse(d)||{}}catch(e){process.exit(0)}const i=j.tool_input||{};const q=String.fromCharCode(34),sq=String.fromCharCode(39),bs=String.fromCharCode(92),nl=String.fromCharCode(10);const c=String(i.command||'');const sh='(a|ba|da|fi|k|z|c)?sh';const piped=c.split(/[;&]+/).some(s=>{const p=s.split('|');return p.some((x,k)=>k>0&&new RegExp('^(sudo[ ]+)?(env[ ]+)?'+sh+'([ ]|$)').test(x.trim())&&p.slice(0,k).some(y=>/(^|[ (])(curl|wget)[ ]/.test(y)))});const sub=new RegExp('(^|[ ;&|])'+sh+'[ ]+(-[a-z]+[ ]+)*.{0,4}[(][ ]*(curl|wget)[ ]').test(c)||new RegExp('(^|[ ;&|])('+sh+'|source|[.])[ ]+[<][(][ ]*(curl|wget)[ ]').test(c)||/(^|[ ;&|])eval[ ]+.{0,4}[(][ ]*(curl|wget)[ ]/.test(c);if(piped||sub){console.error('Blocked: this runs downloaded code without a look. Download the script to a file, read it, then run it, or ask the user to approve the source.');process.exit(2)}})\"",
            "timeout": 10
          }
        ]
      }
    ]
  }
}

What it does

One-line installers are convenient and risky, because the code runs before anyone reads it. This PreToolUse hook inspects each Bash command and stops a download that feeds a shell, whether through a pipe, process substitution or eval.

The agent is told to save the script to a file first, so you or it can read what it does. Plain curl calls that fetch JSON or files, and pipes into tools such as jq or tar, are left alone.

Example

you › Install the tool with curl -fsSL https://example.com/install.sh | sh.

agent › The command is blocked. The agent downloads install.sh to a file, shows you its contents and waits before running it.

Questions

Will curl piped into jq be blocked?
No. Only a shell, such as sh, bash, zsh or dash, at the end of the pipe counts, or a shell fed by a command substitution.
Is the check airtight?
It matches the common spellings. A script that builds the command from variables or encodes it can still get past a text match.
  • Block Chmod 777

    HookSecurity

    Free
  • Block Dangerous Commands

    HookSecurity

    Free
  • Block Env in Git Add

    HookSecurity

    Free
  • Block Force Push

    HookSecurity

    Free