Skip to content

Add public-exposure-check workflow (gitleaks + commit metadata) - #1

Merged
paul-abb merged 5 commits into
mainfrom
infosec/public-exposure-check
Oct 29, 2026
Merged

paul-abb merged 5 commits into
mainfrom
infosec/public-exposure-check

Conversation

@paul-abb

@paul-abb paul-abb commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR change?

Adds .github/workflows/public-exposure-check.yml, a PR check meant to be required on every public sandbox-quantum repo through an org ruleset workflows rule. This repo is public because GitHub only lets public repos call or require public workflows.

What specific problem does this PR solve?

Commits to public repos can carry secrets or corporate email addresses. Once pushed to a public PR they're exposed for good, because refs/pull/* is permanent. The org "Email filter" rulesets refuse non-noreply authors on pushes to org repos, but commits in a fork PR are never pushed here, so they're only caught at merge, with a terse error, and the rulesets never look for secrets. This check gives every PR author, fork or not, early and clear feedback on both.

Without this change, a leaked token in a public PR is only caught by GitHub push protection (provider tokens only) or a later sweep.

How does this PR solve it?

On pull_request and merge_group, with contents: read only and no secrets:

  1. gitleaks over base..head with built-in rules forced on. The config and ignore list are read from the base branch, so a PR can't allowlist its own leak. The PR's .gitleaksignore is removed and inline gitleaks:allow comments are ignored. A malformed base config fails with a clear error naming the file.
  2. Commit metadata: a corporate email (@sandboxaq.com, @sandboxquantum.com, @sandbox-quantum.com or @sbt-ext.com, any subdomain) in author, committer or message (including Co-authored-by/Signed-off-by) fails. It's the same pattern the Email filter ruleset enforces at merge, so it adds no new rejections. A non-noreply address is a warning.
  3. Git attributes come from an empty tree (GIT_ATTR_SOURCE), so a PR can't add a .gitattributes entry such as *.ipynb -diff that makes git report files as binary and hides them from gitleaks.

Actions are pinned by SHA. gitleaks is checksum-verified. Untrusted PR data only reaches scripts through env:, and scanner output is wrapped in a random stop-commands token.

Rollout (org admin, after merge): add an org ruleset workflows rule targeting visibility:public and excluding email-privacy-exempt (so switch is out, matching the Email filter ruleset). Start in evaluate mode, then switch to active. Pin the workflows rule to a commit SHA of this file rather than main (or add a pull_request rule to this repo), because once it's required, a direct push to main here changes code that runs on every public repo's PRs.

