Skip to content

Commit b7db82a

Browse files
authored
Merged PR 25295: Allow spaces between the url and http version (#43704)
# Allow spaces between the url and http version ## Description This is a change for app service to allow requests that have extra spaces between the url and http version. E.g. "GET(sp)/(sp)(sp)HTTP/1.1\r\n". The spec only allows one space, but some clients send more than one and IIS/Http.Sys allow it. ## Customer Impact The customer regressed when app service moved to Kestrel. The customer doesn't expect to be able to update/replace the affected clients for 3+ years. ## Regression? - [ ] Yes - [ ] No - [x] Umm... Not a regression in Kestrel, but a compat break for customers moving from IIS/Http.Sys. ## Risk - [ ] High - [ ] Medium - [x] Low Constrained, unit testable. ## Verification - [x] Manual (required) - [x] Automated ## Packaging changes reviewed? - [ ] Yes - [ ] No - [x] N/A
1 parent 6e7667d commit b7db82a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/Servers/Kestrel/Core/src/Internal/Http/HttpParser.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ private void ParseRequestLine(TRequestHandler handler, ReadOnlySpan<byte> reques
148148
// Consume space
149149
offset++;
150150

151+
while ((uint)offset < (uint)requestLine.Length
152+
&& requestLine[offset] == ByteSpace)
153+
{
154+
// It's invalid to have multiple spaces between the url resource and version
155+
// but some clients do it. Skip them.
156+
offset++;
157+
}
158+
151159
// Version + CR is 9 bytes which should take us to .Length
152160
// LF should have been dropped prior to method call
153161
if ((uint)offset + 9 != (uint)requestLine.Length || requestLine[offset + sizeof(ulong)] != ByteCR)

src/Servers/Kestrel/shared/test/HttpParsingData.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ public static IEnumerable<string[]> RequestLineValidData
7676
var httpVersions = new[]
7777
{
7878
"HTTP/1.0",
79-
"HTTP/1.1"
79+
"HTTP/1.1",
80+
" HTTP/1.1",
81+
" HTTP/1.1"
8082
};
8183

8284
return from method in methods
@@ -91,7 +93,7 @@ select new[]
9193
$"{path.Item1}",
9294
$"{path.Item2}",
9395
queryString,
94-
httpVersion
96+
httpVersion.Trim()
9597
};
9698
}
9799
}
@@ -164,6 +166,12 @@ public static IEnumerable<string> RequestLineInvalidData
164166
"GET / HTTP/1.1\n",
165167
"GET / HTTP/1.0\rA\n",
166168
"GET / HTTP/1.1\ra\n",
169+
"GET / HTTP/1.1\r\n",
170+
"GET / HTTP/1.1\r\n",
171+
"GET / HTTP/1.1\r\n",
172+
"GET / HTTP/1.1\r\n",
173+
"GET / HTTP/1.1 \r\n",
174+
"GET / HTTP/1.1 \r\n",
167175
"GET / H\r\n",
168176
"GET / HT\r\n",
169177
"GET / HTT\r\n",
@@ -195,6 +203,12 @@ public static IEnumerable<string> RequestLineInvalidData
195203
"CUSTOM / HTTP/1.1\n",
196204
"CUSTOM / HTTP/1.0\rA\n",
197205
"CUSTOM / HTTP/1.1\ra\n",
206+
"CUSTOM / HTTP/1.1\r\n",
207+
"CUSTOM / HTTP/1.1\r\n",
208+
"CUSTOM / HTTP/1.1\r\n",
209+
"CUSTOM / HTTP/1.1\r\n",
210+
"CUSTOM / HTTP/1.1 \r\n",
211+
"CUSTOM / HTTP/1.1 \r\n",
198212
"CUSTOM / H\r\n",
199213
"CUSTOM / HT\r\n",
200214
"CUSTOM / HTT\r\n",

0 commit comments

Comments
 (0)