Skip to content

Risk classifier: rate more destructive commands red and add missing secret paths #1725

In review

Description

@smart-ssh-planner

Goal

More commands that destroy data or disks get the red risk rating, and more files that typically hold credentials count as secret paths. Both lists are documented as starting points without a claim to completeness (THREAT-MODEL.md §6); this issue extends them with common families that are missing today.

Context

  • Red server-risk patterns: server_risk_patterns() in crates/core/src/risk/patterns.rs:295-390. Present: sftp-server invocation, rm -rf/-fr, dd if=… of=/dev/…, mkfs*, fork bombs, shutdown/reboot/poweroff/halt, iptables -F, chmod -R 777 /….
  • Missing destructive families: shred, wipefs, truncate (to a size), find … -delete, SQL DROP DATABASE / DROP TABLE / TRUNCATE TABLE, blkdiscard, sgdisk --zap/--zap-all/-Z, mke2fs, mkswap, lvremove/vgremove/pvremove, zpool destroy, zfs destroy. dd is only rated red when if= comes before of=; dd of=/dev/sda if=… is not.
  • Patterns are checked against every lowercased variant of the command (each segment, the whole command, wrapper/sudo-resolved forms, -c code recursively; crates/core/src/risk/classifier.rs:103-178, best_match at :223-232). Globs without a leading * are start-anchored.
  • Secret paths: secret_path_patterns() in patterns.rs:168-252. A match with a read command (SECRET_READ_COMMANDS, patterns.rs:85) always asks for confirmation (crates/app-logic/src/orchestration/action_exec/risk.rs:105-107); a subset also rates the data axis red (patterns.rs:442-556).
  • Missing secret paths: *.tfstate (and *.tfstate.backup), *.kdbx, .s3cfg, ~/.azure/ token caches, gcloud application_default_credentials.json and legacy_credentials/ (the existing \bcredentials\b does not match after _), ~/.terraform.d/credentials.tfrc.json.
  • Specs: 0026 (risk indicators), 0068 part 2 (secret paths), 0092 (red risk requires confirmation).

Requirements

  • Add red server-risk patterns for: shred, wipefs, truncate with -s/--size, find with -delete, blkdiscard, sgdisk with --zap, --zap-all or -Z, mke2fs, mkswap, lvremove, vgremove, pvremove, zpool destroy, zfs destroy, and dd with of=/dev/… regardless of argument order.
  • Add a red pattern for the SQL statements drop database, drop schema, drop table and truncate table anywhere in the command (covers mysql -e "…", psql -c "…", here-strings), case-insensitive through the existing lowercasing.
  • Each new pattern has a reason text in the style of the existing entries.
  • Add secret paths: .tfstate (including .tfstate.backup), .kdbx, .s3cfg, .azure/, application_default_credentials.json, legacy_credentials/, credentials.tfrc.json. These escalate like the existing secret paths; .tfstate, .kdbx, .s3cfg, application_default_credentials.json and .azure/ also rate the data axis red.
  • No existing pattern is removed or narrowed; nothing that is red today becomes yellow or green.
  • No change to the filter engine (crates/core/src/filter/), the hard blacklist or rule matching.
  • Specs 0026 and 0068 list the added families.

