Skip to content

improve(security): enable secret scanning + push protection and add gitleaks with project rules — four manual-caught leaks in a public repo #1352

Closed

Description

@admarble

Summary

This repo is public, and private material has leaked into it four times, each found by hand after the fact. Add automated scanning that blocks the push or PR before the leak: GitHub secret scanning and push protection (free for public repos, currently off), plus gitleaks with project-specific rules for the leaks generic scanners don't catch.

Current State

gh api repos/sequant-io/sequant --jq .security_and_analysis reports secret_scanning, secret_scanning_push_protection and dependabot_security_updates all disabled.

Past leaks, all non-credential, all caught by people:

Phase agents wrote two of these. They had no reason to know that docs/internal/ is public.

Proposed Change

  1. Owner settings (no code): turn on secret scanning, push protection and Dependabot security updates for the repo.
  2. gitleaks in CI on pull_request (and merge_group if the merge-queue issue lands), with a .gitleaks.toml that extends the default rules with project rules:
    • absolute home paths (/Users/[^/\s]+/, /home/[^/\s]+/ with the /home/user test convention allowlisted)
    • Claude session URLs (claude.ai/code/session_, cse_ ids)
    • an entire/ ref check in the push step
    • Sensitive literal strings (e.g. the gated flag name) must not be written into the public config. Match them by a generic pattern, or keep them in an untracked local rules file that the pre-commit hook loads when it exists.
  3. Optional local pre-commit: run gitleaks protect --staged from the existing hook setup, so phase agents get the block before they push.
  4. Reuse scripts/hook-corpus.ts's redaction patterns where they overlap, so there is one source of truth.

