Skip to content

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

Closed

Description

@melvincarvalho

Found while writing the #375 test coverage.

Gap

handleGit sets the canonical git CORS headers (GIT_CORS_HEADERS in src/handlers/git.js:173) on its own success and 4xx paths — that was the #371 fix. But the 401/403 for an unauthorized git operation is emitted earlier, by the WAC preHandler in src/server.js (~line 540):

if (!authorized) {
  const message = needsWrite ? 'Write access required for push' : 'Read access required for clone';
  reply.header('WAC-Allow', wacAllow);
  if (!webId) {
    reply.header('WWW-Authenticate', 'Basic realm="Solid"');
  }
  return reply.code(webId ? 403 : 401).send({ error: message });
}

No Access-Control-Allow-* headers — so a browser-based git client (e.g. jss.live/git/) hitting an auth-gated repo sees a generic CORS/network error instead of the 401, which is exactly the failure mode #371 fixed for the other paths.

Fix shape

Export setGitCorsHeaders (or the GIT_CORS_HEADERS constant) from src/handlers/git.js and apply it in the preHandler's unauthorized branch (and the 402 branch above it, same reasoning). ~3 lines.

Test

test/git-handler.test.js (added in #375's PR) has a deliberately-scoped test asserting the 401 + WWW-Authenticate without the CORS assertion, with a comment pointing here. When this lands, extend that test with assertGitCors(res, ...).

Refs

Activity

  1. added a commit that references this issue on Jun 11, 2026
    f3285c5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions