diff options
| author | Morgan Lunt <morganl@anthropic.com> | 2026-06-09 08:49:47 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-09 08:49:47 -0700 |
| commit | 746c982737e3ce684dc45844f703d5b40389ed78 (patch) | |
| tree | 7d3127a7d7c34f4f0dcbbc0ef2c1f6f40dd7d0aa /plugins/code-modernization/commands | |
| parent | 88233b24ba89bcfb04d28444b32b60ad2d4cac01 (diff) | |
| parent | 4f49895abd8e59eb019780b87531d3ffd3f38765 (diff) | |
Merge pull request #2467 from anthropics/morganl/code-mod-secrets-redaction
code-modernization: never write discovered credential values into findings
Diffstat (limited to 'plugins/code-modernization/commands')
3 files changed, 110 insertions, 21 deletions
diff --git a/plugins/code-modernization/commands/modernize-assess.md b/plugins/code-modernization/commands/modernize-assess.md index 188c2d43..692bb643 100644 --- a/plugins/code-modernization/commands/modernize-assess.md +++ b/plugins/code-modernization/commands/modernize-assess.md @@ -1,11 +1,13 @@ --- description: Full discovery & portfolio analysis of a legacy system — inventory, complexity, debt, effort estimation -argument-hint: <system-dir> | --portfolio <parent-dir> +argument-hint: <system-dir> [--show-secrets] | --portfolio <parent-dir> --- **Mode select.** If `$ARGUMENTS` starts with `--portfolio`, run **Portfolio mode** against the directory that follows. Otherwise run **Single-system -mode** against `legacy/$1`. +mode** against the system dir. Parse flags positionally-independently: +`--show-secrets` may appear before or after the system dir — the system +dir is the first non-flag token. --- @@ -108,12 +110,16 @@ Spawn three subagents **in parallel**: 2. **legacy-analyst** — "Identify technical debt in legacy/$1: dead code, deprecated APIs, copy-paste duplication, god objects/programs, missing error handling, hardcoded config. Return the top 10 findings ranked by - remediation value, each with file:line evidence." + remediation value, each with file:line evidence. If evidence contains a + credential value, mask it per your secret-handling rules — never quote + it." 3. **security-auditor** — "Scan legacy/$1 for security vulnerabilities: injection, auth weaknesses, hardcoded secrets, vulnerable dependencies, missing input validation. Return findings in CWE-tagged table form with - file:line evidence and severity." + file:line evidence and severity. Mask every discovered credential value + per your secret-handling rules — file:line plus a 2–4 character masked + preview, never the value itself." Wait for all three. Synthesize their findings. @@ -141,6 +147,31 @@ need explained. ## Step 6 — Write the assessment +**Secrets quarantine first.** The assessment gets shared and committed — +discovered credential values must never appear in it. If the +security-auditor found any hardcoded credentials: + +1. Ensure `analysis/.gitignore` exists and contains the lines + `SECRETS.local.md` and `*.local.patch` (create or append as needed — + the patch pattern is used by `/modernize-harden`; writing both now + means the ignore set is complete from first contact). If the project is a + git repo, verify with `git check-ignore -q analysis/$1/SECRETS.local.md` + — do not write any findings until the check passes. If there is **no + git repo** (check for `.svn`/`.hg`/`CVS` too — a `.gitignore` protects + nothing under another VCS): refuse `--show-secrets` and write + `SECRETS.local.md` to `~/.modernize/$1/` instead of the project tree, + telling the user where it went and why. +2. Write `SECRETS.local.md`: one row per credential — masked preview, + `file:line`, credential type, what it grants access to, + production/test guess, rotation recommendation. Only if the user passed + `--show-secrets`, add the raw value column here — this file only, never + ASSESSMENT.md. +3. Masking applies to **every section of ASSESSMENT.md**, whichever agent + produced the finding — the Technical Debt section quotes hardcoded + config; those quotes follow the same masking rule as Security Findings. + The Security Findings section adds a one-line pointer: + "Credential inventory in SECRETS.local.md (gitignored; not for sharing)." + Create `analysis/$1/ASSESSMENT.md` with these sections: - **Executive Summary** (3-4 sentences: what it is, how big, how risky, headline recommendation) - **System Inventory** (the scc table + tech fingerprint) diff --git a/plugins/code-modernization/commands/modernize-extract-rules.md b/plugins/code-modernization/commands/modernize-extract-rules.md index 1fe7979c..e842867c 100644 --- a/plugins/code-modernization/commands/modernize-extract-rules.md +++ b/plugins/code-modernization/commands/modernize-extract-rules.md @@ -46,7 +46,7 @@ Merge the three result sets. Deduplicate. For each distinct rule, write a When <trigger> Then <outcome> [And <additional outcome>] -**Parameters:** <constants, rates, thresholds with their current values> +**Parameters:** <constants, rates, thresholds with their current values — credentials masked: `<credential — masked, see file:line>`> **Edge cases handled:** <list> **Suspected defect:** <optional — legacy behavior that looks wrong; decide preserve-vs-fix during transform> **Confidence:** High | Medium | Low — <why; if < High, state the exact SME question> diff --git a/plugins/code-modernization/commands/modernize-harden.md b/plugins/code-modernization/commands/modernize-harden.md index b8f7a72c..64e36f3f 100644 --- a/plugins/code-modernization/commands/modernize-harden.md +++ b/plugins/code-modernization/commands/modernize-harden.md @@ -1,14 +1,42 @@ --- description: Security vulnerability scan with a reviewable remediation patch — OWASP, CWE, CVE, secrets, injection -argument-hint: <system-dir> +argument-hint: <system-dir> [--show-secrets] --- -Run a **security hardening pass** on `legacy/$1`: find vulnerabilities, rank -them, and produce a reviewable patch for the critical ones. +Run a **security hardening pass** on the legacy system: find +vulnerabilities, rank them, and produce a reviewable patch for the +critical ones. Parse arguments flag-independently: the system dir +(referred to as `$1` below) is the first non-flag token in `$ARGUMENTS`; +`--show-secrets` may appear anywhere. This command never edits `legacy/` — it writes findings and a proposed patch to `analysis/$1/`. The user reviews and applies (or not). +## Step 0 — Secrets quarantine setup + +Findings files get shared, committed, and pasted into decks — discovered +credential values must never land in them. Before any scanning: + +1. Ensure `analysis/.gitignore` exists and contains the lines + `SECRETS.local.md` and `*.local.patch`. Create the file or append the + missing lines. +2. If the project is a git repo, verify with + `git check-ignore -q analysis/$1/SECRETS.local.md` — if that exits + non-zero, fix the ignore rule before proceeding. Do not write any + findings until this check passes. +3. **If there is no git repo** (check for `.svn`/`.hg`/`CVS` too — a + `.gitignore` protects nothing under another VCS): refuse + `--show-secrets`, and write `SECRETS.local.md` and any `.local.patch` + file to `~/.modernize/$1/` instead of the project tree, telling the + user where they went and why. + +All secret values in every shareable artifact this command produces are +**masked** (`AKIA****`, `password=****`) and cited by `file:line`. Raw +values may appear in exactly two places, both gitignored: the +`*.local.patch` remediation hunks (unavoidably — see Remediate) and, only +with `--show-secrets`, `SECRETS.local.md`. Never in SECURITY_FINDINGS.md +or patch commentary. + ## Scan Spawn the **security-auditor** subagent: @@ -20,7 +48,9 @@ hardcoded secrets, vulnerable dependency versions, missing input validation, path traversal. For each finding return: CWE ID, severity (Critical/High/Med/Low), file:line, one-sentence exploit scenario, and recommended fix. Run any available SAST tooling (npm audit, pip-audit, -OWASP dependency-check) and include its raw output." +OWASP dependency-check) and include its raw output. Mask every discovered +credential value per your secret-handling rules — file:line plus a 2–4 +character masked preview, never the value itself." ## Triage @@ -29,26 +59,50 @@ Write `analysis/$1/SECURITY_FINDINGS.md`: - Findings table sorted by severity - Dependency CVE table (package, installed version, CVE, fixed version) +If any hardcoded credentials were found, also write +`analysis/$1/SECRETS.local.md` (the gitignored quarantine file from Step 0): +one row per credential — masked preview, `file:line`, credential type, what +it appears to grant access to, production/test guess, and a rotation +recommendation. With `--show-secrets`, append the raw value column here — +this file only. SECURITY_FINDINGS.md gets a one-line pointer: +"N hardcoded credentials found — inventory in SECRETS.local.md (gitignored; +not for sharing)." + ## Remediate For each **Critical** and **High** finding, draft a minimal, targeted fix. -Do **not** edit `legacy/` — write all fixes as a single unified diff to -`analysis/$1/security_remediation.patch`, with a comment line above each -hunk citing the finding ID it addresses (`# SEC-001: parameterize the query`). +Do **not** edit `legacy/` — write fixes as unified diffs with **paths +relative to the project root** (`legacy/$1/...`), applied from the project +root, with a comment line above each hunk citing the finding ID it +addresses (`# SEC-001: parameterize the query`). + +**Credential findings split into two files.** A diff that removes a +hardcoded secret necessarily contains the raw value on its `-` and +context lines — that cannot go in the shareable patch: + +- `analysis/$1/security_remediation.patch` (shareable) — every + non-credential hunk, plus for each credential finding a comment-only + placeholder: `# SEC-NNN: credential remediation — hunk in + security_remediation.local.patch (gitignored; not for sharing)`. +- `analysis/$1/security_remediation.local.patch` (gitignored in Step 0) — + the real, applyable hunks for credential findings only. Add a **Remediation Log** section to SECURITY_FINDINGS.md mapping each -finding ID → one-line summary of the proposed fix and the patch hunk that -implements it. +finding ID → one-line summary of the proposed fix and which patch file +carries the hunk. ## Verify -Spawn the **security-auditor** again to **review the patch** against the -original code: +Spawn the **security-auditor** again to **review both patches** against +the original code: -"Review analysis/$1/security_remediation.patch against legacy/$1. For each +"Review analysis/$1/security_remediation.patch and +analysis/$1/security_remediation.local.patch against legacy/$1. For each hunk: does it fully remediate the cited finding? Does it introduce new -vulnerabilities or change behavior beyond the fix? Return one verdict per -hunk: RESOLVES / PARTIAL / INTRODUCES-RISK, with a one-line reason." +vulnerabilities or change behavior beyond the fix? Confirm no raw +credential values appear anywhere in the shareable patch. Return one +verdict per hunk: RESOLVES / PARTIAL / INTRODUCES-RISK, with a one-line +reason." Add a **Patch Review** section to SECURITY_FINDINGS.md with the verdicts. If any hunk is PARTIAL or INTRODUCES-RISK, revise the patch and re-review. @@ -57,8 +111,12 @@ If any hunk is PARTIAL or INTRODUCES-RISK, revise the patch and re-review. Tell the user the artifacts are ready: - `analysis/$1/SECURITY_FINDINGS.md` — findings, remediation log, patch review -- `analysis/$1/security_remediation.patch` — review, then apply if appropriate - with `git -C legacy/$1 apply ../../analysis/$1/security_remediation.patch` +- `analysis/$1/security_remediation.patch` — review, then apply **from the + project root**: `git apply analysis/$1/security_remediation.patch` + (if `legacy/$1` is a symlink, use `git apply --unsafe-paths` or apply + with `patch -p0` from the project root) +- `analysis/$1/security_remediation.local.patch` — the credential fixes; + apply the same way, and rotate the affected credentials regardless - Re-run `/modernize-harden $1` after applying to confirm resolution Suggest: `glow -p analysis/$1/SECURITY_FINDINGS.md` |