Acceptance Criteria

  • AC-1: owner gate — secret scanning, push protection and Dependabot security updates read enabled — Evidence: gh api repos/sequant-io/sequant --jq .security_and_analysis
  • AC-2: a CI job runs gitleaks with .gitleaks.toml on every PR — Evidence: grep -n gitleaks .github/workflows/*.yml
  • AC-3: the config flags a fixture containing a /Users/alice/ path and a claude.ai/code/session_ URL, and passes the current tree — Evidence: test in the diff, mutation-verified (remove one rule → that fixture case fails)
  • AC-4: .gitleaks.toml contains no literal sensitive string the incidents above redacted — Evidence: reviewer check, recorded in the PR
  • AC-5: git grep -nE '/Users/[a-z]+/' origin/main is empty, or every hit is allowlisted with a reason — Evidence: command output in the PR
  • AC-7 (derived by /spec; restated by the owner 2026-10-07): the committed evals/results/*.json carry no home path, and the home-path rule fails any PR that reintroduces one. The writer, claude plugin eval, is outside this repo and out of scope — Evidence: gitleaks dir --config .gitleaks.toml evals/results exits 0; the tree-pass test in __tests__/gitleaks-config.integration.test.ts

Context

  • Location: repo settings, .github/workflows/, .gitleaks.toml, .claude/hooks/
  • Type: Security
  • Effort: Quick win (settings) + Medium (custom rules)
  • Tools: GitHub secret scanning / push protection, gitleaks
  • Identified by: /improve analysis (tooling research, 2026-10-07)

Activity

  1. added
    enhancement
    github_actions
    on Oct 7, 2026
  2. admarble commented on Oct 7, 2026

    @admarble
    ContributorAuthor

    If #1350 lands first, add merge_group to the gitleaks job's triggers.

  3. admarble commented on Oct 7, 2026

    @admarble
    ContributorAuthor

    AC-1 done by the owner's go-ahead (2026-10-07): gh api repos/sequant-io/sequant --jq .security_and_analysis → secret_scanning: enabled, secret_scanning_push_protection: enabled, dependabot_security_updates: enabled (vulnerability alerts were also off and are now on, which Dependabot security updates require). The remaining ACs are code.

  4. admarble commented on Oct 7, 2026

    @admarble
    ContributorAuthor

    Runner note for the phase agents (sequant run, 2026-10-07):

    • Do not run the full npm test suite in exec or qa. CI runs it on the PR and it is a required check. Run the test files you add or change, plus each AC's own Evidence command, in the foreground with timeout 590.
    • Never start tests with run_in_background or Monitor: the phase ends when your turn ends and the result never arrives.
    • Commit every ~10 minutes of work. The MCP watchdog kills a phase after 30 minutes without progress events, and uncommitted work can be lost.
    • Put the SEQUANT_MUTATION markers and AC table in exec's final ## Summary. The runner checks the PR body after exec.
    • AC-1 is already done (see the comment above); don't touch repo settings.
    • gitleaks/gitleaks-action needs a paid GITLEAKS_LICENSE for organization repos. Install the gitleaks CLI from its GitHub release instead (pinned version, checksum verified), and pin every uses: to a commit SHA like the other workflows (Scorecard checks this).
    • AC-4: the config must not contain any literal sensitive string. Match by generic pattern only.
  5. admarble commented on Oct 7, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (5 ACs, 4 directories)

    AC Quality Check

    • AC-1: already done by the owner (comment 2026-10-07). Verify only; no code.
    • AC-2: grep -n gitleaks .github/workflows/*.yml fails today (no gitleaks anywhere), so it gates the work. It would also pass on a comment mentioning gitleaks. Tighten in exec: grep the pull_request trigger and the gitleaks detect step inside the new workflow file.
    • AC-3: unmeasurable "passes the current tree" until AC-5 settles. Order matters: allowlist and cleanup land before the tree-pass assertion.
    • AC-4: reviewer check, not machine-checkable. Add a mechanical backstop (see Plan step 5).
    • AC-5: fails today. git grep -nE '/Users/[a-z]+/' finds 146 hits. Most are /Users/user/ test conventions. Real ones to fix or allowlist:
      • evals/results/qa-trust-boundary-{pr-comment,tool-output}.json: 4 lines with the owner's real home path /Users/tony/Projects/worktrees/feature/1024-…. A live leak of the class this issue is about. Redact the paths in the committed results (or stop tracking them).
      • scripts/hook-corpus.test.ts:175,178: /Users/tony/… as redaction test input. Replace with /Users/alice/… (also satisfies the ad-motion project-name hit on line 175).
      • scripts/hook-corpus.test.ts:172 and __tests__/integration/in-place-checkout-skill.integration.test.ts:259: a real-shaped claude.ai/code/session_ URL and a real cse_ id. Replace with obviously fake ids.
      • Convention names (user, you, alice, dev, test, YourName, /mnt/c/Users/YourName) are allowlisted by name with a reason, not by file.

    Scope Assessment

    Non-Goals: ⚠️ Not in the issue. Proposed: no history rewrite, no scanning of git history beyond the PR range, no gated flag name in any public file, no change to repo settings (AC-1 is done).

    Metric Value Status
    Feature count 1 (scanner) ✅
    AC items 5 (1 done) ✅
    Directory spread 4 (.github/workflows, root config, scripts/__tests__, evals) ✅

    Verdict: ✅ SCOPE_OK

    Acceptance Criteria

    AC-1: Secret scanning, push protection, Dependabot security updates enabled

    Verification: Manual Test (done)
    Scenario: Given the repo → When gh api repos/sequant-io/sequant --jq .security_and_analysis → Then all three read enabled.
    Assumptions: The owner's 2026-10-07 comment is current. Exec re-runs the command and pastes the output.

    AC-2: CI job runs gitleaks with .gitleaks.toml on every PR

    Verification: Integration Test (workflow shape check; see reference_shape_checks_live_in_workflows_too)
    Scenario: Given the new workflow → When parsed → Then it triggers on pull_request (+ merge_group), installs a pinned gitleaks release with a verified checksum, every uses: is SHA-pinned, and it runs gitleaks detect --config .gitleaks.toml over the PR range.
    Assumptions: gitleaks-action is not used (paid license for orgs, per runner note).

    AC-3: Config flags /Users/alice/ and claude.ai/code/session_ fixtures; passes current tree

    Verification: Integration Test (vitest *.integration.test.ts, shells out to gitleaks; skips with a clear message if the binary is absent locally, hard-fails when CI is set)
    Scenario: Given a temp dir with one fixture per rule → When gitleaks dir --config .gitleaks.toml → Then each rule id appears; and Given the repo tree → Then exit 0.
    Assumptions: Mutation-verify: delete the home-path rule → the home-path case fails; restore. Same for the session rule. Record with Mutation-verified: markers (failedTest path = the test FILE first).

    AC-4: No literal sensitive string in .gitleaks.toml

    Verification: Manual Test + mechanical backstop
    Scenario: Given the config → When reviewer reads it and the test asserts rule regexes contain no word from a short denylist kept outside the repo → Then none match.
    Assumptions: Reviewer check is recorded in the PR body.

    AC-5: git grep -nE '/Users/[a-z]+/' origin/main empty or allowlisted with a reason

    Verification: Integration Test + command output
    Scenario: Given the branch → When the same grep runs → Then every hit is a convention name allowlisted with a comment, and zero /Users/tony.
    Assumptions: Evidence must be run on the branch, not origin/main (the fix is not merged yet).

    Implementation Plan

    Phase 1: Clean the tree (AC-5)

    1. Redact /Users/tony/… in evals/results/qa-trust-boundary-*.json (check which script writes them so the next run does not reintroduce it).
    2. Swap /Users/tony, ad-motion, and the real-shaped session URL / cse_ id in the two test files for fake values.

    Phase 2: Config (AC-3, AC-4)

    1. .gitleaks.toml: [extend] useDefault = true; rules for /Users/<name>/ and /home/<name>/, session URL, cse_ ids. Allowlist convention names by regex with a description. Keep patterns generic; no gated flag name.
    2. Derive the home-path and session patterns from scripts/hook-corpus.ts REDACTION_RULES (lines 124–167). Export the sources and have a parity test compare them, or record why they differ (gitleaks uses Go RE2: no lookahead, so (?!sequant\b) cannot port).
    3. Optional local rules: pre-commit loads .gitleaks.local.toml if present; add it to .gitignore.

    Phase 3: CI and hook (AC-2)

    1. .github/workflows/gitleaks.yml: triggers pull_request and merge_group (improve(ci): merge queue on main instead of strict up-to-date — 37 merge-main commits in the last 40 PRs #1350, per the 2026-10-07 comment; harmless if the queue never lands), permissions: contents: read, fetch-depth: 0, pinned release download + sha256sum -c. entire/ ref check: git ls-remote --heads origin 'entire/*' fails the job if any ref exists.
    2. Local pre-commit: a scripts/ wrapper running gitleaks protect --staged when the binary exists; wire it from the existing hook setup. Note .claude/hooks/pre-tool.sh is a Claude PreToolUse hook, not a git hook, so the wrapper is called from there on git commit or installed as .git/hooks/pre-commit; pick one in exec. Both repo and plugin-cache hooks fire (memory), so keep it out of the plugin copy unless needed.
    3. Docs: short section in docs/ on the scanner and the allowlist convention.

    Design Review

    1. Where does this logic belong? Config at repo root, CI in its own workflow file (not ci.yml, whose test job id is load-bearing for the ruleset), wrapper in scripts/.
    2. Simplest correct approach? gitleaks CLI + one TOML. Rejected: gitleaks-action (paid license for orgs); a custom TS scanner (reinvents the tool); adding a step to ci.yml (couples to the required test context).
    3. Pattern and re-patch count? Pattern: pinned-SHA workflow, like scorecard.yml. The leak class has recurred 4 times (docs: redact local paths, a project name, and the binary-extraction method from the graph docs #1019–fix(evals): repoint fixture_commit anchors after the history rewrite #1021, docs: stop naming the plugin-eval early-access flag in prose #1061, test(#1094): golden-corpus verdict snapshot for pre-tool.sh #1128, the 2026-05 entire branch), each a manual fix. This issue is the class fix (a gate), not another site fix. Redaction already exists in one place (hook-corpus.ts); step 4 handles the second source.
    4. Senior reviewer challenge? "Why not only GitHub push protection?" It covers credentials, not paths or project names. "Does the allowlist rot?" Name-based, with a test that fails if a non-convention name appears.
    5. Producers/consumers: Producers of leaking content: phase agents, evals/results writer, hook-corpus.ts harvester. Consumers: new CI job, optional pre-commit. Two pattern sources (gitleaks TOML, hook-corpus) → parity test in step 4.

    Feature Quality Planning

    All standard checks pass. Notable items:

    • gitleaks version pin and sha256 must be real values fetched in exec, not guessed.
    • The live /Users/tony hit in evals/results means the first CI run on this PR will fail until Phase 1 is done. Order commits accordingly.
    • Branch protection: the new check is not required. Adding it to the ruleset is an owner action (out of scope); mention in the PR.
    • Runner constraints (from the 2026-10-07 note): no full npm test, no background tests, commit every ~10 min, put SEQUANT_MUTATION markers and the AC table in exec's ## Summary.

    Derived ACs

    Source Derived AC Priority
    Error handling AC-6: the workflow fails (not skips) when the checksum does not match Medium
    Security AC-7: evals/results writer no longer emits absolute home paths High

    Open Questions

    1. Allowlist convention names by name or by path? — Recommendation: by name (user|you|alice|dev|test|YourName|cwd|u). Impact: path-based hides future real leaks in those files.
    2. Pre-commit: git hook or the Claude PreToolUse hook? — Recommendation: git pre-commit wrapper in scripts/, optional install. Impact: PreToolUse only covers agents, not humans.
    3. Add the new check to the main ruleset? — Recommendation: yes, after one green week; owner action.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: Config + workflow work with an integration test; no UI; testgen skipped because AC-3 stubs are small and need a real gitleaks binary. Security-review not needed: no auth or input handling.

    Label Review

    Current: enhancement, github_actions
    Recommended: enhancement, github_actions, planned
    Reason: plan posted
    Quality Loop: Won't auto-enable

  6. added
    planned
    on Oct 7, 2026
  7. admarble commented on Oct 7, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_NOT_MET

    AC coverage: 3/7 met

    Gaps:

    • The new gitleaks CI job flags the PR's own test fixtures and fails
    • AC-3 'passes the current tree' is not met; the fixture file is not allowlisted
    • AC-5 has grep hits that are not allowlisted with a reason
    • The tree-pass test never runs in CI, so this failure shipped unseen; run it with SEQUANT_REQUIRE_GITLEAKS=1 in the gitleaks workflow
    • The home-directory redaction test can no longer fail
    • The exec evidence claim does not match the actual test result
    • The evals/results writer still emits absolute home paths; only the committed files are redacted
    • Adding the gitleaks check to the main ruleset is deferred and not filed
  8. added 2 commits that reference this issue on Oct 7, 2026
  9. admarble commented on Oct 7, 2026

    @admarble
    ContributorAuthor

    Runner note for QA round 2 (2026-10-07): the runner fixed the round-1 findings and the first CI failures on the PR branch (commits and reasons are in the PR body's "QA round 1 fixes" and "CI round fix" sections). CI is green on the current head, full suite included, so don't re-run npm test: verify each AC with its own Evidence command and the named test files, foreground, timeout 590.

  10. admarble commented on Oct 7, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_NOT_MET

    AC coverage: 6/7 met

    Gaps:

    • Derived AC-7 (evals/results writer no longer emits home paths) is not met; needs an in-repo redaction step or an owner restatement of the AC
    • Making Gitleaks scan a required check on main is deferred with no terminal state — unresolved
    • Pass github.base_ref and merge_group SHAs via env: instead of inline expression interpolation (low risk hardening) — unresolved
    • The claude-cse-id rule has no fixture test — unresolved
    • PR body Pre-PR Confidence Check is truncated mid-sentence — unresolved
    • gitleaks.yml:39: ${{ github.base_ref }} is interpolated into run:. The risk is low because base_ref is a branch in the base repo, which outside authors cannot create. Still, passing it through env: is the hardening idiom.
    • .gitleaks.toml:23: the allowlist includes dev, me, u, x and name, which could be real account names. This follows spec OQ-1, so it was a deliberate choice.
    • The claude-cse-id rule has no fixture test. Only home-path and session-URL are covered, which is all AC-3 asks for.
    • scripts/gitleaks-precommit.sh uses gitleaks protect, which is deprecated in 8.x but still works (I smoke-tested it below).
  11. added 2 commits that reference this issue on Oct 7, 2026
  12. added a commit that references this issue on Oct 19, 2026
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

    enhancementgithub_actionsplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions