fix(ipr): replace LEDGER_REMOTE_PATTERN regex with URL parser + regression test#3642
Merged
Conversation
…ssion test (closes #3635) scripts/ipr/check-and-record.mjs previously used a regex (LEDGER_REMOTE_PATTERN) to guard the push target of signature-ledger writes. The regex was both narrow (rejected bare-URL origins, fixed in #3532 by making credentials optional) and fragile (relied on backtracking semantics around the literal `@`). Replace it with isLedgerRemoteAllowed() in scripts/ipr/ledger-remote.mjs, which parses the remote URL via `new URL()` and explicitly checks scheme=https, host=github.com, and pathname=/adcontextprotocol/adcp (after stripping a single trailing `/` and `.git`). Credentials in userinfo are ignored; default-port https is accepted; SSH and non-https URLs throw at parse time and are rejected. tests/ipr-ledger-remote.test.mjs pins the accept/reject matrix so future workflow tweaks (token rotation, checkout version bumps, mirror introduction) can't silently re-narrow the guard the way the original regex did. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #3635.
#3532 fixed a one-character bug in
scripts/ipr/check-and-record.mjsLEDGER_REMOTE_PATTERNthat was silently rejecting bare-URL git remotes (the shapeactions/checkout@v6produces). The fix was correct, but the underlying mechanism — a regex that depends on backtracking semantics around the literal@— is the kind of code that breaks again the next time anyone touches it. This PR replaces it with a URL parser and pins the accept/reject matrix as a unit test.Changes
scripts/ipr/ledger-remote.mjsexportingisLedgerRemoteAllowed(url). Parses withnew URL()and explicitly checks scheme, host, and normalized path. Credentials in userinfo are ignored; default-port https is accepted; SSH and other schemes are rejected at thenew URL()step or at the protocol check.scripts/ipr/check-and-record.mjs—assertLedgerRemote()now calls the helper. Removed the regex constant.tests/ipr-ledger-remote.test.mjs— 17 cases covering the matrix from the issue plus default-port and unparseable inputs.Why this is the right shape
The regex tried to express a structural property ("this URL is github.com over https for adcontextprotocol/adcp, regardless of credentials") via character-class arithmetic. The URL parser checks the structural property directly. Reading the function tells you exactly which URLs pass — no need to mentally simulate backtracking. The accept/reject set is now also documented machine-checkably in the test.
Test plan
npx vitest run tests/ipr-ledger-remote.test.mjs— 17/17 passnpm run typecheck— clean:8443, host-confusion via userinfo to a non-github host)actions/checkoutis known to emit (bare or credentialed)🤖 Generated with Claude Code