Skip to content

#803: redact the Content-Type before BadResponse cuts it - #805

Open
ephico2real2 wants to merge 1 commit into
mainfrom
fix/803-redact-content-type
Open

ephico2real2 wants to merge 1 commit into
mainfrom
fix/803-redact-content-type

Conversation

@ephico2real2

Copy link
Copy Markdown
Owner

Closes #803
Part of #26

Written by Opus 5.5 at high (all commits). Small security fix: reviewer 1 only, per CLAUDE.md.

What was wrong

KubeClient._object (cmapi/src/cmapi/core/clients/kube.py, old line 221) put the server's Content-Type, cut to 60 characters, into BadResponse without the client's redaction, against docs/02 "Client rules" (redact the whole text, then cut). The comment in ThanosQuerier._base_url said KubeClient redacts each of these errors.

Why a header value is redacted

RFC 9110 (fetched 2026-12-01, https://www.rfc-editor.org/rfc/rfc9110.txt): §8.3 "The "Content-Type" header field indicates the media type of the associated representation ... Content-Type = media-type"; §8.3.1 "media-type = type "/" subtype parameters"; §5.6.6 "parameter-value = ( token / quoted-string )". A quoted-string holds any visible text (§5.6.4 qdtext), so a proxy that echoes the Authorization header can put the token in it. It is the server's text in an error message, so the same rule holds as for a body.

Fix (improves reviewer 2's L1 proposal on #795)

  • New module function json_object(r, path, redact); redact is required, and None names no text of the server's (the old sensitive=True). The whole Content-Type is redacted, then cut to 60.
  • KubeClient._object is now an instance method that passes self.redact (None when sensitive). Every KubeClient call site is redacted with no edit. Reviewer 2 proposed an identity default on the static method, which fails open for a call site that forgets it.
  • HubImportSource.list calls json_object(r, path, None), as before naming no server text.
  • thanos.py comment corrected. docs/21: 27 citations relocated by scripts/doc-citations.py --relocate; the two thanos.py ranges re-read and recorded with --write; --check 0 problems.

Tests (no cluster; real HTTP server on 127.0.0.1)

cmapi/tests/service/test_bad_response_redaction_803.py: Content-Type holding the token whole, split by the 60-character cut, and cut short by the server, across get, version, whoami, list, get_object, apply and access_review, for a JWT and a token with escaped characters. Before the fix: 6 failed, 2 passed (the two behaviour-preservation tests: an unredacted media type is named as before, and the reader TokenRequest still names no Content-Type). After: 8 passed.

Not tested: the full suite locally (CI gates it); any cluster.

KubeClient._object put the server's Content-Type, cut to 60 characters, into
BadResponse without the client's redaction, against docs/02 "Client rules"
(redact the whole text, then cut). RFC 9110 §5.6.6 lets a parameter-value be
any quoted string, so the field can carry an echoed credential.

The parse is now the module function json_object(r, path, redact), with redact
required: None names no text of the server's (the old sensitive=True). The
instance method _object passes self.redact, so every KubeClient call site is
redacted without an edit, and HubImportSource.list calls json_object(r, path,
None). The comment in ThanosQuerier._base_url now states the order.

Test: test_bad_response_redaction_803.py, a real server on 127.0.0.1 whose
Content-Type carries the token whole, split by the cut, and cut by the server.
docs/21 citations relocated (27 moved) and the two thanos.py ranges re-read.
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.

BadResponse carries the server's Content-Type cut to 60 characters, not redacted first (kube.py:221)

1 participant