Skip to content

Commit c8f89f5

Browse files
cyberpapiiiclaude
andcommitted
fix: read Host header from request.head.authority instead of HTTPFields
swift-http-types strips the Host header from the HTTPFields collection and stores it in HTTPRequest.authority for HTTP/1.1 Host and HTTP/2 :authority compatibility. This caused all requests to fail with "Host not allowed" since request.uri.host is nil for standard HTTP requests where the URI is just "/". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f146938 commit c8f89f5

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

swift/Sources/iMessageMax/Server/OriginValidationMiddleware.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ struct OriginValidationMiddleware<Context: RequestContext>: RouterMiddleware {
5555

5656
// Also validate Host header to prevent DNS rebinding
5757
// Host validation is mandatory — reject if we cannot determine the host
58-
guard let authority = request.uri.host else {
58+
// Note: swift-http-types strips the Host header from HTTPFields and stores it
59+
// in HTTPRequest.authority (for HTTP/1.1 Host and HTTP/2 :authority compatibility)
60+
guard let authority = request.head.authority ?? request.uri.host else {
5961
return Response(
6062
status: .forbidden,
6163
headers: [.contentType: "application/json"],

0 commit comments

Comments
 (0)