mirror of
https://github.com/garrytan/gstack.git
synced 2026-06-10 12:03:59 +02:00
9cc41b7163
* fix(ship): adversarial subagent no longer trips usage-policy denial on own security fixtures (#1899) The Claude adversarial subagent in /review and /ship was told to "think like an attacker" over the full diff. When the diff includes the repo's own security regression fixtures (real attack payloads, by design), reasoning adversarially over that material triggered Anthropic's real-time usage-policy safeguards and the subagent call was denied — blocking the review. Fix at the prompt's source of truth (scripts/resolvers/review.ts {{ADVERSARIAL_STEP}}): - Authorized-defensive-testing framing: declares this is the maintainer's own repo and that attack-pattern strings inside test/fixture paths are the project's own regression corpus to analyze, not material to expand on. - Fixture summary-mode diff: full content for non-fixture source, --stat/--name-status for test/fixture files, so raw exploit bytes aren't fed into adversarial reasoning. The subagent must state fixtures were reviewed in summary mode (no silent coverage cut). Reported by @bmajewski. Regenerated review/SKILL.md + ship/sections/adversarial.md. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(redact): detect modern sk-proj-/sk-svcacct-/sk-admin- OpenAI keys (#1868) openai.key (HIGH/block) used /\b(sk-(?:proj-)?[A-Za-z0-9]{32,})\b/, which stops at the first - or _ in the body. Modern OpenAI project/service-account/admin keys use base64url bodies containing - and _, so they never reached the 32-char run and produced ZERO findings — a HIGH credential failing open through /spec, /ship, /cso, and /document-*. Replace with explicit alternation, bare vs prefixed (not a globally-optional prefix, which would match malformed sk--... or separator-less sk-projabc...): sk-{proj,svcacct,admin}- + [A-Za-z0-9_-]{20,} | sk-[A-Za-z0-9]{32,} (legacy) Tests: the three previously-missed shapes now block; FP guards pin that hyphenated prose and malformed sk- strings do NOT match (HIGH tier blocks, so calibration matters). Reported by @jbetala7. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(redact): reject malformed --max-bytes instead of silently disabling the size guard (#1824) The oversize check is designed to fail CLOSED, but a malformed --max-bytes turned it fail-OPEN. bin/gstack-redact did parseInt(maxBytes,10) and passed it straight through; parseInt("foo") is NaN. The engine guarded with `opts.maxBytes ?? DEFAULT`, and ?? does not catch NaN, so `byteLen > NaN` was always false and the fail-closed block never fired. A negative value made `byteLen > -5` always true, blocking everything. Two layers: - bin/gstack-redact validates the RAW string (parseInt accepts "123abc"->123, "1.5"->1): require /^\d+$/ and > 0, else exit 1 with a clear message. - lib/redact-engine.ts hardens the fallback to Number.isFinite && > 0 else the default cap — a guardrail so the engine never silently runs uncapped even if a bad value reaches it directly. Tests: NaN and negative both fall back to the default cap (oversize still blocks); CLI rejects garbage/negative with exit 1. Reported by @jbetala7. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(learnings): cross-project trust gate is an allowlist, not a denylist (#1745) gstack-learnings-search --cross-project is documented as an allowlist — foreign learnings load only when user-stated/trusted, to stop one project's AI-generated learnings from injecting into another project's reviews. It was implemented as a denylist: `if (isCrossProject && e.trusted === false) continue`. Any row where `trusted` is missing/undefined (legacy rows from before the field existed, hand-edited rows, rows from other tools) passed `undefined === false` → false → admitted. Those rows leaked across projects. Flip to `e.trusted !== true`. Test: a foreign row with no `trusted` field is now excluded (true still included, false still excluded). Reported by @jbetala7. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(safety): one-way-door classifier catches "rotate ... password" (#1839) scripts/one-way-doors.ts is the secondary safety net for ad-hoc AskUserQuestion ids with no registry entry; a false negative auto-approves a destructive op. The revoke and reset credential patterns both include `password`, but the rotate pattern omitted it, so the most common phrasing ("rotate the database password") classified as a reversible two-way question. Add `password` to the rotate alternation so all three verbs are parallel. New test covers rotate+password, the revoke/reset/rotate parallel, and rotate's other nouns. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(review): route .mjs/.cjs/.mts/.cts changes to the backend reviewer (#1810) gstack-diff-scope backend detection matched only *.ts|*.js. Modern Node ships backend code as ESM (.mjs) / CommonJS (.cjs) and explicit-module TS (.mts/.cts); none matched any category, so a PR touching only those files reported no backend scope and the Review Army skipped the backend reviewer. Add the four module extensions to the backend case. Test covers all four. Reported by @jbetala7. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(brain-cache): loadMeta tolerates malformed _meta.json without crashing (#1879) loadMeta returned the parsed JSON verbatim. A valid JSON file that lacked the last_refresh map made three consumers (isStale, cmdInvalidate, refreshEntity) throw a TypeError dereferencing meta.last_refresh — the sibling last_attempt was already guarded, last_refresh wasn't. Fix in loadMeta: - Shape-guard: JSON.parse can return null/array/string/number; non-object → fresh meta. - Normalize ONLY the dereferenced maps (last_refresh, last_attempt). - Deliberately do NOT default schema_version/endpoint_hash. Leaving them absent makes schemaVersionMismatch()/endpointSwitched() force a rebuild (missing identity = mismatch = safe); defaulting them would suppress cache invalidation and trust a stale file of unknown provenance. Tests: missing last_refresh no longer throws; null/array/primitive treated as cold; missing schema_version forces rebuild instead of a trusted warm hit. Reported by @jbetala7. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(skills): anchor guard/freeze/careful hook paths so they survive CC 2.1.162 (#1871) The PreToolUse frontmatter hooks for guard, freeze, and careful invoked `bash ${CLAUDE_SKILL_DIR}/.../check-*.sh`. Claude Code 2.1.162 no longer populates ${CLAUDE_SKILL_DIR} in the skill-hook execution env, so it expanded to empty and every Edit/Write/Bash ran `bash /...` and errored — breaking the safety skills entirely. Frontmatter hooks run before any skill-body bash, so no runtime-resolved variable can fix this; the command must be a path that's valid at hook time. Anchor to the installed checkout: $HOME/.claude/skills/gstack/{careful,freeze}/bin/check-*.sh, where the scripts actually live. ($HOME is expanded by the hook shell.) Reported by @omariani-howdy. Regenerated the three SKILL.md from templates. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore: v1.58.0.0 — fix-wave release notes, VERSION bump, #1882 TODO CHANGELOG entry for the 8-fix safety wave (#1899, #1868, #1824, #1745, #1839, #1810, #1879, #1871). VERSION + package.json to 1.58.0.0 (MINOR — coordinated multi-file safety fixes on top of main's 1.57.3.0). #1882 filed as the top TODOS.md item (scoped out of this wave per decision; host-config change touching all 52 skills, distinct from the #1871 hook fix). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(learnings): strip backticks from #1745 comment inside the bun -e block The #1745 trust-gate fix added an explanatory comment containing backticks (`=== false`) and the JS block is a double-quoted `bun -e "..."` bash string, so bash command-substituted the backtick contents on every cross-project search — polluting stderr with "command not found" and leaving a latent shell-injection / source-corruption surface in a security gate. Caught by the wave's own adversarial review (#1899 framing working as intended). Reworded the comments to avoid backticks and dollar-paren entirely; the gate logic is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test(golden): refresh ship golden baselines (#1899 prompt + main's PR-title line) The three ship golden fixtures were stale: main's v1.57.3.0 added the always-loaded PR-title invariant to ship/SKILL.md but did not regenerate the goldens (the golden regression test fails on main too), and the codex golden still carried an unresolved ${ctx.paths.binDir} token. Regenerated from the current generated ship skills, which also picks up this wave's #1899 adversarial-prompt framing (inlined for codex/factory). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
162 lines
5.6 KiB
TypeScript
162 lines
5.6 KiB
TypeScript
/**
|
|
* One-Way Door Classifier — belt-and-suspenders safety layer.
|
|
*
|
|
* Primary safety gate is the `door_type` field in scripts/question-registry.ts.
|
|
* Every registered AskUserQuestion declares whether it is one-way (always ask,
|
|
* never auto-decide) or two-way (can be suppressed by explicit user preference).
|
|
*
|
|
* This file is a SECONDARY keyword-pattern check for questions that fire
|
|
* WITHOUT a registry id (ad-hoc question_ids generated at runtime). If the
|
|
* question_summary contains any of the destructive keyword patterns, treat
|
|
* it as one-way regardless of what the (absent or unknown) registry entry says.
|
|
*
|
|
* Codex correctly pointed out (design doc Decision C) that prose-parsing is
|
|
* too weak to be the PRIMARY safety gate — wording can change. The registry
|
|
* is primary. This is the fallback for questions not yet catalogued, and it
|
|
* errs on the side of asking the user even when tuning preferences say skip.
|
|
*
|
|
* Ordering
|
|
* --------
|
|
* isOneWayDoor() is called by gstack-question-sensitivity --check in this
|
|
* order:
|
|
* 1. Look up registry by id → use registry.door_type if found
|
|
* 2. If not in registry: apply keyword patterns below
|
|
* 3. Default to ASK_NORMALLY (safer than AUTO_DECIDE)
|
|
*/
|
|
|
|
import { getQuestion } from './question-registry';
|
|
|
|
/**
|
|
* Keyword patterns that identify one-way-door questions when the registry
|
|
* doesn't have an entry for the question_id. Case-insensitive substring match
|
|
* against the question_summary passed into AskUserQuestion.
|
|
*
|
|
* Additions here should be conservative — a false positive means the user
|
|
* gets asked an extra question they might have preferred to auto-decide.
|
|
* A false negative could mean auto-approving a destructive operation.
|
|
*/
|
|
const DESTRUCTIVE_PATTERNS: RegExp[] = [
|
|
// File system destruction
|
|
/\brm\s+-rf\b/i,
|
|
/\bdelete\b/i,
|
|
/\bremove\s+(directory|folder|files?)\b/i,
|
|
/\bwipe\b/i,
|
|
/\bpurge\b/i,
|
|
/\btruncate\b/i,
|
|
|
|
// Database destruction
|
|
/\bdrop\s+(table|database|schema|index|column)\b/i,
|
|
/\bdelete\s+from\b/i,
|
|
|
|
// Git / VCS destruction
|
|
/\bforce[- ]push\b/i,
|
|
/\bpush\s+--force\b/i,
|
|
/\bgit\s+reset\s+--hard\b/i,
|
|
/\bcheckout\s+--\b/i,
|
|
/\brestore\s+\.\b/i,
|
|
/\bclean\s+-f\b/i,
|
|
/\bbranch\s+-D\b/i,
|
|
|
|
// Deploy / infra destruction
|
|
/\bkubectl\s+delete\b/i,
|
|
/\bterraform\s+destroy\b/i,
|
|
/\brollback\b/i,
|
|
|
|
// Credentials / auth — allow filler words ("the", "my") between verb and noun
|
|
/\brevoke\s+[\w\s]*\b(api key|token|credential|access key|password)\b/i,
|
|
/\breset\s+[\w\s]*\b(api key|token|password|credential)\b/i,
|
|
/\brotate\s+[\w\s]*\b(api key|token|secret|credential|access key|password)\b/i,
|
|
|
|
// Scope / architecture forks (reversible with effort — still deserve confirmation)
|
|
/\barchitectur(e|al)\s+(change|fork|shift|decision)\b/i,
|
|
/\bdata\s+model\s+change\b/i,
|
|
/\bschema\s+migration\b/i,
|
|
/\bbreaking\s+change\b/i,
|
|
];
|
|
|
|
/**
|
|
* Skill-category combinations that are always one-way even when the question
|
|
* body looks benign. Matches the ownership model: certain skill actions are
|
|
* inherently high-stakes.
|
|
*/
|
|
const ONE_WAY_SKILL_CATEGORIES = new Set<string>([
|
|
'cso:approval', // security-audit findings
|
|
'land-and-deploy:approval', // anything /land-and-deploy asks
|
|
]);
|
|
|
|
export interface ClassifyInput {
|
|
/** Registry id OR ad-hoc id; looked up first */
|
|
question_id?: string;
|
|
/** Skill firing the question (for skill-category fallback) */
|
|
skill?: string;
|
|
/** Question category (approval | clarification | routing | cherry-pick | feedback-loop) */
|
|
category?: string;
|
|
/** Free-form question summary — pattern-matched against destructive keywords */
|
|
summary?: string;
|
|
}
|
|
|
|
export interface ClassifyResult {
|
|
/** true = treat as one-way door (always ask, never auto-decide) */
|
|
oneWay: boolean;
|
|
/** Which check triggered the classification (for audit/debug) */
|
|
reason: 'registry' | 'skill-category' | 'keyword' | 'default-safe' | 'default-two-way';
|
|
/** Matched pattern if reason is 'keyword' */
|
|
matched?: string;
|
|
}
|
|
|
|
/**
|
|
* Classify a question as one-way (always ask) or two-way (can be suppressed).
|
|
* Returns {oneWay: false, reason: 'default-two-way'} only when no evidence of
|
|
* one-way nature is found. Errs conservatively otherwise.
|
|
*/
|
|
export function classifyQuestion(input: ClassifyInput): ClassifyResult {
|
|
// 1. Registry lookup (primary)
|
|
if (input.question_id) {
|
|
const registered = getQuestion(input.question_id);
|
|
if (registered) {
|
|
return {
|
|
oneWay: registered.door_type === 'one-way',
|
|
reason: 'registry',
|
|
};
|
|
}
|
|
}
|
|
|
|
// 2. Skill-category fallback (certain combos are always one-way)
|
|
if (input.skill && input.category) {
|
|
const key = `${input.skill}:${input.category}`;
|
|
if (ONE_WAY_SKILL_CATEGORIES.has(key)) {
|
|
return { oneWay: true, reason: 'skill-category' };
|
|
}
|
|
}
|
|
|
|
// 3. Keyword pattern match (catch destructive questions without registry entry)
|
|
if (input.summary) {
|
|
for (const pattern of DESTRUCTIVE_PATTERNS) {
|
|
if (pattern.test(input.summary)) {
|
|
return {
|
|
oneWay: true,
|
|
reason: 'keyword',
|
|
matched: pattern.toString(),
|
|
};
|
|
}
|
|
}
|
|
}
|
|
|
|
// 4. No evidence either way — treat as two-way (can be preference-suppressed).
|
|
return { oneWay: false, reason: 'default-two-way' };
|
|
}
|
|
|
|
/**
|
|
* Convenience wrapper for the sensitivity check binary.
|
|
* Returns true if the question must be asked regardless of user preferences.
|
|
*/
|
|
export function isOneWayDoor(input: ClassifyInput): boolean {
|
|
return classifyQuestion(input).oneWay;
|
|
}
|
|
|
|
/**
|
|
* Export patterns for tests and audit tooling.
|
|
*/
|
|
export const DESTRUCTIVE_PATTERN_LIST = DESTRUCTIVE_PATTERNS;
|
|
export const ONE_WAY_SKILL_CATEGORY_SET = ONE_WAY_SKILL_CATEGORIES;
|