Skip to content

fix(git): WAC preHandler 401/402/403 responses carry the git CORS headers — closes #548#550

Merged
melvincarvalho merged 1 commit into
gh-pagesfrom
issue-548-git-cors-401
Jun 10, 2026
Merged

fix(git): WAC preHandler 401/402/403 responses carry the git CORS headers — closes #548#550
melvincarvalho merged 1 commit into
gh-pagesfrom
issue-548-git-cors-401

Conversation

@melvincarvalho

Copy link
Copy Markdown
Contributor

Closes #548.

Bug

The 401/403 for an unauthorized git operation is emitted by the WAC preHandler in src/server.js — before handleGit ever 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 saw a generic CORS/network error instead of the 401 auth challenge — the exact failure mode #371 fixed for handleGit's own paths.

Fix (+25/-13, the 3-line shape from the issue)

Touch Change
src/handlers/git.js setGitCorsHeaders exported (was module-private); GIT_CORS_HEADERS doc comment updated to name the new caller so it stays the single source of truth
src/server.js setGitCorsHeaders(reply) on the preHandler's two early returns: the 402 paymentRequired branch and the 401/403 unauthorized branch — each with a comment tying it to #548/#371
test/git-handler.test.js 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 file docstring all flipped to match

On 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 headers
  • Full suite: 934/934 passing

Refs

…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.

Copilot AI 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.

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 setGitCorsHeaders from src/handlers/git.js so 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 in src/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
melvincarvalho merged commit 666f7db into gh-pages Jun 10, 2026
2 checks passed
@melvincarvalho
melvincarvalho deleted the issue-548-git-cors-401 branch June 10, 2026 19:04
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)
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.

git: WAC preHandler 401/403 responses lack the git CORS headers — browser clients see a CORS error instead of the status

2 participants