Skip to content

Validation middleware consumes request body without restoring for downstream handlers #3864

@coderabbitai

Description

@coderabbitai

Problem

The OpenAPI validation middleware in go/pkg/zen/middleware_openapi_validation.go calls validator.Validate() which consumes the request body (r.Body) without buffering or restoring it. This leaves downstream handlers with an exhausted stream (EOF) when they attempt to read the request body.

Impact

  • Downstream handlers cannot access request body content
  • API endpoints that need to parse request bodies will fail after validation
  • Silent failures where handlers receive empty/EOF body streams

Context

This issue was identified during review of PR #3841 in comment: #3841 (comment)

The validation logic needs to be updated to:

  1. Buffer the request body before validation
  2. Restore the body for downstream handlers on both success and error paths
  3. Ensure proper cleanup and memory management

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions