Details
3. Observed output (go run .):
ValidateRequest returned: *openapi3filter.RequestError
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x20 pc=0x...]
goroutine 1 [running]:
github.com/getkin/kin-openapi/openapi3filter.convertParseError(...)
.../openapi3filter/validation_error_encoder.go:120 +0x17c
github.com/getkin/kin-openapi/openapi3filter.ConvertErrors(...)
.../openapi3filter/validation_error_encoder.go:42 +0xec
main.main()
...
exit status 2
The panic is at exactly validation_error_encoder.go:120 — the unguarded e.Parameter.In dereference.
Control (confirms JSON is not a vector): repeating the setup with an application/json body and either a malformed body ({"age": ) or a wrong-type body ({"age": "notanumber"}) returns from ConvertErrors normally, with no panic. Only the multipart/form-data path crashes.
In a real HTTP server, ConvertErrors / ValidationErrorEncoder.Encode runs inside the request handler, so the panic aborts the in-flight request (connection reset / 500) and, without a recover() in the middleware chain, is trivially repeatable.
Impact
- Type: Nil-pointer dereference → unauthenticated remote denial of service.
- Who is impacted: any application using
github.com/getkin/kin-openapi/openapi3filterthat (1) exposes an endpoint accepting amultipart/form-datarequest body with at least one non-string scalar property (integer/number/boolean), and (2) renders validation errors through the library's ownValidationErrorEncoderorConvertErrorshelpers. These are the library's advertised error-rendering helpers, so this is a realistic default integration. - Attack: a single crafted, unauthenticated request (a multipart part whose value doesn't parse to the declared scalar type). No credentials, special privileges, or unusual client capabilities are required, and it is repeatable at will.
- Consequence: the handling goroutine panics. Absent a
recover()boundary in the application's middleware, the request is aborted; sustained requests deny service. Confidentiality and integrity are not affected. - Not affected: applications that only accept
application/jsonbodies (verified above), applications that do not useConvertErrors/ValidationErrorEncoderto format errors, or applications that wrap handlers in arecover()(which converts the crash into a handled 500 but still prevents normal error rendering).