fix(engine): add default ReadHeaderTimeout to http.Server in Run methods - #4800
Open
RubenPari wants to merge 1 commit into
Open
fix(engine): add default ReadHeaderTimeout to http.Server in Run methods#4800RubenPari wants to merge 1 commit into
RubenPari wants to merge 1 commit into
Conversation
Engine.Run, RunTLS, and RunListener created an http.Server without ReadHeaderTimeout, leaving applications exposed to slowloris-style resource exhaustion. A new Engine.ReadHeaderTimeout field (default 10s) is now applied to the http.Server created by these methods. Users can customize the value or use a custom http.Server for full control. Fixes gin-gonic#4760
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4800 +/- ##
==========================================
- Coverage 99.21% 98.33% -0.89%
==========================================
Files 42 48 +6
Lines 3182 3180 -2
==========================================
- Hits 3157 3127 -30
- Misses 17 43 +26
- Partials 8 10 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
4 tasks
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.
Summary
Engine.Run,RunTLS, andRunListenercreated anhttp.ServerwithoutReadHeaderTimeout, leaving applications that use the defaultRunhelper exposed to slowloris-style resource exhaustion.Changes
Engine.ReadHeaderTimeoutfield (time.Duration), defaulting to 10 seconds.http.Servercreated byRun,RunTLS, andRunListenernow setsReadHeaderTimeoutfrom this field.ReadHeaderTimeoutis zero or negative, the 10-second default is used as a fallback.Rundoc comment to document the timeout behavior and recommend a customhttp.Serverfor full control.Why
ReadHeaderTimeout?ReadHeaderTimeoutis the most important timeout for slowloris mitigation — it limits how long the server will wait for the client to send the complete request headers. UnlikeReadTimeoutorWriteTimeout, it does not interfere with legitimate slow responses or large uploads.Compatibility
engine.ReadHeaderTimeoutbefore callingRun.http.Serverand useengine.ServeHTTPdirectly.Test plan
TestReadHeaderTimeoutDefault— verifiesNew()sets the 10s defaultTestReadHeaderTimeoutCustom— verifies a custom value is respectedTestReadHeaderTimeoutZeroFallsBackToDefault— verifies zero falls back to the defaultgo test .— all existing tests passFixes #4760