mirror of
https://github.com/versity/versitygw.git
synced 2026-01-03 18:44:04 +00:00
fix: implements proper error handling for malformed http requests
Fixes #1364 When a completely malformed request is sent to the gateway, Fiber/Fasthttp fails to parse the request, and the code execution never reaches the routers or handlers. Instead, the error is caught by the global error handler. These kinds of errors (malformed requests that fail during request parsing) are prefixed with **"error when reading request headers"** in Fiber. The implementation adds a check in the global error handler for this specific error message and returns an S3-like XML **BadRequest** error instead.
This commit is contained in:
@@ -199,6 +199,13 @@ func globalErrorHandler(ctx *fiber.Ctx, er error) error {
|
||||
ctx.Status(http.StatusBadRequest)
|
||||
return nil
|
||||
}
|
||||
if strings.Contains(fiberErr.Message, "error when reading request headers") {
|
||||
// This error means fiber failed to parse the incoming request
|
||||
// which is a malfoedmed one. Return a BadRequest in this case
|
||||
err := s3err.GetAPIError(s3err.ErrCannotParseHTTPRequest)
|
||||
ctx.Status(err.HTTPStatusCode)
|
||||
return ctx.Send(s3err.GetAPIErrorResponse(err, "", "", ""))
|
||||
}
|
||||
}
|
||||
|
||||
// additionally log the internal error
|
||||
|
||||
Reference in New Issue
Block a user