This repository was archived by the owner on Dec 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 521
[Wip] Don't process infinite request lengths #313
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,10 @@ public class KestrelServerInformation : IKestrelServerInformation, IServerAddres | |
|
||
public bool NoDelay { get; set; } | ||
|
||
public int MaxHeaderBytes { get; set; } = 16384; // 16kB | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something is out of sync with this PR. This property is read from config but the server never checks it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR is incomplete; just making sure I'm reading correctly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your config approach looks reasonable. |
||
|
||
public long MaxUploadBytes { get; set; } = 8388608; // 8MB | ||
|
||
public IConnectionFilter ConnectionFilter { get; set; } | ||
|
||
public void Initialize(IConfiguration configuration) | ||
|
@@ -26,6 +30,36 @@ public void Initialize(IConfiguration configuration) | |
{ | ||
Addresses.Add(url); | ||
} | ||
|
||
var maxHeaderBytes = configuration["request.maxHeaderBytes"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (!string.IsNullOrEmpty(maxHeaderBytes)) | ||
{ | ||
int value; | ||
if (!int.TryParse(maxHeaderBytes, out value)) | ||
{ | ||
throw new ArgumentException("maxHeaderBytes must be an integer 1024 or greater", "request.maxHeaderBytes"); | ||
} | ||
if (value < 1024) | ||
{ | ||
throw new ArgumentOutOfRangeException("request.maxHeaderBytes", maxHeaderBytes, "maxHeaderBytes must be 1024 or greater"); | ||
} | ||
MaxHeaderBytes = value; | ||
} | ||
|
||
var maxUploadBytes = configuration["request.maxUploadBytes"]; | ||
if (!string.IsNullOrEmpty(maxHeaderBytes)) | ||
{ | ||
long value; | ||
if (!long.TryParse(maxHeaderBytes, out value)) | ||
{ | ||
throw new ArgumentException("maxUploadBytes must be an integer 0 or greater", "request.maxUploadBytes"); | ||
} | ||
if (value < 0) | ||
{ | ||
throw new ArgumentOutOfRangeException("request.maxUploadBytes", maxUploadBytes, "maxUploadBytes must be a positive integer"); | ||
} | ||
MaxUploadBytes = value; | ||
} | ||
} | ||
} | ||
} |
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.
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 definition of this variable is missing?
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.
trying to work out how to get it there :-/
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.
Any suggestions? Always pass it to constructor is what I'm looking at currently... Hoping there is a better way.
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.
@halter73 ?
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.
We could put these limits directly on ServiceContext like we do for ConnectionFilter. It might be best to put the entire IKestrelServerInformation object in ServiceContext.
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.
I also think that the limits need to be passed as arguments to functions like Seek. Just in case it is ever used for something other than headers.
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.
return a
ResultType { int count, bool limitReached }
struct and add alimit
into each function and the caller can decide what to do? (e.g. throw BadRequest)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.
Sounds good. Another option might be to throw directly and let the caller wrap the exception.