fix infinite loop parsing the Forwarded header#13229
Draft
arshsmith1 wants to merge 1 commit into
Draft
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #13229 +/- ##
==========================================
- Coverage 98.98% 98.98% -0.01%
==========================================
Files 131 131
Lines 48993 48999 +6
Branches 2550 2551 +1
==========================================
+ Hits 48496 48500 +4
- Misses 373 374 +1
- Partials 124 125 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Merging this PR will not alter performance
Comparing Footnotes
|
arshsmith1
force-pushed
the
forwarded-parse-infinite-loop
branch
from
July 23, 2026 08:50
8b5fd88 to
7cbe0aa
Compare
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.
What do these changes do?
BaseRequest.forwardedwalks eachForwardedheader with a hand-written cursor loop. When a segment neither matches_FORWARDED_PAIR_REnor has a following;,field_value.find(";", pos)returns-1, so the empty-value branch setspos = -1 + 1 = 0and the cursor jumps back to the start. The loop then never makes progress and spins at 100% CPU on the event loop thread. A single header such asForwarded: a(alsofor=1.2.3.4; a,for=_; x,; a) is enough to hang the worker permanently. Readingrequest.forwardedis common in reverse-proxy setups, so any middleware or handler that touches it exposes this.The loop now breaks when there is no further
;to consume, since a trailing empty-or-malformed value ends the field-value either way. That also drops the off-by-one where the old[pos : field_value.find(";", pos)]slice quietly cut the last character when no;was present.Are there changes in behavior for the user?
No API change. Well-formed and previously-terminating headers parse exactly as before; the only difference is that the pathological inputs now terminate and return the valid prefix instead of hanging.
Is it a substantial burden for the maintainers to support this?
No. It touches the one parse loop and adds a parametrized regression test next to the existing
Forwardedtests.Related issue number
None.
Checklist
CONTRIBUTORS.txtCHANGES/folder