feat: add rules for npx commands + command substitutions#25
feat: add rules for npx commands + command substitutions#25sarahxsanders wants to merge 2 commits into
Conversation
Generated-By: PostHog Code Task-Id: 718b2db1-f48b-4bd0-88db-318035320ba1
gewenyu99
left a comment
There was a problem hiding this comment.
Some stuff to look at. Not sure how to solve 🤔
There was a problem hiding this comment.
My bot tells me npx --yes <pkg> gets through this.
There was a problem hiding this comment.
Apparently
exfiltration_command_substitution_in_url keys on $([a-zA-Z] / `[a-zA-Z]. So these all bypass:
curl "…?x=$(/bin/hostname)" (absolute path)
curl "…?x=$( hostname)" (leading space — valid shell)
curl "…?x=/bin/id"
these can get through (accoridng to my bot)
There was a problem hiding this comment.
Some possible false positive possibly?
$API_URL / $AUTH_URL / $ACCESS_* trip the secret-exfil block
Since it's [A-Z_]*, lets a keyword match a prefix of a longer var name, and API/AUTH/ACCESS are keywords.
So curl "$API_URL/health" and stuff like this will get hard blocked.
There was a problem hiding this comment.
Maybe this is non-issue but
| $wget_backtick = /\bwget\s[^\n]{0,300}`[a-zA-Z]/ | ||
|
|
||
| // httpie (http/https commands) with command substitution | ||
| $httpie_dollar_paren = /\bhttps?\s[^\n]{0,300}\$\([a-zA-Z]/ |
There was a problem hiding this comment.
\bhttps?\s matches the word "http"/"https" + whitespace
So like in markdown Connect via https and pass your $API_KEY will trigger this I think
Changes
adds three new rules:
supply_chain_npx_auto_confirm: catchesnpx/dlx/bunxwith--yes/yoryes |(silent package execution) as critical/blocksupply_chain_npx_in_skill: catches anynpx/dlx/bunxinvocation, with the belief that a trusted skill shouldn't tell an agent to install packages, high/warnexfiltration_command_substitution_in_url: catchscurl/wgetwith$(...)or backtick command substitutions for data exfil via URL params or POST body, critical/blockthese rules catch a real attack pattern found on skills.sh where a skill silently installs a second malicious skill via
npx --yes, which then exfiltrates machine identity to an attacker-controlled domain via command substitution in a curl URL >.<Test plan
pnpm test)pnpm build)