Repository navigation
fix(api): spend-gate section history with empty key segments; query-role TLS settings - #540
Conversation
Codex review round 1 (gpt-6.1-sol, max effort)VERDICT: REQUEST_CHANGES Major — Spend gating still classifies a different path from Starlette routing, at src/rememberstack/surfaces/http_api.py:2848. Two bypasses reproduce with a valid bearer token and a lease configured to refuse:
Simplest fix: Pass The empty-segment fix works. Checks across all 40 TLS plumbing is correct and default-preserving: settings reach the connection factory, certificate paths become strings, and unset values omit both kwargs, preserving libpq defaults. The updated docs are accurate. Validation: 76 focused tests passed. No files changed. Disposition (Claude): accepted, fixed in ba50eceThe spend-lease middleware now classifies |
Codex review round 2 (gpt-6.1-sol, max effort)VERDICT: REQUEST_CHANGES Major — Encoded final newline bypasses spend gating, at src/rememberstack/surfaces/http_api.py:2853.
Reproduced over real Uvicorn HTTP with a valid bearer token and a refusing lease:
Section history and SQL/saved-query execution also bypass the lease this way. This is a regression: the previous Simplest fix: Reject decoded LF in the path before classification and dispatch, returning 400. Add an end-to-end regression asserting The original empty-segment fix and both round-1 fixes work. Auditing all 40 route registrations found no other mismatch among the tested trailing/repeated/encoded slash, delimiter, method, and TLS plumbing is correct and default-preserving: profile settings reach the factory, CA paths become strings, and unset values omit both kwargs. Docs are accurate. Validation: 167 focused tests passed, plus both docs checks. No files changed. Disposition (Claude): accepted, fixed in 036e70fThe perimeter gate, which is always installed and the outermost layer apart from CORS, now answers |
Codex review round 3 (gpt-6.1-sol, max effort)VERDICT: APPROVE No blocker, major, or minor findings.
No files changed. |
…ole TLS - A section key is a path parameter, so /documents/x/sections/a//b/history routes, but _spend_gated_route refused any path with an empty segment before matching it, so that read skipped the spend lease. The section-history match now runs first; every other route's parameters are single non-empty segments, so such paths 404 and spend nothing. - SelfHostSettings.query_role_sslmode / query_role_sslrootcert reach libpq for the customer-SQL connection; unset keeps libpq's defaults. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
…imiters) Codex round 1: under a mount (root_path) and with an encoded ? or # inside a parameter, request.url.path differs from the path Starlette routes, so reads skipped the lease. The gate now classifies get_route_path(scope). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
Codex round 2: a decoded final newline matches a route pattern's $, so /documents%0A read the inventory while the spend classification saw a different path. The perimeter gate answers 400 for any ASCII control character in the decoded path, before resolution, auth or routing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
036e70f to
d5a202e
Compare
Two small engine fixes found while building the UMC shared API.
1. Spend-gating bypass.
GET /documents/{doc_id}/sections/{section_key:path}/historytakes the section key as a path parameter, so.../sections/a//b/historyroutes. I verified this: it returns 200 with keya//b. However,_spend_gated_routereturnedNonefor any path with an empty segment before matching it, so this memory read skipped the D46 spend lease. The section-history match now runs before the empty-segment refusal. Every other route's parameters are single non-empty segments (Starlette's default converter is[^/]+), so a path with an empty segment matches none of them, gets a 404 and spends nothing; that refusal stays. Tests: three empty-segment section-history paths are now gated (test_memory_reads_are_spend_gated).2. TLS for the customer-SQL connection. New settings
SelfHostSettings.query_role_sslmode(libpq modesdisable…verify-full) andquery_role_sslrootcert(path), set via envREMEMBERSTACK_SELFHOST_QUERY_ROLE_SSLMODE/_SSLROOTCERT. Both are passed to the query-rolepsycopg.connectonly when set; unset keeps libpq's defaults. They are documented on the configuration reference page and in D147 item 5. Tests check that the values reach the connection and that unset values add nothing.Checks: ruff, pyright (0), the unit lane (3106 passed) and the docs checks.
🤖 Generated with Claude Code
https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm