Skip to content

fix(http): replace User-Agent with X-Client-Info for CORS - #7

Merged
thinkclay merged 1 commit into
mainfrom
fix/cors-replace-user-agent
Jun 11, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/cors-replace-user-agent

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Summary

  • User-Agent is a forbidden request header per the Fetch spec — browsers either strip it or trip CORS preflight rejection against servers that don't list it in Access-Control-Allow-Headers.

  • Supabase Kong (the gateway in front of any /functions/v1/* baseUrl) only allows authorization, x-client-info, apikey, content-type, x-trpc-source. So every SDK call from a browser was failing with:

    Request header field User-Agent is not allowed by Access-Control-Allow-Headers

  • Switches the SDK to X-Client-Info, which is the Supabase convention and is in Kong's default allowed list. Same purpose (client identification), no preflight breakage.

Discovery

Surfaced immediately after #6 shipped — the apikey-header fix unblocked one CORS issue and exposed this one. Live reproduction on app.scaffald.com magic-link.

Test plan

  • pnpm test src/__tests__/http-client.test.ts — 21/21 pass
  • pnpm build — clean dual-format emit
  • Verified X-Client-Info appears in the built chunk

Backwards compat

  • No type signature changes.
  • Server-side callers (Node.js) had User-Agent: scaffald-sdk-js/0.1.0; they'll now see X-Client-Info: scaffald-sdk-js/0.1.0. If any consumer was filtering logs on the User-Agent string, they'll need to switch.

🤖 Generated with Claude Code

User-Agent is a forbidden request header per the Fetch spec — browsers
either strip it silently or, worse, trip CORS preflight rejection
against servers that don't list it in `Access-Control-Allow-Headers`.
Supabase Kong (the gateway in front of any /functions/v1/* baseUrl)
only allows `authorization, x-client-info, apikey, content-type,
x-trpc-source`, so every SDK call from a browser was failing with:

    Request header field User-Agent is not allowed by
    Access-Control-Allow-Headers

`X-Client-Info` is the Supabase-blessed equivalent and is in Kong's
default allowed list. Same purpose (client identification), no preflight
breakage.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@thinkclay
thinkclay merged commit e99ecee into main Jun 11, 2026
@thinkclay
thinkclay deleted the fix/cors-replace-user-agent branch June 11, 2026 07:41
thinkclay added a commit to Scaffald/SaaS that referenced this pull request Jun 11, 2026
…#342)

Picks up Scaffald/sdk#7. The previous SDK release (#6) unblocked the
apikey-header check at Kong, but exposed a second CORS-preflight failure:
the SDK was sending `User-Agent: scaffald-sdk-js/0.1.0`, which is a
forbidden request header in browsers and isn't in Kong's
`Access-Control-Allow-Headers` list. Browsers (esp. Safari) rejected
the preflight with:

    Request header field User-Agent is not allowed by
    Access-Control-Allow-Headers

The SDK now sends `X-Client-Info` instead, which Kong allows by default.

Also bumps scaffald-app patch version to 1.10.1.

Co-authored-by: Claude Opus 4.7 <[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