Skip to content

Commit 3d32154

Browse files
Deny requests with path navigation segments (#808)
1 parent 3bb5f17 commit 3d32154

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

Engine/Internal/Protocol/Parser/RequestSecurity.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ public static void Validate(Request request)
1414
{
1515
throw new ProtocolException("Multiple 'Host' headers specified");
1616
}
17+
18+
var target = request.Target.Path.Parts;
19+
20+
for (var i = 0; i < target.Count; i++)
21+
{
22+
if (target[i].Value == "." || target[i].Value == "..")
23+
{
24+
throw new ProtocolException("Segments '.' or '..' are now allowed in path");
25+
}
26+
}
1727
}
1828

1929
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace GenHTTP.Testing.Acceptance.Engine.Internal.Security;
2+
3+
[TestClass]
4+
public class PathSegmentTests : WireTest
5+
{
6+
7+
[TestMethod]
8+
public async Task TestUp()
9+
{
10+
var request = new []
11+
{
12+
"GET /../ HTTP/1.1",
13+
"Host: host"
14+
};
15+
16+
await TestAsync(request, "Segments '.' or '..' are now allowed in path");
17+
}
18+
19+
[TestMethod]
20+
public async Task TestEncoded()
21+
{
22+
var request = new []
23+
{
24+
"GET /%2E/ HTTP/1.1",
25+
"Host: host"
26+
};
27+
28+
await TestAsync(request, "Segments '.' or '..' are now allowed in path");
29+
}
30+
31+
}

0 commit comments

Comments
 (0)