mirror of
https://github.com/garrytan/gstack.git
synced 2026-06-10 12:03:59 +02:00
e722c5bf89
* test: canonical CARVE_GUARDS registry; derive parity + size-budget from it Single source of truth for the carved-skill set + per-skill invariants (EQ1). parity-harness.ts sectioned entries and skill-size-budget.ts SECTIONS_EXTRACTED now derive from it instead of hand-maintained lists. Closes a pre-existing drift: plan-devex-review was in SECTIONS_EXTRACTED but had no sectioned parity invariant; now generated. carve-guards.ts is a pure leaf data module (import type only) to avoid an import cycle. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test: shared carve-guard check fns with injectable root discoverCarvedSkills/checkOrdering/checkCompleteness take a root param so the negative tests can point the real guards at a fixture dir. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test: E2 data-driven carve static ordering guard (gate) Per-PR backstop for every carved skill, one test() per skill, driven by CARVE_GUARDS staticInvariants. Generalizes + retires the ceo-specific ordering test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test: E1 carve-guard completeness meta-guard (gate) Asserts filesystem carved set == CARVE_GUARDS set both directions, so a future carve without a registry entry fails CI. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test: ET1 guard-of-guards negative tests (gate) Temp fixture broken 3 ways proves E1/E2 actually throw, via the injectable root. Kills the silent-pass-guard failure class. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test: T2 data-driven behavioral section-loading guard (periodic) One file iterating CARVE_GUARDS, one test() per skill with GSTACK_CARVE_SKILL cost-scoping (D-CODEX A). external carves (ship, plan-ceo) keep bespoke tests; testNames aligned to their touchfile keys. Registered in touchfiles. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs: defer E3 real-session carve canary to TODOS Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat: carve document-release into skeleton + on-demand section Steps 2-9 (per-file audit, auto-updates, risky-change asks, CHANGELOG voice polish, cross-doc consistency, TODOS cleanup, VERSION bump, commit + PR body) move to sections/release-body.md, read on demand after the Step 1.5 coverage map. Skeleton 59,256 -> 45,797 B (-23%); union preserved. Adds the CARVE_GUARDS entry (auto-extends parity + size-budget via EQ1). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat: carve design-consultation into skeleton + on-demand section Phases 3-6 (complete proposal, drill-downs, design preview, writing DESIGN.md) move to sections/proposal-and-preview.md, read on demand after product context + research. Skeleton 80,719 -> 59,229 B (-27%); union preserved. Adds the CARVE_GUARDS entry. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat: carve cso into skeleton + on-demand section (security-safe) Scope-dependent audit Phases 2-11 move to sections/audit-phases.md. Mode dispatch (## Arguments, ## Mode Resolution), always-run Phases 0/1, and the Phase 12 false-positive-filtering exceptions stay ALWAYS-LOADED in the skeleton. Skeleton 79,383 -> 65,117 B (-18%); union preserved. Adds a cso CARVE_GUARDS entry with an earliest-use invariant (mustPrecedeStop): mode dispatch must appear before any STOP-Read, so a directive that decides which sections to read can't be stranded behind the STOP that reads them (codex outside-voice #6). carve-guard-checks gains the mustPrecedeStop check. parity moves cso monolith -> generated carved entry. cso-preserved.test.ts strengthened: phrases checked against the union, plus an always-loaded contract on the skeleton (dispatch + FP-filtering, codex #5). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test: make redaction/taxonomy tests union-aware for cso + document-release carves The cso carve moved Secrets Archaeology (prefixes, lib/redact-patterns.ts pointer, git-history scan) into sections/audit-phases.md, and the document-release carve moved the Step 9 PR-body redaction scan into sections/release-body.md. Three content-presence tests asserted that content in the skeleton SKILL.md/.md.tmpl; they now read the skeleton+sections union (same fix as cso-preserved + parity). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore: bump version and changelog (v1.57.0.0) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix: address pre-landing review (codex) on the carve - cso section: add a scope-gate header so '--owasp' (and other scoped modes) run only their selected phases, not every phase bundled in the section ('execute in full' no longer overrides Mode Resolution). - carve-guard-checks: gateAfterStop now compares against the LAST STOP, not the first, so a gate stranded between two STOPs in a multi-STOP skeleton fails. - TODOS: behavioral section-loading hermeticity (verifier matches global-install path, not the fixture) — pre-existing in auq-sdk-capture.ts, deferred. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
252 lines
14 KiB
Cheetah
252 lines
14 KiB
Cheetah
**Scope gate (read first).** This section holds every scope-dependent phase (2-11), but you run ONLY the phases your resolved mode selected back in `## Mode Resolution` (always-loaded in the skeleton). Phases 0, 1, 12, 13, 14 always run; Phases 2-11 are scope-gated. "Execute in full" means work through this section applying that selection, NOT run a phase your mode did not select just because its prose lives here. Example: `--owasp` runs Phase 9 from this section, not Phases 2-8/10/11.
|
|
|
|
### Phase 2: Secrets Archaeology
|
|
|
|
Scan git history for leaked credentials, check tracked `.env` files, find CI configs with inline secrets.
|
|
|
|
**Canonical pattern catalog.** The HIGH-tier credential prefixes the archaeology
|
|
greps below target (AKIA, ghp_, sk-ant-, sk_live_, xoxb-, `-----BEGIN ... PRIVATE
|
|
KEY-----`, etc.) are the same set `/spec`'s in-flight redaction blocks on. The full
|
|
3-tier taxonomy (HIGH credentials, MEDIUM PII/legal/internal, LOW) is generated from
|
|
and lives in `lib/redact-patterns.ts` — the single source of truth shared by the
|
|
`gstack-redact` engine, `/spec`, `/ship`, and the `/document-*` skills.
|
|
|
|
**Git history — known secret prefixes:**
|
|
```bash
|
|
git log -p --all -S "AKIA" --diff-filter=A -- "*.env" "*.yml" "*.yaml" "*.json" "*.toml" 2>/dev/null
|
|
git log -p --all -S "sk-" --diff-filter=A -- "*.env" "*.yml" "*.json" "*.ts" "*.js" "*.py" 2>/dev/null
|
|
git log -p --all -G "ghp_|gho_|github_pat_" 2>/dev/null
|
|
git log -p --all -G "xoxb-|xoxp-|xapp-" 2>/dev/null
|
|
git log -p --all -G "password|secret|token|api_key" -- "*.env" "*.yml" "*.json" "*.conf" 2>/dev/null
|
|
```
|
|
|
|
**.env files tracked by git:**
|
|
```bash
|
|
git ls-files '*.env' '.env.*' 2>/dev/null | grep -v '.example\|.sample\|.template'
|
|
grep -q "^\.env$\|^\.env\.\*" .gitignore 2>/dev/null && echo ".env IS gitignored" || echo "WARNING: .env NOT in .gitignore"
|
|
```
|
|
|
|
**CI configs with inline secrets (not using secret stores):**
|
|
```bash
|
|
for f in $(find .github/workflows -maxdepth 1 \( -name '*.yml' -o -name '*.yaml' \) 2>/dev/null) .gitlab-ci.yml .circleci/config.yml; do
|
|
[ -f "$f" ] && grep -n "password:\|token:\|secret:\|api_key:" "$f" | grep -v '\${{' | grep -v 'secrets\.'
|
|
done 2>/dev/null
|
|
```
|
|
|
|
**Severity:** CRITICAL for active secret patterns in git history (AKIA, sk_live_, ghp_, xoxb-). HIGH for .env tracked by git, CI configs with inline credentials. MEDIUM for suspicious .env.example values.
|
|
|
|
**FP rules:** Placeholders ("your_", "changeme", "TODO") excluded. Test fixtures excluded unless same value in non-test code. Rotated secrets still flagged (they were exposed). `.env.local` in `.gitignore` is expected.
|
|
|
|
**Diff mode:** Replace `git log -p --all` with `git log -p <base>..HEAD`.
|
|
|
|
### Phase 3: Dependency Supply Chain
|
|
|
|
Goes beyond `npm audit`. Checks actual supply chain risk.
|
|
|
|
**Package manager detection:**
|
|
```bash
|
|
[ -f package.json ] && echo "DETECTED: npm/yarn/bun"
|
|
[ -f Gemfile ] && echo "DETECTED: bundler"
|
|
[ -f requirements.txt ] || [ -f pyproject.toml ] && echo "DETECTED: pip"
|
|
[ -f Cargo.toml ] && echo "DETECTED: cargo"
|
|
[ -f go.mod ] && echo "DETECTED: go"
|
|
```
|
|
|
|
**Standard vulnerability scan:** Run whichever package manager's audit tool is available. Each tool is optional — if not installed, note it in the report as "SKIPPED — tool not installed" with install instructions. This is informational, NOT a finding. The audit continues with whatever tools ARE available.
|
|
|
|
**Install scripts in production deps (supply chain attack vector):** For Node.js projects with hydrated `node_modules`, check production dependencies for `preinstall`, `postinstall`, or `install` scripts.
|
|
|
|
**Lockfile integrity:** Check that lockfiles exist AND are tracked by git.
|
|
|
|
**Severity:** CRITICAL for known CVEs (high/critical) in direct deps. HIGH for install scripts in prod deps / missing lockfile. MEDIUM for abandoned packages / medium CVEs / lockfile not tracked.
|
|
|
|
**FP rules:** devDependency CVEs are MEDIUM max. `node-gyp`/`cmake` install scripts expected (MEDIUM not HIGH). No-fix-available advisories without known exploits excluded. Missing lockfile for library repos (not apps) is NOT a finding.
|
|
|
|
### Phase 4: CI/CD Pipeline Security
|
|
|
|
Check who can modify workflows and what secrets they can access.
|
|
|
|
**GitHub Actions analysis:** For each workflow file, check for:
|
|
- Unpinned third-party actions (not SHA-pinned) — use Grep for `uses:` lines missing `@[sha]`
|
|
- `pull_request_target` (dangerous: fork PRs get write access)
|
|
- Script injection via `${{ github.event.* }}` in `run:` steps
|
|
- Secrets as env vars (could leak in logs)
|
|
- CODEOWNERS protection on workflow files
|
|
|
|
**Severity:** CRITICAL for `pull_request_target` + checkout of PR code / script injection via `${{ github.event.*.body }}` in `run:` steps. HIGH for unpinned third-party actions / secrets as env vars without masking. MEDIUM for missing CODEOWNERS on workflow files.
|
|
|
|
**FP rules:** First-party `actions/*` unpinned = MEDIUM not HIGH. `pull_request_target` without PR ref checkout is safe (precedent #11). Secrets in `with:` blocks (not `env:`/`run:`) are handled by runtime.
|
|
|
|
### Phase 5: Infrastructure Shadow Surface
|
|
|
|
Find shadow infrastructure with excessive access.
|
|
|
|
**Dockerfiles:** For each Dockerfile, check for missing `USER` directive (runs as root), secrets passed as `ARG`, `.env` files copied into images, exposed ports.
|
|
|
|
**Config files with prod credentials:** Use Grep to search for database connection strings (postgres://, mysql://, mongodb://, redis://) in config files, excluding localhost/127.0.0.1/example.com. Check for staging/dev configs referencing prod.
|
|
|
|
**IaC security:** For Terraform files, check for `"*"` in IAM actions/resources, hardcoded secrets in `.tf`/`.tfvars`. For K8s manifests, check for privileged containers, hostNetwork, hostPID.
|
|
|
|
**Severity:** CRITICAL for prod DB URLs with credentials in committed config / `"*"` IAM on sensitive resources / secrets baked into Docker images. HIGH for root containers in prod / staging with prod DB access / privileged K8s. MEDIUM for missing USER directive / exposed ports without documented purpose.
|
|
|
|
**FP rules:** `docker-compose.yml` for local dev with localhost = not a finding (precedent #12). Terraform `"*"` in `data` sources (read-only) excluded. K8s manifests in `test/`/`dev/`/`local/` with localhost networking excluded.
|
|
|
|
### Phase 6: Webhook & Integration Audit
|
|
|
|
Find inbound endpoints that accept anything.
|
|
|
|
**Webhook routes:** Use Grep to find files containing webhook/hook/callback route patterns. For each file, check whether it also contains signature verification (signature, hmac, verify, digest, x-hub-signature, stripe-signature, svix). Files with webhook routes but NO signature verification are findings.
|
|
|
|
**TLS verification disabled:** Use Grep to search for patterns like `verify.*false`, `VERIFY_NONE`, `InsecureSkipVerify`, `NODE_TLS_REJECT_UNAUTHORIZED.*0`.
|
|
|
|
**OAuth scope analysis:** Use Grep to find OAuth configurations and check for overly broad scopes.
|
|
|
|
**Verification approach (code-tracing only — NO live requests):** For webhook findings, trace the handler code to determine if signature verification exists anywhere in the middleware chain (parent router, middleware stack, API gateway config). Do NOT make actual HTTP requests to webhook endpoints.
|
|
|
|
**Severity:** CRITICAL for webhooks without any signature verification. HIGH for TLS verification disabled in prod code / overly broad OAuth scopes. MEDIUM for undocumented outbound data flows to third parties.
|
|
|
|
**FP rules:** TLS disabled in test code excluded. Internal service-to-service webhooks on private networks = MEDIUM max. Webhook endpoints behind API gateway that handles signature verification upstream are NOT findings — but require evidence.
|
|
|
|
### Phase 7: LLM & AI Security
|
|
|
|
Check for AI/LLM-specific vulnerabilities. This is a new attack class.
|
|
|
|
Use Grep to search for these patterns:
|
|
- **Prompt injection vectors:** User input flowing into system prompts or tool schemas — look for string interpolation near system prompt construction
|
|
- **Unsanitized LLM output:** `dangerouslySetInnerHTML`, `v-html`, `innerHTML`, `.html()`, `raw()` rendering LLM responses
|
|
- **Tool/function calling without validation:** `tool_choice`, `function_call`, `tools=`, `functions=`
|
|
- **AI API keys in code (not env vars):** `sk-` patterns, hardcoded API key assignments
|
|
- **Eval/exec of LLM output:** `eval()`, `exec()`, `Function()`, `new Function` processing AI responses
|
|
|
|
**Key checks (beyond grep):**
|
|
- Trace user content flow — does it enter system prompts or tool schemas?
|
|
- RAG poisoning: can external documents influence AI behavior via retrieval?
|
|
- Tool calling permissions: are LLM tool calls validated before execution?
|
|
- Output sanitization: is LLM output treated as trusted (rendered as HTML, executed as code)?
|
|
- Cost/resource attacks: can a user trigger unbounded LLM calls?
|
|
|
|
**Severity:** CRITICAL for user input in system prompts / unsanitized LLM output rendered as HTML / eval of LLM output. HIGH for missing tool call validation / exposed AI API keys. MEDIUM for unbounded LLM calls / RAG without input validation.
|
|
|
|
**FP rules:** User content in the user-message position of an AI conversation is NOT prompt injection (precedent #13). Only flag when user content enters system prompts, tool schemas, or function-calling contexts.
|
|
|
|
### Phase 8: Skill Supply Chain
|
|
|
|
Scan installed Claude Code skills for malicious patterns. 36% of published skills have security flaws, 13.4% are outright malicious (Snyk ToxicSkills research).
|
|
|
|
**Tier 1 — repo-local (automatic):** Scan the repo's local skills directory for suspicious patterns:
|
|
|
|
```bash
|
|
ls -la .claude/skills/ 2>/dev/null
|
|
```
|
|
|
|
Use Grep to search all local skill SKILL.md files for suspicious patterns:
|
|
- `curl`, `wget`, `fetch`, `http`, `exfiltrat` (network exfiltration)
|
|
- `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `env.`, `process.env` (credential access)
|
|
- `IGNORE PREVIOUS`, `system override`, `disregard`, `forget your instructions` (prompt injection)
|
|
|
|
**Tier 2 — global skills (requires permission):** Before scanning globally installed skills or user settings, use AskUserQuestion:
|
|
"Phase 8 can scan your globally installed AI coding agent skills and hooks for malicious patterns. This reads files outside the repo. Want to include this?"
|
|
Options: A) Yes — scan global skills too B) No — repo-local only
|
|
|
|
If approved, run the same Grep patterns on globally installed skill files and check hooks in user settings.
|
|
|
|
**Severity:** CRITICAL for credential exfiltration attempts / prompt injection in skill files. HIGH for suspicious network calls / overly broad tool permissions. MEDIUM for skills from unverified sources without review.
|
|
|
|
**FP rules:** gstack's own skills are trusted (check if skill path resolves to a known repo). Skills that use `curl` for legitimate purposes (downloading tools, health checks) need context — only flag when the target URL is suspicious or when the command includes credential variables.
|
|
|
|
### Phase 9: OWASP Top 10 Assessment
|
|
|
|
For each OWASP category, perform targeted analysis. Use the Grep tool for all searches — scope file extensions to detected stacks from Phase 0.
|
|
|
|
#### A01: Broken Access Control
|
|
- Check for missing auth on controllers/routes (skip_before_action, skip_authorization, public, no_auth)
|
|
- Check for direct object reference patterns (params[:id], req.params.id, request.args.get)
|
|
- Can user A access user B's resources by changing IDs?
|
|
- Is there horizontal/vertical privilege escalation?
|
|
|
|
#### A02: Cryptographic Failures
|
|
- Weak crypto (MD5, SHA1, DES, ECB) or hardcoded secrets
|
|
- Is sensitive data encrypted at rest and in transit?
|
|
- Are keys/secrets properly managed (env vars, not hardcoded)?
|
|
|
|
#### A03: Injection
|
|
- SQL injection: raw queries, string interpolation in SQL
|
|
- Command injection: system(), exec(), spawn(), popen
|
|
- Template injection: render with params, eval(), html_safe, raw()
|
|
- LLM prompt injection: see Phase 7 for comprehensive coverage
|
|
|
|
#### A04: Insecure Design
|
|
- Rate limits on authentication endpoints?
|
|
- Account lockout after failed attempts?
|
|
- Business logic validated server-side?
|
|
|
|
#### A05: Security Misconfiguration
|
|
- CORS configuration (wildcard origins in production?)
|
|
- CSP headers present?
|
|
- Debug mode / verbose errors in production?
|
|
|
|
#### A06: Vulnerable and Outdated Components
|
|
See **Phase 3 (Dependency Supply Chain)** for comprehensive component analysis.
|
|
|
|
#### A07: Identification and Authentication Failures
|
|
- Session management: creation, storage, invalidation
|
|
- Password policy: complexity, rotation, breach checking
|
|
- MFA: available? enforced for admin?
|
|
- Token management: JWT expiration, refresh rotation
|
|
|
|
#### A08: Software and Data Integrity Failures
|
|
See **Phase 4 (CI/CD Pipeline Security)** for pipeline protection analysis.
|
|
- Deserialization inputs validated?
|
|
- Integrity checking on external data?
|
|
|
|
#### A09: Security Logging and Monitoring Failures
|
|
- Authentication events logged?
|
|
- Authorization failures logged?
|
|
- Admin actions audit-trailed?
|
|
- Logs protected from tampering?
|
|
|
|
#### A10: Server-Side Request Forgery (SSRF)
|
|
- URL construction from user input?
|
|
- Internal service reachability from user-controlled URLs?
|
|
- Allowlist/blocklist enforcement on outbound requests?
|
|
|
|
### Phase 10: STRIDE Threat Model
|
|
|
|
For each major component identified in Phase 0, evaluate:
|
|
|
|
```
|
|
COMPONENT: [Name]
|
|
Spoofing: Can an attacker impersonate a user/service?
|
|
Tampering: Can data be modified in transit/at rest?
|
|
Repudiation: Can actions be denied? Is there an audit trail?
|
|
Information Disclosure: Can sensitive data leak?
|
|
Denial of Service: Can the component be overwhelmed?
|
|
Elevation of Privilege: Can a user gain unauthorized access?
|
|
```
|
|
|
|
### Phase 11: Data Classification
|
|
|
|
Classify all data handled by the application:
|
|
|
|
```
|
|
DATA CLASSIFICATION
|
|
═══════════════════
|
|
RESTRICTED (breach = legal liability):
|
|
- Passwords/credentials: [where stored, how protected]
|
|
- Payment data: [where stored, PCI compliance status]
|
|
- PII: [what types, where stored, retention policy]
|
|
|
|
CONFIDENTIAL (breach = business damage):
|
|
- API keys: [where stored, rotation policy]
|
|
- Business logic: [trade secrets in code?]
|
|
- User behavior data: [analytics, tracking]
|
|
|
|
INTERNAL (breach = embarrassment):
|
|
- System logs: [what they contain, who can access]
|
|
- Configuration: [what's exposed in error messages]
|
|
|
|
PUBLIC:
|
|
- Marketing content, documentation, public APIs
|
|
```
|
|
|