Skip to content

Harden POST response filter against undecodable results - #7211

Open
rkb32 wants to merge 7 commits into
stacklok:mainfrom
rkb32:pr-a-post-only
Open

rkb32 wants to merge 7 commits into
stacklok:mainfrom
rkb32:pr-a-post-only

Conversation

@rkb32

@rkb32 rkb32 commented Nov 21, 2026 •

Copy link
Copy Markdown

Summary
Why: A POST response with a result nested past encoding/json's depth cap was sent to the client unfiltered. A result split across lone CR line breaks could also get past the filter, because a spec client reads those breaks differently.

What: Such bodies are now answered with a JSON-RPC error that carries the request id, as the GET stream does. Events with a lone CR that could carry a result fail closed. The no-shape decision is shared between the POST path and the GET stream.

Type of change
Bug fix
Does this introduce a user-facing change?
Before: a POST response carrying a result past the depth cap passed through unfiltered.
After: it is answered with a JSON-RPC error that carries the request id.
Before: an event with a lone CR could hide a list from the filter.
After: that event is answered with an error.
Test plan
go test -race ./pkg/authz/ ./pkg/transport/proxy/httpsse/ passes locally
Full task test on CI (pending; the laptop cannot run it)

A POST body that carries a result past encoding/json's depth cap was
written unfiltered. Reject it instead, answering with the request id,
as the GET stream does. Also filter a result split across lone CR line
breaks, and share the no-shape decision between the POST path and the
GET stream so the two cannot drift apart.
@rkb32
rkb32 requested a review from ChrisJBurns as a code owner November 21, 2026 18:59
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T19:03:15.208092Z 34ec327 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@rkb32 rkb32 changed the title Pr a post only Harden POST response filter against undecodable results Nov 21, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 34ec327bd7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkg/authz/response_filter.go Outdated
if id == (jsonrpc2.ID{}) {
id = topLevelID(rawResponse)
}
return rfw.writeErrorResponse(id,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reset upstream headers before writing this error

When a filtered POST has an unrecognized media type and an undecodable body naming result, this call writes a replacement JSON-RPC error without clearing the backend’s Content-Length or changing its Content-Type. With a real reverse-proxied response, the stale length can truncate the shorter 500 body, and a type such as text/plain leaves the JSON-RPC error mislabeled. Clear the stale entity headers and set Content-Type: application/json before writing the replacement.

Useful? React with 👍 / 👎.

Comment thread pkg/authz/response_filter.go Outdated
case noShapeFilterSSE:
rfw.ResponseWriter.Header().Del("Content-Length")
return rfw.processSSEResponse(rawResponse)
case noShapeReject:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Document the changed malformed-response behavior

For a filtered request with an unrecognized media type, an undecodable body naming result now returns an HTTP 500 JSON-RPC error instead of passing the body through. docs/authz.md does not describe this client-visible behavior; please document the before-and-after behavior in the subsystem page.

AGENTS.md reference: AGENTS.md:L91-L91

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant