#23447: Gateway: harden hook ingress content-type validation
gateway
size: S
trusted-contributor
Cluster:
Gateway and Hooks Enhancements
## Summary
- enforce hook request content-type allowlist (`application/json` by default)
- add `hooks.allowedContentTypes` config + schema validation
- reject unsupported/missing content type with HTTP 415 before body parsing
- preserve bounded hook body handling and ensure oversize payloads reliably return 413
## Why
This hardens hook ingress against content-type parsing edge cases and request-shape abuse while keeping existing body-size protection in place.
## Testing
- `pnpm check`
- `pnpm test src/gateway/hooks.test.ts`
- `pnpm test src/gateway/server-http.hooks-request-timeout.test.ts`
- `pnpm test src/infra/http-body.test.ts`
- `pnpm test:e2e src/gateway/server.hooks.e2e.test.ts`
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR adds content-type validation to the webhook/hooks ingress endpoint. The implementation enforces an allowlist of accepted content-types (defaulting to `application/json`) and rejects unsupported types with HTTP 415 before parsing the request body. The validation is configurable via `hooks.allowedContentTypes` and properly normalizes content-type headers by stripping charset parameters and converting to lowercase. The PR also includes a minor cleanup to `http-body.ts` removing redundant request destruction code when content-length exceeds the limit.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The changes are well-tested with comprehensive unit and e2e test coverage, the implementation follows existing patterns in the codebase, and the feature provides a clear security hardening benefit by validating content-type before body parsing. The normalization logic is sound and handles edge cases appropriately.
- No files require special attention
<sub>Last reviewed commit: 726f5ed</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#23765: Gateway hooks: enforce JSON content type and strict payload keys
by bmendonca3 · 2026-02-22
91.4%
#23355: Gateway: fail closed on untrusted proxy headers
by bmendonca3 · 2026-02-22
76.1%
#8121: fix(gateway): remove query parameter token support for hooks
by yubrew · 2026-02-03
75.9%
#9909: Gateway: add HITL approvals integration
by FletcherFrimpong · 2026-02-05
75.4%
#6405: feat(security): Add HTTP API security hooks for plugin scanning
by masterfung · 2026-02-01
75.2%
#23461: Gateway: add hook replay protection with timestamp and nonce
by bmendonca3 · 2026-02-22
74.9%
#9403: feat(hooks): Support application/x-www-form-urlencoded content-type...
by chipgpt · 2026-02-05
74.9%
#23410: Gateway: require prefixes for hook request session-key overrides
by bmendonca3 · 2026-02-22
74.8%
#10679: fix(hooks): invoke gateway_start and gateway_stop in lifecycle
by yassinebkr · 2026-02-06
74.3%
#13144: harden archive extraction, auth tokens, hook transforms, and queue ...
by qxlsz · 2026-02-10
74.2%