-
Notifications
You must be signed in to change notification settings - Fork 25
Avoid usePropagateHeaders potential header duplication #1563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a header duplication issue in the usePropagateHeaders
plugin where request IDs could be duplicated when forwarding headers from subgraphs to clients. The issue occurs because useRequestId
sets the request ID header and then usePropagateHeaders
appends it again when forwarding response headers.
- Adds a duplicate value check before appending headers in the
fromSubgraphsToClient
flow - Prevents header duplication by comparing values before appending to response headers
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
if (value) { | ||
for (const v of value) { | ||
response.headers.append(key, v); | ||
if (v !== response.headers.get(key)) { |
Copilot
AI
Sep 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comparison v !== response.headers.get(key)
only checks against the first header value when multiple values exist for the same key. response.headers.get(key)
returns the first value or null, but headers can have multiple values. This could still allow duplicates if the header already exists with multiple values. Consider using response.headers.getSetCookie()
for set-cookie headers or checking if the value already exists in the complete list of values.
if (v !== response.headers.get(key)) { | |
// Check if the value already exists among all values for this header | |
const existingValues = | |
key.toLowerCase() === 'set-cookie' && typeof response.headers.getSetCookie === 'function' | |
? response.headers.getSetCookie() | |
: response.headers.get(key) | |
? response.headers.get(key).split(',').map(s => s.trim()) | |
: []; | |
if (!existingValues.includes(v)) { |
Copilot uses AI. Check for mistakes.
4f62016
to
21a8893
Compare
21a8893
to
fd855fa
Compare
Hi folks!
Currently, when forwarding naively back and forth headers from the gateway to the subgraphs, if we allow the request ID in both ways, we will end with 2 concatened request IDs:
This happens because:
useRequestId
set the request ID back ononResponse
(link)usePropagateHeaders
, that runs after, append it to because it's forwarded (link)It can be avoided by separating the logic between
forwardRequestHeaders
andforwardResponseHeaders
:But I think we should add a basic check and don't
append
an identical value if it already has been set.