How to add an Authorization header to GraphQL requests in the browser
To send a token on a web app's GraphQL calls, add a request header named Authorization with the value Bearer <token> in HeaderDial, limit it to the API host with a Domain filter, and tick only the xmlhttprequest request type. The token then goes on the fetch() POSTs to /graphql but not on page loads. In Chrome 159 and Firefox 158, a header added this way did not appear in the CORS preflight's Access-Control-Request-Headers. So the cross-origin call worked even though the server allowed only content-type. A page that sends Authorization itself needs the server to allow it.
How a GraphQL call reaches the server
Most GraphQL clients send each query as a fetch() POST with a JSON body:
POST /graphql
Content-Type: application/json
Authorization: Bearer eyJhbGciOi...
{"query":"{ viewer { name } }"}
When the API is on another origin (say the app is on app.example.com and the API on api.example.com), the JSON content type makes the call "preflighted". The browser first sends an OPTIONS request listing the headers the page wants to send in Access-Control-Request-Headers, and only sends the POST if the server's Access-Control-Allow-Headers answer allows them. The CORS guide explains simple and preflighted requests in more detail.
What we measured
We checked this with HeaderDial 0.3.0 in Chrome 159.0.8154.6 and Firefox 158.0.1 in November 2026. A page on http://127.0.0.1:port sent GraphQL queries to http://localhost:port/graphql, a different origin. The server answered preflights with Access-Control-Allow-Headers: content-type only, and logged every request. The HeaderDial rule set Authorization: Bearer test-token, limited to the domain localhost. Both browsers behaved identically. Edge uses Chrome's engine, but we did not test it separately.
| Request | No rule | Rule, no request types ticked | Rule, xmlhttprequest only | Rule, POST only |
|---|---|---|---|---|
Preflight OPTIONS | no token | token sent | token sent | no token |
Access-Control-Request-Headers on the preflight | content-type | content-type | content-type | content-type |
fetch() POST with JSON | no token; viewer was null | token sent; data returned | token sent; data returned | token sent; data returned |
fetch() POST as text/plain (no preflight) | no token | token sent, still no preflight | token sent, still no preflight | not tested |
Opening /graphql in a tab (a GraphiQL-style page) | no token | token sent | no token | no token |
WebSocket handshake to /graphql | no token | token sent | no token (tick websocket too: sent) | not tested |
Two things follow. A header that HeaderDial adds is not something the page asked for, so it is not declared in the preflight, and the server does not have to allow it. The preflight itself also counts as an xmlhttprequest request, so it carries the token unless you limit the rule to POST.
We also checked the case where the page sends its own Authorization:
Page sends Authorization: Bearer from-page | Result in both browsers |
|---|---|
Server allows only content-type, no rule | blocked; the preflight listed authorization,content-type |
Server allows only content-type, HeaderDial rule on | still blocked; the rule does not change what the preflight declares |
Server allows content-type, authorization, HeaderDial rule on | allowed; the server received HeaderDial's token, not the page's |
Steps
- Click the HeaderDial icon. In the site-access banner, choose Allow on all sites. If you allow single hosts instead, allow both the app's host and the API host.
- Click + Request header, type
Authorization(it is in the suggestions) and enterBearer, a space and your token. Keep the operation on set; it replaces any token the app sends itself. If the token is short-lived, choose an expiry such as 1 hour. - Open Where it applies, click + Only on…, choose Domain and enter the API host, for example
api.example.com. - Under Request types (none ticked = all, including page loads), tick xmlhttprequest. That covers
fetch()and XHR. If subscriptions run over a WebSocket and your server reads the token from the handshake headers, tick websocket too. - Optionally, under Methods, tick POST (and GET if your client sends persisted queries as GET). Preflights then go out without the token.
- Run a query that needs authentication, such as
{ viewer { name } }or{ me { id } }, and check that it returns data instead of an authentication error.
Subscriptions over WebSocket
A header rule can only change the WebSocket handshake, the GET request with Upgrade: websocket. Many subscription clients don't send the token there. The graphql-ws protocol, for example, lets the client send it in the payload of its first message, connection_init. HeaderDial cannot change message contents. Check which of the two your server reads before relying on the websocket type.
The curl equivalent
curl -s https://api.example.com/graphql \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
--data '{"query":"{ viewer { name } }"}'
curl sends no preflight, so a request that works in curl can still fail in the browser on CORS. Compare the two to tell an authentication problem from a CORS problem.
Pitfalls
fetch().- Preflights carry the token too. With no method ticked, the
OPTIONSrequest includesAuthorization. If your gateway authenticates preflights and rejects the token on them, tick POST so preflights go out without it. - The page's own token is replaced. With set, the server receives HeaderDial's value even when the app sends its own. That is useful for testing another user's token, and confusing if you forget the rule is on.
- Errors come back as 200. Many GraphQL servers answer authentication failures with HTTP
200and anerrorsarray, so check the response body, not just the status code in the Network panel. - Switch it off afterwards. Use the expiry select, or press Alt+Shift+D to pause every profile.
Add to ChromeFirefox: coming soon