Known limits: a secret introduced only while resolving a merge conflict (merge commits have no diff in git log -p) or stored through LFS isn't scanned, which is a gitleaks limitation. Retargeting a PR's base branch doesn't re-run the check, and GitHub doesn't run it on PRs with merge conflicts; the weekly public-repo monitor (sbt-secops#283) covers both gaps.

Testing

  • Controls, run from the workflow's own scripts (regenerated from this file):
    • clean PR: pass;
    • corporate author plus Co-authored-by: fail;
    • fake GitHub PAT: fail;
    • PR editing .gitleaks.toml to allowlist its own token: still fails;
    • inline gitleaks:allow: still fails;
    • malformed base .gitleaks.toml: clear error;
    • newline/::error:: injection in filenames and emails: escaped.
  • Blast radius (replayed):
    • open PRs: switch 34 of 60 would fail (it's excluded); switch-trust-sdk-py 1 of 10; the other public repos have none open;
    • recent merged PRs: 40–67% would have failed, almost all on corporate commit emails from before the Email filter went active on 2026-10-07.
  • Lint: actionlint is clean; zizmor (pedantic, offline) is clean.
  • Adversarial review: findings fixed (gitleaks:allow bypass, malformed-config traceback, unused workflow_call).
  • Real runner: run 37875674557 on 05112cc scanned 4963d13..05112cc (4 commits) on ubuntu-slim with 0 findings.
  • .gitattributes bypass (found in a second adversarial review, 2026-10-29): reproduced with gitleaks 8.30.1 and this workflow's flags; with *.ipynb -diff the token in a notebook was missed, and with GIT_ATTR_SOURCE set to the empty tree it was found. Also confirmed with plain git log -p on git 2.56. No in-scope public repo has a .gitattributes today.
  • Pins re-verified: actions/checkout 3d3c42e is tag v7.0.1, and the gitleaks v8.30.1 SHA256 matches GitHub's asset digest.

Tracking: INFOSEC-652 (parent INFOSEC-647).

🤖 Generated with Claude Code

Required-workflow candidate for public repos: fails a PR on a secret
(gitleaks, built-in rules forced on, base-branch config, inline allow
comments ignored) or a corporate email in commit author, committer or
message. Non-noreply addresses are warnings only.

Refs INFOSEC-652

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
python3 -I - <<'PY'
import os, re, subprocess, sys
base, head = os.environ["BASE_SHA"], os.environ["HEAD_SHA"]
corp = re.compile(r"(?i)[a-z0-9._%+-]*@([a-z0-9-]+\.)*(sandboxaq|sandboxquantum)\.com")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paul-abb Would it make sense to also filter the contractor domain(s)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Done in the latest commit: the check now treats sbt-ext.com (contractors) and sandbox-quantum.com (release bots) as corporate alongside sandboxaq.com/sandboxquantum.com, so they fail like other company addresses; personal domains stay warnings. Controls: contractor author, bot co-author and corporate author fail; Gmail and a look-alike (notsbt-ext.com) warn; noreply passes. Outside switch (excluded), no commit in the last 90 days would newly fail. The same change is in the weekly monitor (sbt-secops#283).

Adds sbt-ext.com (contractor accounts) and sandbox-quantum.com (release
bots) to the corporate-email pattern alongside sandboxaq.com and
sandboxquantum.com, as suggested in review. Outside switch, which is
excluded, no commit in the last 90 days would newly fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@sbq-nikolai sbq-nikolai left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Please add some test cases or evidence this is working on a repo that is not at root.
  • What's the impact on our worker budget since we like to spam a bunch of PRs?
  • Any reason to run this on ubuntu and not something smaller?

paul-abb and others added 2 commits October 8, 2026 22:14
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Annotations without a file land on the workflow file, which a required
workflow shows as '.github'. Prefer a file the commit changed that is in
the PR diff, so the error shows in Files changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@paul-abb

paul-abb commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks. All three addressed, with test evidence:

Not at root: ran it end to end as a ruleset-required workflow in a throwaway private repo (org ruleset with a workflows rule pinned to this PR's head, plus a merge queue). Results:

case expected result
clean change in a nested dir pass pass; merged through the merge queue (merge_group run passed)
base .gitleaks.toml, merged through the queue pass pull_request and merge_group runs both passed; merged
corporate author/committer fail fail
corporate Co-authored-by trailer only fail fail
fake PAT in a nested file (services/app/config/settings.py) fail fail, annotated on that file
token + the PR's own .gitleaks.toml allowlist fail fail (config is read from base)
token + inline gitleaks:allow fail fail
token in a path the base config allowlists pass pass
token added then removed within the PR fail fail (every commit is scanned)
personal non-noreply email pass + warning pass, 2 warnings
merging a failing PR blocked blocked by the ruleset, both via the queue and a direct merge

Runner: switched to ubuntu-slim (1 vCPU container, GA). gitleaks now installs to $RUNNER_TEMP/bin without sudo. Every run above was on ubuntu-slim.

Budget: runs took 7–14 s. Standard hosted runners are free and unlimited on public repos, and the ruleset only targets public repos (switch excluded). The in-scope repos had ~44 pushes to PRs in the last 30 days. Full history is cheap: the largest in-scope repo clones in ~1 s, and even switch (3,881 commits) clones in ~3 s. cancel-in-progress drops superseded runs.

I also anchored the commit-metadata annotations to a file the offending commit changed, so they show in Files changed instead of on the workflow file. All cases above were re-run on the latest commit (05112cc).

@paul-abb
paul-abb requested a review from sbq-nikolai October 9, 2026 02:46
@paul-abb
paul-abb merged commit 7bc87a8 into main Oct 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants