`NIOHTTPServer` does not enforce response body framing against `Content-Length`
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 68/100
Línea de trabajo
Start at the NIOHTTPServer.ResponseSender.Writer entry points write(buffer:) and finish(trailer:), using the ShortBodyHandler reproduction with Content-Length set to 2. Check the existing Vapor tests mentioned in the issue and verify that writing too many bytes or finishing too early raises an error and aborts the response instead of completing it.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
This was picked up by some tests in Vapor. ResponseSender.Writer accepts any number of body bytes regardless of the Content-Length the handler declared on the response. finish(buffer:finalElement:) just completes the response without checking, resulting in the potential for under-writing and over-writing with no errors raised in the handler. Under-writing is annoying, over-writing is problem with keep-alive connections as it was treat the additional data as the start of the next response.
Repro
struct ShortBodyHandler: HTTPServerRequestHandler {
typealias RequestContext = NIOHTTPServer.RequestContext
typealias Reader = NIOHTTPServer.Reader
typealias ResponseSender = NIOHTTPServer.ResponseSender
static let payload = "a" // or "abcdefgh"
func handle(
request: HTTPRequest,
requestContext: consuming NIOHTTPServer.RequestContext,
reader: consuming sending NIOHTTPServer.Reader,
responseSender: consuming sending NIOHTTPServer.ResponseSender
) async throws {
var fields = HTTPFields()
// Limit the content length to 2 which we'd expect to cause issues with over or under writing.
fields[.contentLength] = "2"
var writer = try await responseSender.send(HTTPResponse(status: .ok, headerFields: fields))
var body = UniqueArray<UInt8>()
body.append(copying: Array(Self.payload.utf8)[...])
try await writer.write(buffer: &body)
try await writer.finish(trailer: nil) // ...and declare the body complete
}
}
Actual
Both responses return successfully with no error:
payload = "a" -> "HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\na"
payload = "abcdefgh" -> "HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nabcdefgh"
In the over-write case six bytes follow the declared body.
Expected
write(buffer:) should fail once the accumulated body would exceed the declared Content-Length and finish(buffer:finalElement:) should fail if fewer bytes were written than expected, aborting the response rather than completing it
Impact
In Vapor (where Content-Length is set but the caller on streaming response bodies) an under-writing handler produced a response that AsyncHTTPClient timed out on:
threw after 30.008566208 seconds: stream ended at an unexpected time
This is correct but should error way quicker. I added a guard in Vapor so this fails pretty instantly but it feels like this should be the server's responsibility rather than every implementation having to implement it. There's no workaround for the over-write case
- Lenguaje dominante
- Swift
- Estrellas
- 53
- Forks
- 16
- Merge medio
- 3 d 14 h
- PR fusionados (30 d)
- 11
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de swift-server/swift-http-server
-
Expose the negotiated HTTP version to request handlersPosiblemente ocupada @dioKaratzas la tomó hace 47 días. Abiertogood first issue kind/enhancement size/S
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
swift-server/swift-http-server#113 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
swift-server/swift-http-server#137 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
swift-server/swift-http-server#131 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Offer ResponseSender.Writer RawSpan APIsPosiblemente ocupada @0xTim la tomó hace 49 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
swift-server/swift-http-server#123 ·
Los mantenedores suelen responder en 1 día
-
Support Request DecompressionAbiertokind/feature
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
swift-server/swift-http-server#122 ·
Los mantenedores suelen responder en 1 día
Todos los issues de swift-server/swift-http-server
Issues similares
-
swift.md: `Date(myString, strategy: .iso8601)` example omits `try` — the initializer is throwingAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
-
core: RAC_LLM_OPTIONS_DEFAULT.min_p disagrees with the IDL's annotated defaultPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertobug core p3
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
RunanywhereAI/runanywhere-sdks#1083 ·
Los mantenedores suelen responder en 5 días
-
bug/fix needs: triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
capawesome-team/capacitor-firebase#1054 ·
Los mantenedores suelen responder en 1 día
-
area: docs eco: swift good first issue help wanted lane: free-agent roadmap size: XS type: docs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 62/100
arminazimi/evergreen#441 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día