fix(endpoint-auth): return after passing secret error to next() - #871
Merged
paulrobertlloyd merged 1 commit intoAug 15, 2026
Merged
Conversation
aciccarello
approved these changes
Aug 14, 2026
paulrobertlloyd
force-pushed
the
main
branch
2 times, most recently
from
August 15, 2026 15:39
ade3f7b to
2b7c903
Compare
hasSecret calls next(error) when SECRET is unset, then falls through and calls next() again. Express dispatches to the error handler on the first call and continues down the normal stack on the second, so the request is handled twice — rendering the error and then running the route, or failing with ERR_HTTP_HEADERS_SENT depending on which finishes first. Return the error call so the middleware stops there.
paulrobertlloyd
force-pushed
the
fix/secret-middleware-double-next
branch
from
August 15, 2026 15:52
3c0904a to
bac0f1f
Compare
Collaborator
|
Thanks @rmdes (and @aciccarello for the review) |
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.
Problem
hasSecretpasses an error tonext()whenSECRETis unset, but doesn'treturn, so execution falls through to the unconditional
next()on thefollowing line:
Express treats those as two separate dispatches: the first jumps to the
error-handling middleware, the second carries on through the normal stack.
Both run for the same request, so the misconfiguration is reported and the
route executes anyway — ending in a doubled response or
ERR_HTTP_HEADERS_SENT, depending on which finishes first.Fix
Return the error dispatch so the middleware stops there.
Notes
Only reachable when the server is started without
SECRET, so it doesn'taffect a correctly configured instance — but it turns a clear "secret not
set" message into a confusing double-handled request, which is exactly the
wrong experience for someone in the middle of setting Indiekit up.
Found while working on the
endpoint-authpackage for a separateredirect_urifix; kept as its own commit since the two are unrelated.