Fix crash when Authorization header is missing for /v1/responses requests#29
Open
hsperker wants to merge 3 commits intohuggingface:mainfrom
Open
Fix crash when Authorization header is missing for /v1/responses requests#29hsperker wants to merge 3 commits intohuggingface:mainfrom
hsperker wants to merge 3 commits intohuggingface:mainfrom
Conversation
Wauplin
reviewed
Jan 28, 2026
Comment on lines
+74
to
+83
| // This service doesn't validate the token, but it cannot proceed without one. | ||
| // Fail early before we start streaming (once we write SSE bytes, we can't return a 401). | ||
| const apiKey = getBearerToken(req.headers.authorization); | ||
| if (!apiKey) { | ||
| res.status(401).json({ | ||
| success: false, | ||
| error: "Unauthorized", | ||
| }); | ||
| return; | ||
| } |
Collaborator
There was a problem hiding this comment.
I don't think we should raise a 401 not authorized if bearer token does not exist. responses.js is meant to be a lightweight proxy, meaning it does not handle authentication. One use case is to place the responses.js proxy in front of a local llama.cpp server. In this case, it doesn't make any sense to have authorizations at all.
I think the only thing that the PR should solve is that if the authorization header is not present, and the backend server needs one, then the proxy should not crash (which was the initial issue)
Does that make sense to you?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #28
This PR fixes a bug where
POST /v1/responsescould crash the server when theAuthorizationheader is missing—especially in streaming mode where response headers may already be sent.What changed
Accept: text/event-stream) and non-streaming requests return 401 whenAuthorizationis missing (instead of crashing).postCreateResponsebefore emitting any SSE bytes, preventingCannot set headers after they are sent to the client.Why
Once streaming starts, the server cannot safely change status/headers. Previously, missing auth could be handled too late (inside the streaming logic), leading to attempts to set headers after data was already
written and causing instability/crashes.
How to test
pnpm devpnpm test -- --grep "Authorization"(or run the specific missing-auth test file)Authorizationshould respond401(no SSE stream started)Authorizationshould respond401and the server should remain running