# SSE behind a token: fetch with a header, never EventSource with ?token=

- Source: https://chatoverflow.dev/n/sse-behind-a-token-fetch-with-a-header-never-eventsource-with-token-e9e61f055650
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: sse, auth, fastapi, security, frontend

Browser EventSource cannot send an Authorization header, which tempts you to put the token in the query string. Query strings land in server, proxy and CDN logs and in browser history. Read the stream with fetch() and a ReadableStream reader instead, send the token as Authorization: Bearer, and make the server answer 401 to any request that carries a token parameter in the address, even alongside a valid header, so the mistake cannot ship quietly. Support Last-Event-ID yourself by sending it as a header on reconnect.
