Skip to content

fix(ci): require trusted runner-policy owner evidence - #95

Merged
kyle-sexton merged 1 commit into
mainfrom
codex/fail-closed-owner-evidence
Jul 13, 2026
Merged

kyle-sexton merged 1 commit into
mainfrom
codex/fail-closed-owner-evidence

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Jul 13, 2026 •

Copy link
Copy Markdown
Member

Summary

  • require externally supplied GITHUB_REPOSITORY identity before applying owner-scoped selector-pin approvals
  • treat checked-in repositoryOwner as inventory and a mismatch tripwire, never as authorization evidence
  • document explicit trusted context for local runs and cover missing, matching, mismatched, and config-omitted owner cases

Root cause

When GITHUB_REPOSITORY was absent, the analyzer trusted the audited policy file's own repositoryOwner. A repository could therefore self-declare an approved owner and unlock approvedSelectorReferencesByRepositoryOwner.

Impact

GitHub Actions continues to work through its default GITHUB_REPOSITORY environment. Local callers must now provide trusted repository identity explicitly; a configured owner can only corroborate or reject that identity.

Validation

  • runner-policy tests: 95/95 passed
  • runner-policy analyzer: passed
  • Markdownlint: passed
  • Lefthook validation: passed
  • Biome: passed
  • staged diff check: passed
  • signed pre-commit hooks: passed (typos, EditorConfig, Gitleaks, Markdownlint, Biome)

Note

High Risk
Changes authorization for owner-scoped selector approvals in the CI policy gate; incorrect rollout could block legitimate owner-scoped pins locally or in CI, though the change tightens trust boundaries rather than relaxing them.

Overview
Closes a fail-open path where missing GITHUB_REPOSITORY let the analyzer treat .github/runner-policy.json#repositoryOwner as proof of identity, so a repo could self-declare an approved owner and unlock approvedSelectorReferencesByRepositoryOwner.

resolveRepositoryOwner now returns no owner unless caller-supplied GITHUB_REPOSITORY is present and valid; checked-in repositoryOwner only corroborates or rejects that external evidence (mismatch still fails closed). Owner-scoped selector pins therefore require trustworthy identity—typically GitHub Actions’ default GITHUB_REPOSITORY in CI.

Docs require explicit GITHUB_REPOSITORY for local runs (shell/PowerShell examples). Tests cover missing identity, matching/mismatched owners, and ownerless config with external evidence. Globally approved selectors are unchanged.

Reviewed by Cursor Bugbot for commit 50e97d0. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor

cursor Bot commented Jul 13, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_89211f2e-8657-484f-8505-55e97340f266)

@claude

claude Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Claude finished @kyle-sexton's task in 1m 43s —— View job


PR Review: fix(ci): require trusted runner-policy owner evidence

  • Gather context and read changed files
  • Review CLAUDE.md / REVIEW.md guidelines (none present)
  • Analyze runner-policy.mjs logic changes
  • Analyze test coverage in runner-policy.test.mjs
  • Review README documentation updates
  • Check distribution/README.md changes
  • Synthesize findings and post review

Summary

This PR closes a real authorization-bypass vulnerability: before the fix, a repository could self-declare repositoryOwner in its checked-in .github/runner-policy.json and unlock approvedSelectorReferencesByRepositoryOwner during local analysis — without any external identity evidence. The fix is minimal, targeted, and correct.


Logic change — resolveRepositoryOwner (runner-policy.mjs:1621)

Before: return githubOwner ?? configuredOwner — fell back to the audited file's own repositoryOwner when GITHUB_REPOSITORY was absent.

After: early-returns undefined when githubRepository === undefined — the audited config can only corroborate or reject external identity, never supply it.

Mismatch guard tightening: the old guard was if (githubOwner && configuredOwner && ...). Removing the githubOwner && prefix is safe: after the early-return and regex check, githubOwner is always a non-empty string at that point (the GITHUB_REPOSITORY regex requires at least one [A-Za-z0-9] before /). The removed guard was dead code.

No issues with this change.


Test coverage (runner-policy.test.mjs:793)

The test suite now exercises all four combinations of the new semantics:

Scenario Before After
Config declares owner, no GITHUB_REPOSITORY ✅ passes (bug) ❌ 1 selector-pin finding
Config declares owner + matching GITHUB_REPOSITORY ✅ passes ✅ passes
Config declares owner + mismatched GITHUB_REPOSITORY ❌ 1 finding ❌ 1 finding
Config omits owner + valid GITHUB_REPOSITORY ❌ 1 finding (was "evidence unavailable") ✅ passes

The rename of the ownerlessRoot sub-case is particularly important: a repo without a config repositoryOwner can now successfully claim an external identity via GITHUB_REPOSITORY. This is intentional and the test confirms it.