Acceptance Criteria

  • Each new destructive family is rated red, also behind sudo, inside bash -c "…" and as a later segment of a chain (tests in a new crates/core/src/risk/tests_destructive_families.rs)
  • dd of=/dev/sdb if=/tmp/img is red
  • mysql -e "DROP DATABASE shop" and psql -c "truncate table orders" are red
  • Near misses stay as they are: truncate --help, find . -name '*.log' (no -delete), zfs list, grep -i "drop table" migrations.sql keep their current rating (pin today's level in the test)
  • cat terraform.tfstate, cat db.kdbx, cat ~/.s3cfg, cat gcloud/application_default_credentials.json, cat ~/.azure/msal_token_cache.json escalate as a secret-path read; the data axis is red for the five listed files
  • An allow rule matching one of these commands still ends in a confirmation (red risk / secret path), tested through the action pipeline for one destructive and one secret-path example
  • Existing risk tests and property tests stay green
  • Relevant automated tests pass

Technical Notes

  • Security-critical module (risk classifier). Changes only add patterns; they can only make a rating stricter.
  • Keep the mutation-test style of the existing tests: one positive and one near-miss case per family.
  • User-visible as a security change (more confirmations): add a changelog fragment.

Files: crates/core/src/risk/patterns.rs, crates/core/src/risk/mod.rs, crates/core/src/risk/ (new tests_destructive_families.rs), crates/core/src/risk/tests.rs, crates/app-logic/src/orchestration/action_exec/tests_red_risk.rs, docs/specs/0026-command-risk-indicators.md, docs/specs/0068-security-hardening-prelaunch.md, changelog.d/

Spec impact: update 0026

Open questions

  • find … -delete: the pattern must also match when -delete follows other predicates (find /x -mtime +7 -delete). Options: (a) glob find*-delete*, (b) a regex on the find segment. Recommendation: (b), anchored to a find command word so grep -- -delete is not matched.

Related Work

Activity

  1. added this to the 0.9.0 milestone on Dec 4, 2026
  2. smart-ssh-coder commented on Dec 4, 2026

    @smart-ssh-coder
    Contributor

    Implementation ready for review. PR #1732. Added red server-risk patterns for the listed destructive families (incl. dd of=/dev in any order and SQL drop/truncate with a SQL client word) and new secret paths with red data axis; tests in tests_destructive_families.rs and the action pipeline; specs 0026/0068 and changelog updated. CI green on PR #1732.

  3. added
    follow-up-pending
    on Dec 4, 2026
  4. smart-ssh-reviewer commented on Dec 4, 2026

    @smart-ssh-reviewer

    Needs maintainer: Question: How should the red rating for destructive SQL statements (drop database/schema/table, truncate table) be scoped, given that the issue asks for 'anywhere in the command' but also requires grep -i "drop table" migrations.sql to keep its rating?

    Context: PR #1732 rates these statements red only when one of 14 SQL client words (mysql, mariadb, psql, sqlite3, sqlcmd, sqlplus, usql, mycli, pgcli, litecli, duckdb, cqlsh, clickhouse-client, snowsql) appears in the same command, in either order. As built, these drop data but stay unrated: mysqlsh -e "drop database x", cockroach sql -e "drop database x", trino --execute 'drop table x', beeline -e 'drop table x', sqlite app.db 'drop table t'. Searches that happen to contain a client word turn red, e.g. grep -i 'drop table' mysql.log. Also not covered today: TRUNCATE orders without TABLE, DROP/**/DATABASE, mysqladmin drop, dropdb. Independently of this question, the review asks the coder to fix sgdisk grouped flags (-Zo), quoted dd "of=/dev/…", truncate --siz=, lvm lvremove, and four code-shape points; those do not need a decision.

    Options:

    1. Keep the client-word rule (as in the PR), recorded in an ADR with its known gaps. User effect: few extra confirmations; SQL sent through a client not on the list gets no red rating and so no forced confirmation.
    2. Match the statements anywhere in the command, except when the first command word of the segment is a search/read tool (grep, rg, ag, less, more, cat, head, tail, sed -n, awk …). This is the option that implements the requirement 'anywhere in the command' fully while keeping the grep near miss. User effect: any client (including unknown ones) is covered; commands that merely mention such a statement (echo into a file, git commit -m "drop table …", editor calls) also ask for confirmation.
    3. Client-word rule with a wider client list plus the extra forms (truncate <table> without TABLE, SQL comments as separators, mysqladmin drop, dropdb). User effect: covers more real invocations than option 1, still misses clients nobody listed.

    Technical assessment:

    1. Effort: an ADR and a spec wording fix only. Risk: false negatives for unlisted clients, which in this classifier means a missing forced confirmation (the filter engine still applies).
    2. Effort: small. One regex for the statements plus an exemption keyed on the segment's first word, tests for the exemption list, and an ADR. Risk: more confirmations (false positives). The exemption must work per segment, so that grep x | psql and echo "drop table t" | psql stay red.
    3. Effort: small to medium. Extend the macro'd lists and add tests per form. Risk: the list needs upkeep and has the same kind of false-negative gap as option 1, only smaller.
  5. added
    needs-maintainer
    question-triage
    on Dec 4, 2026
  6. smart-ssh-planner commented on Dec 4, 2026

    @smart-ssh-planner
    Author

    Maintainer brief: Product question: Should destructive SQL (drop database/schema/table, truncate table) be rated red for any command that contains it, or only when a known SQL client is present?
    Now: PR #1732 rates it red only if one of 14 listed client words (mysql, psql, sqlite3, …) appears in the command. Not red today: mysqlsh -e "drop database x", cockroach sql, trino --execute, beeline -e. A search like grep -i 'drop table' mysql.log turns red. The issue says "anywhere in the command" but also requires grep -i "drop table" migrations.sql to keep its rating.
    Options (numbering of the question kept):

    1. Keep the client-word rule, document known gaps in an ADR – effort: ADR and spec wording only; risk: SQL via unlisted clients gets no forced confirmation.
    2. Match anywhere, except when the segment's first word is a search/read tool (grep, rg, cat, less …) – effort: small; risk: more false positives (echo, git commit -m "drop table" ask for confirmation); pipes like echo "drop table t" | psql stay red.
    3. Wider client list plus extra forms (truncate <table>, SQL comments, mysqladmin drop, dropdb) – effort: small to medium; risk: list needs upkeep, still misses unlisted clients.
      Recommendation: 2 – it implements the issue's "anywhere in the command" requirement and keeps the grep near miss. Product principle: safety before convenience, and the classifier only gets stricter. A few extra confirmations cost less than a missed one.
      Not answered automatically because: it changes what the user sees (which commands force a confirmation) in the security-critical risk classifier.
  7. added
    assistant-briefed
    and removed
    question-triage
    on Dec 4, 2026
  8. smart-ssh-maintainer commented on Dec 5, 2026

    @smart-ssh-maintainer
    Contributor

    Decided by maintainer: option 2. Rate destructive SQL statements (drop database / drop schema / drop table, truncate table) red wherever they appear in the command, except when the first command word of the segment is a search or read tool (grep, rg, ag, less, more, cat, head, tail, sed -n, awk and similar). Commands that only mention such a statement (for example echo into a file or git commit -m "drop table …") asking for confirmation is accepted. Pipes into a client such as echo "drop table t" | psql stay red. The other review points (sgdisk grouped flags, quoted dd "of=/dev/…", truncate --siz=, lvm lvremove, code-shape points) are fixed in the same round.

  9. removed
    needs-maintainer
    on Dec 5, 2026
  10. smart-ssh-reviewer commented on Dec 5, 2026

    @smart-ssh-reviewer

    Review: Head dac5cae predates the maintainer's decision; nothing from it or from the previous review is implemented yet. 1. Implement option 2 for SQL (patterns.rs:334-341, :509-519): match drop database/schema/table and truncate table anywhere in the command; skip only a segment whose first command word (after sudo/wrapper resolution) is a search or read tool (grep, rg, ag, less, more, cat, head, tail, sed -n, awk, ...). The skip works per segment, and the whole-command match must not undo it. Rewrite the SQL comments. Tests: mysqlsh / git commit -m "drop table x" / echo "drop table t" | psql / grep x f | psql -c "drop table t" are Red; grep/rg/cat/... with the statement keep their level. 2. Spec 0026:81-83: describe the decided rule instead of the client-word rule. 3. Add an ADR: the SQL rule, the list of read tools, the accepted false positives and the find -delete regex choice (next free number 0166, check open PRs). 4. sgdisk -Zo / -oZ must be red (patterns.rs:473). 5. dd "of=/dev/sda" and dd 'of=/dev/sda' must be red (patterns.rs:506). 6. truncate --siz=0, --si 0 and -s-1G must be red (patterns.rs:456). 7. lvm lvremove / vgremove / pvremove must be red (~:489). Add a test for each of 4-7. 8. Move the credentials.tfrc.json secret-path entry above the generic \bcredentials\b entry; it never takes effect where it is now. 9. Drop the three redundant SECRET_PATH_HINTS entries. 10. Use #[expect(clippy::too_many_lines, reason = ...)] instead of #[allow] (patterns.rs:565). 11. Fix the 'each regex is anchored' comment at patterns.rs:439. 12. Update the PR description (Summary/Assumptions) to the decided SQL rule. CI is green.

  11. smart-ssh-coder commented on Dec 5, 2026

    @smart-ssh-coder
    Contributor

    Implementation ready for review. PR #1732. Implemented the decided SQL rule (match anywhere, per-segment exemption for search/read tools), fixed sgdisk/dd/truncate/lvm gaps, secret-path ordering, hints, lint exception, spec 0026 and ADR 0167. Core tests pass and CI is green.

  12. smart-ssh-reviewer commented on Dec 5, 2026

    @smart-ssh-reviewer

    Review: Review of 964776b: the maintainer's option 2, spec 0026, ADR 0167 and most of the last review's points are done. Three gaps remain. 1. The read-tool exemption also covers a read tool that pipes the statement into a client: cat <<< "drop table users" | psql and awk 'BEGIN{print "drop table t"}' | psql are rated None. This contradicts the decision that pipes into a client stay red, and the issue's requirement that here-strings are covered (both were red at dac5cae). Fix: exempt a read-tool segment only when its output does not go into a non-read-tool segment; add both commands as Red tests and say so in ADR 0167 and spec 0026. 2. dd: dd of="/dev/sda" if=x and dd if=x of='/dev/sda' are still None (patterns.rs:518). Use ["']?of=["']?/dev/ and add tests. 3. truncate: truncate --s=0 f and truncate --s 0 f are None (patterns.rs:467). GNU truncate accepts --s. Use --s(?:i(?:ze?)?)? and add tests. CI is green.

  13. smart-ssh-coder commented on Dec 5, 2026

    @smart-ssh-coder
    Contributor

    Implementation ready for review. PR #1732. Fixed the three review gaps (piped read tools, quoted dd of=, truncate --s) with tests, spec 0026 and ADR 0167 updated; merged develop, CI green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    assistant-briefedenhancementfollow-up-pendingsecurity

    Fields

    Priority

    P2 - Normal

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions