fix(git): WAC preHandler 401/402/403 responses carry the git CORS headers — closes #548#550
Merged
Merged
Conversation
…ders (#548) The 401/403 for an unauthorized git operation is emitted by the WAC preHandler in src/server.js — before handleGit runs — and that path set WAC-Allow / WWW-Authenticate but not the git CORS headers. A browser-based git client (e.g. jss.live/git/) hitting an auth-gated repo therefore saw a generic CORS/network error instead of the 401 auth challenge — the exact failure mode #371 fixed for handleGit's own paths. Fix: export setGitCorsHeaders from src/handlers/git.js (it was module-private) and apply it on the preHandler's early returns — the 402 paymentRequired branch and the 401/403 unauthorized branch. The GIT_CORS_HEADERS doc comment is updated to name the new caller so it stays the single source of truth. The 402 branch gets the same one-line helper call as the tested 401/403 path; a dedicated 402 test would need a pay-gated git fixture, which is disproportionate to an identical mechanical call — the 401 test pins the helper's output. Test: the deliberately-scoped 401 test from #549 (which asserted WWW-Authenticate but NOT CORS, with a pointer comment at this issue) now asserts the full contract via assertGitCors. Test title, inline comment, and the file docstring all updated to match the new behaviour. Full suite: 934/934 passing. Closes #548.
There was a problem hiding this comment.
Pull request overview
Ensures browser-based Git clients can observe WAC preHandler failures (401/402/403) by attaching the same canonical Git CORS headers that handleGit already applies, closing the remaining gap identified in #548 (and aligning with the earlier #371 fix).
Changes:
- Export
setGitCorsHeadersfromsrc/handlers/git.jsso it can be reused outside the Git handler module. - Apply
setGitCorsHeaders(reply)to the Git WAC preHandler’s early-return 402 and 401/403 responses insrc/server.js. - Update the existing 401 contract test to assert the full Git CORS header set via
assertGitCors.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/handlers/git.js |
Exports setGitCorsHeaders and updates the single-source-of-truth CORS header documentation to include the new caller. |
src/server.js |
Adds Git CORS headers to WAC preHandler early returns (402 + unauthorized 401/403) so browsers don’t surface them as opaque CORS failures. |
test/git-handler.test.js |
Extends the unauthenticated push-advertise test to assert Git CORS headers are present on the WAC preHandler’s 401 response. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
melvincarvalho
added a commit
that referenced
this pull request
Jun 11, 2026
Eight PRs merged since 0.0.206 — IdP hardening, protocol conformance, and the de-Googled-phone (#46) arc: IdP / auth - #558 passkey login degrades cleanly on stale WebViews / insecure contexts instead of crashing — drops a redundant browser crypto.randomUUID and guards both ceremonies on secure-context + WebAuthn (closes #556) - #554 IdP login-form error now survives the POST→redirect→GET cycle (rode in a non-persisted field that Interaction.save() dropped); failed sign-ins show the error instead of a silent re-render (closes #514) - #551 RFC 9207 'iss' authorization-response param normalized to match the discovery issuer, so strict OIDC clients (solid-oidc) complete sign-in (closes #524) Tunnel - #555 opt-in, per-tunnel credential passthrough (Cookie / Authorization / Set-Cookie) so authenticated access works through a tunnel; the relay's own IdP session cookies are isolated from the tunnel client (closes #530) Content negotiation / git - #553 HEAD now mirrors GET's negotiated Content-Type / Content-Length / Cache-Control for files (RFC 9110 §9.3.2 parity) (closes #552) - #550 git WAC preHandler 401/402/403 responses carry the git CORS headers, so browser git clients see the status, not a CORS error (closes #548) - #549 first HTTP-contract coverage for the git handler + fixes a DATA_ROOT test-pollution bug (closes #375) Docs / metadata - #547 README tagline + npm keywords surface the agentic positioning (closes #406)
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.
Closes #548.
Bug
The 401/403 for an unauthorized git operation is emitted by the WAC preHandler in
src/server.js— beforehandleGitever runs — and that path setWAC-Allow/WWW-Authenticatebut not the git CORS headers. A browser-based git client (e.g. jss.live/git/) hitting an auth-gated repo saw a generic CORS/network error instead of the 401 auth challenge — the exact failure mode #371 fixed forhandleGit's own paths.Fix (+25/-13, the 3-line shape from the issue)
src/handlers/git.jssetGitCorsHeadersexported (was module-private);GIT_CORS_HEADERSdoc comment updated to name the new caller so it stays the single source of truthsrc/server.jssetGitCorsHeaders(reply)on the preHandler's two early returns: the 402paymentRequiredbranch and the 401/403 unauthorized branch — each with a comment tying it to #548/#371test/git-handler.test.jsWWW-Authenticatebut not CORS, with a pointer comment at this issue) now asserts the full contract viaassertGitCors. Test title, inline comment, and file docstring all flipped to matchOn the untested 402 branch
The 402 branch receives the same one-line helper call as the tested 401/403 path. A dedicated 402 test would require a pay-gated git fixture (payment config + funded request flow), which is disproportionate for a mechanically identical call — the 401 test pins the helper's emitted headers; the 402 difference is only which status precedes them.
Verification
test/git-handler.test.js: 8/8, with the 401 case now asserting all three CORS headersRefs
git-protocolheader in CORS preflight responses #371 — the original git CORS fix this completes