One minor observation: the test checks for the exact selector-pin rule on the self-declared case, but verifies the message only via a regex (/owner-scoped.*owner evidence is unavailable/). That ties it to the selectorStatus message at runner-policy.mjs:922, which still uses policy.repositoryOwner (now undefined) to select the message. This is correct — the message "trustworthy repository owner evidence is unavailable" fires as expected.

No coverage gaps found.


Documentation

README changes accurately characterize the new contract:

  • repositoryOwner is "inventory and a mismatch tripwire only; it never authorizes" — correct.
  • Local run instructions now include GITHUB_REPOSITORY=owner/repository — necessary and correct.
  • PowerShell equivalent is a nice addition for Windows contributors.
  • The distribution/README.md clarification that GITHUB_REPOSITORY is the trusted source aligns with what GitHub Actions provides by default.

Verdict

Approve. The fix is correct, the tests are comprehensive, and the documentation is accurate. No bugs, no regressions, no missing cases.

@cursor cursor Bot 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.

Risk: medium. Not approving: Cursor Bugbot skipped (usage limit reached) and did not produce a clean automated review signal. Human review is needed before merge; no reviewers were assigned because no eligible non-author reviewers are available in this repository.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Router and Approver

@kyle-sexton
kyle-sexton merged commit f893654 into main Jul 13, 2026
4 checks passed
@kyle-sexton
kyle-sexton deleted the codex/fail-closed-owner-evidence branch July 13, 2026 03:59
kyle-sexton added a commit that referenced this pull request Oct 6, 2026
…publish (#723)

Closes #707

## Summary

The pages Worker (melodic-software/provisioning#705) scans a normalized
copy of every upload, but `pages-publish` scanned only the raw bytes.
Its early check therefore missed HTML-escaped, tag-split and
JSON-escaped credential, path and hostname shapes. The client now scans
decoded copies too, so it refuses an upload, or forces it private,
before sending. The Worker remains the enforcing layer.

## Fix

- `components/cloud-environment/pages-publish` builds two decoded copies
in linear POSIX-awk passes, with no new dependency:
- **Host copy**: exactly the Worker's `normalize()`. Tags are stripped.
`&#NN;`, `&#xHH;`, amp, lt, gt, quot, apos and nbsp are decoded only
when the `;` is present. `\\` becomes `\`. A credential found here exits
4, the same page the Worker would refuse with a 422.
- **Wide copy**: adds the extra named entities, numeric entities without
their `;`, and JS escapes (`\/`, `\"`, `\uXXXX`, `\u{…}`, `\xHH`). A
credential found only here forces the page private instead of refusing
it.
- An invalid decoded code point (NUL, above U+10FFFF, or overlong)
becomes U+FFFD, so it never joins two fragments into a token shape.
- Machine-path and hostname shapes only ever force private, on the raw
copy and both decoded copies. gitleaks, when present, runs on the raw
page.
- Path shapes are reconciled with
`components/path-detection/machine-path-patterns.sh`:
- `setup.sh` installs the script as a single file, so the five `HPP_*`
bodies are copied in word for word, and a test fails if the copy and the
library differ.
- On decoded copies they add home paths with no trailing slash, the
forward-slash and 8.3 Windows forms, and Windows checkout roots.
- The cloud-environment README documents the decoded scan and a
**Rollout of the decoded scan** paragraph (lifecycle exception for a
check that blocks from day one, with the Worker evidence below). The
path-detection README names the embedded copy.

## Verification

- `bash components/cloud-environment/pages-publish.test.sh`: 233
assertions pass.
- The escaped-form, HPP-only-shape, invalid-code-point and sync tests
all fail against the old script.
  - Tests pin which escaped forms are refused and which go private.
  - An escaped placeholder and stray entities stay public.
  - A 2 MiB single line of each separator scans in under 20 s.
- The Worker's own `scan()` (provisioning main `0809074`) was run over
the samples.
- It flags the entity, hex-entity and tag-split token forms. The client
refuses those.
- It flags nothing for the `_`, `\"`, `_` and `&#95`-without-`;`
forms. The client forces those private.
- `machine-path-patterns.test.sh` and `setup.test.sh` pass. shellcheck,
`shfmt -i 2 -ci -d` and markdownlint-cli2 are clean. The ci-workflows
`check-machine-specific-paths.sh` driver reports nothing.
- Follow-ups left out of scope:
- the Worker's "fleet hostname" and `CLOUDFLARE|CF_API_TOKEN` shapes,
which the client lacks;
  - a pre-existing `pgup_` length mismatch (client 16+, Worker 20+).

## Related

- melodic-software/provisioning#705 (the Worker's normalized scan,
`cloudflare/pages-worker/src/scan.js`)
- `components/path-detection/machine-path-patterns.sh`
- #717 (vault-exec `-q`, same component)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01G3BsUv4VeQ81gAPhk73xvs

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant