-
Notifications
You must be signed in to change notification settings - Fork 523
Ignore everything but path and query in requests for absolute URIs (#666). #711
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -804,8 +804,43 @@ protected bool TakeStartLine(SocketInput input) | |
QueryString = queryString; | ||
HttpVersion = httpVersion; | ||
|
||
bool caseMatches; | ||
if (requestUrlPath.Length > 0 && requestUrlPath[0] != '/') | ||
{ | ||
int hostIndex; | ||
if (requestUrlPath.StartsWith("http://")) | ||
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. I'd be interested in the allocation profile on this. Just curious if we could just operate on the bytes before materializing to a string or all the operations here non-allocating? 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. I'm guessing the normal path is a relative URI this path might not even showup. Is that correct? In reply to: 57374946 [](ancestors = 57374946) 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. It's what I'm expecting. 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. Specify the StringComparison to avoid a CurrentCulture comparision. Is requestUrlPath expected to be lower case? 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. ordinal ignore case. |
||
{ | ||
hostIndex = 7; | ||
} | ||
else if (requestUrlPath.StartsWith("https://")) | ||
{ | ||
hostIndex = 8; | ||
} | ||
else | ||
{ | ||
ReportCorruptedHttpRequest(new BadHttpRequestException($"Invalid request path: {requestUrlPath}")); | ||
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. officially it's the request target, not path. 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. |
||
return true; | ||
} | ||
|
||
int pathIndex = requestUrlPath.IndexOf('/', hostIndex); | ||
if (pathIndex == -1) | ||
{ | ||
int queryIndex = requestUrlPath.IndexOf('?', hostIndex); | ||
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. Isn't the query string already removed from 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. Totally overlooked that. 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. Hmm, looking at the code that brings up an interesting point. pathBegin and pathEnd are now the wrong name, it should be urlBegin or targetBegin. Similar for requestUrlPath. 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. Yeah, I'm renaming those. |
||
if (queryIndex == -1) | ||
{ | ||
requestUrlPath = "/"; | ||
} | ||
else | ||
{ | ||
requestUrlPath = "/" + requestUrlPath.Substring(queryIndex); | ||
} | ||
} | ||
else | ||
{ | ||
requestUrlPath = requestUrlPath.Substring(pathIndex); | ||
} | ||
} | ||
|
||
bool caseMatches; | ||
if (!string.IsNullOrEmpty(_pathBase) && | ||
(requestUrlPath.Length == _pathBase.Length || (requestUrlPath.Length > _pathBase.Length && requestUrlPath[_pathBase.Length] == '/')) && | ||
RequestUrlStartsWithPathBase(requestUrlPath, out caseMatches)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,12 @@ public override async Task RequestProcessingAsync() | |
|
||
InitializeHeaders(); | ||
|
||
if (_corruptedRequest) | ||
{ | ||
await ProduceEnd(); | ||
return; | ||
} | ||
|
||
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. This seems different than what we do for corrupted request headers. I would like to determine the correct behavior and consolidate this logic. |
||
while (!_requestProcessingStopping && !TakeMessageHeaders(SocketInput, FrameRequestHeaders)) | ||
{ | ||
if (SocketInput.RemoteIntakeFin) | ||
|
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.
Again, this is an edge case and I don't see the need to optimize this path.
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.
what happens for requestUrlPath.Lenght == 0? That shouldn't be valid either.
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.
Add a comment and RFC link for the scenario you're handling, and the fact that you're ignoring the scheme and host at the moment.