Skip to content

fix: web-response audit on HTTP/1, MariaDB executable comments, and three console/CLI fixes - #339

Merged
jfcmartins merged 5 commits into
mainfrom
claude/focused-thompson-6j6ly0
Nov 16, 2026
Merged

jfcmartins merged 5 commits into
mainfrom
claude/focused-thompson-6j6ly0

Conversation

@jfcmartins

Copy link
Copy Markdown
Collaborator

What and why

Five independent fixes from a scheduled repository review, one commit each. None overlaps the open PRs (#300 OIDC groups claim, #276 release).

  1. fix(proxy): the end-of-response audit didn't fail closed on HTTP/1 (crates/limen-proxy/src/web.rs, AuditResponseBody).
    • Cause: once hyper's HTTP/1 server has fully written a Content-Length body, it drops the body without polling for Ready(None) (hyper 1.12 proto/h1/dispatch.rs: once can_write_body() is false it sets clear_body and drops it). The "complete" audit only started on Ready(None).
    • Effect: every such HTTP/1 response was audited from Drop as client_disconnected, in a detached task. A failed emit there could not close the connection, which breaks ADR-0022 and the rule that audit fails closed.
    • Fix: the upstream's last frame is held back until the event is written. If the write fails, the frame is withheld and the response errors.
    • Empty bodies (HEAD, 204, 304, Content-Length: 0) may never be polled at all, so they are audited before the head goes out and answered 503 audit is unavailable if that fails.
    • HTTP/2 was already correct and keeps working: the end-of-stream flag now goes with the last frame.
  2. fix(worker): MariaDB /*M! … */ executable comments are now read as SQL (crates/limen-worker/src/db/sqltext.rs).
    • Cause: sqlparser expands only /*! … */, so /*M!USE other*/ and /*M!KILL 42*/ were classified as empty.
    • Effect: they got past the one-database USE guard and the KILL-ownership guard in mysql.rs. With normalize_literals on, the audit showed them as /* ? */.
    • Fix: for MySQL targets, the comment's content is tokenized as code, in both split and normalize.
    • On MySQL proper this text is only a comment, so the stricter reading can only refuse more, never less.
    • MariaDB's dump sandbox line /*M!999999\- enable the sandbox mode */ classifies as other and is still forwarded (checked locally).
  3. fix(console): a date filter of 9999-12-31 no longer panics (console/query.rs, parse_when).
    • Cause: an upper bound given as a bare date adds one day with +, which panics past the last representable date.
    • Trigger: GET /console/sessions?to=9999-12-31, open to any signed-in user.
    • Fix: checked_add, so the value is reported as ignored like any other bad date.
  4. fix(console): an unknown access or review decision is now refused (console/workflows.rs).
    • Cause: any value other than approve was read as a deny, and anything other than certify as a flag. A flag withholds the role and ends the subject's sessions, and neither a deny nor a flag can be undone.
    • Fix: only the two values each form sends are accepted. Anything else redirects back with an error, as change_decide already does.
  5. fix(cli): known_hosts is now written atomically (commands/ssh.rs).
    • Cause: it was the one profile file written with std::fs::write.
    • Effect: an interrupted write left a truncated host-CA trust file, and the file's mode depended on the umask.
    • Fix: it now goes through profile::write_file.

Related: ADR-0022 (web-app audit), ADR-0033 §5 (statement text), design §13 phases 6, 12 and 13. No new behavior beyond these fixes.

How it was verified

  • cargo fmt --all and cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.
  • cargo test --lib on limen-worker (367), limen-proxy (51) and limen-control-plane (208), plus cargo test -p limen-cli --bins (126): all pass.
  • New tests:
    • web::tests::response_audit: serves a real hyper HTTP/1 upstream with Content-Length back out through hyper's HTTP/1 server. It asserts that the reason is complete and that a failing sink withholds the end of the response. With the hold-back logic disabled, both tests fail, so they reproduce the bug.
    • sqltext::tests::mariadb_executable_comments_are_classified_as_code, plus cases added to the comment-normalization test.
    • query::tests::the_last_representable_day_does_not_panic.
    • workflows::tests::only_the_two_known_decisions_are_read.
  • protoc came from Ubuntu's protobuf-compiler (3.21), not the 36.2 pinned in mise.toml, because mise isn't available in this environment. The build succeeded with it.

Not verified

  • Demos and integration tests: the Docker daemon wasn't running, so demos/demo-phase12.sh, demos/demo-phase6.sh, the limen-e2e suites and the DB-backed control-plane tests were not run. CI covers them once the PR is marked ready.
  • Real servers: the MariaDB behavior is not checked against a real server (unverified). It rests on MariaDB's documented /*M! syntax.
  • Browsers: HTTP/1 and HTTP/2 browser traffic through the proxy is not tested end to end.
  • Scans: gitleaks isn't installed here; I grepped the diff by hand.
  • cargo deny and cargo audit were not run; no dependencies changed.

Review guide

Look hardest at the AuditResponseBody change: the held frame, the empty-body path in handle, and its effect on HTTP/2. An empty response now waits for one audit write before its head is sent. HTTP/2 already waited for that write before ending the stream.

Remaining concerns (found, deliberately not fixed)

  • High, needs a design decision. A client can change how the server parses strings, so the worker splits statements differently from the server.
    • MySQL: after SET SESSION sql_mode='NO_BACKSLASH_ESCAPES', the server runs SELECT 'a\'; KILL 99; -- ' as two statements, while sqlparser sees one select. That bypasses the KILL and USE guards, and the normalized audit hides the second statement.
    • PostgreSQL: SET standard_conforming_strings = off has the same effect on the audit only.
    • Fixing it means refusing or pinning those settings, or tracking the server's status flags. That needs a decision on client compatibility.
  • Medium, needs verification. Anonymous browser HTTP/2 connections are dropped without a GOAWAY when ANONYMOUS_API_MAX_AGE (120 s, limen-proxy/src/lib.rs) runs out. Web-app downloads and streams in flight would be cut off.
  • Medium, needs verification in a browser. Each unauthenticated request to a web app mints a new sign-in nonce cookie (web.rs login_redirect). A polling app can then overwrite the nonce of a sign-in already in progress.
  • Medium. A database error after a SCIM group change silently skips ending the affected logins (scim.rs enforce and idp_check::end_logins_of use unwrap_or_default()).
  • Low:
    • reviews::active_denies drops rows that fail to decode, which fails open.
    • access::expire can write the same audit events twice when a later item fails.
    • The raw manifests deploy/kubernetes/limen/{proxy,worker}.yaml lack the pod securityContext (non-root, fsGroup, seccomp) that the control plane and the Helm chart set.
    • scripts/policy-pr-comment.sh matches the marker comment of any author.
    • scripts/ci-db-targets.sh uses a fixed temp path when RUNNER_TEMP is unset.
    • docs/design.md §11 still calls modules/ecs, modules/ec2 and examples/complete "not yet in the repo".
    • limen-audit's JsonlFileSink is used only in tests, and the crate doc around it is stale.

Checklist

  • Tests added or updated; cargo fmt and cargo clippy ... -D warnings clean
  • Docs updated: n/a (no user-facing behavior change)
  • Phase work: n/a (fixes only; the demos weren't run, see above)
  • Secrets stay out of logs; mTLS and fail-closed audit intact (fix 1 restores fail-closed audit on HTTP/1)
  • New dependency: n/a
  • New entry point or data store: n/a
  • Commits are conventional, small and focused

Compatibility and rollback

  • MariaDB statements wrapped in /*M! USE … */ or /*M! KILL … */ are now refused, as the unwrapped forms already were.
  • A console form posting a decision other than its two values now gets an error instead of a deny or flag.
  • To roll back, revert the individual commit.

Generated by Claude Code

@jfcmartins
jfcmartins marked this pull request as ready for review November 16, 2026 10:09
… frame

hyper's HTTP/1 server drops a body with a known length as soon as it is
written in full, without polling for its end. The outcome audit only started
on Ready(None), so on HTTP/1 every Content-Length response was audited from
Drop as "client_disconnected", in a detached task whose failure could not
close the connection (ADR-0022: audit fails closed). Hold back the upstream's
last frame until the "complete" event is written; an empty body, which may
never be polled at all, is audited before the head goes out and answered 503
if that fails. The tests serve a real HTTP/1 upstream and fail without the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEiXYYXVETRewQNUQF7xTn
MariaDB runs the content of /*M! ... */ (and /*M!100100 ... */), but sqlparser
expands only /*! ... */, so a statement inside one was classified as
"empty". USE and KILL inside it got past the one-database and KILL-ownership
guards, and normalize_literals audited it as /* ? */. Tokenize the content as
code for MySQL targets, in both split and normalize. On MySQL proper it is a
comment, so the stricter reading only refuses more.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEiXYYXVETRewQNUQF7xTn
An upper bound that is a bare date adds one day, which is out of range for the
last representable date and panicked the handler (GET
/console/sessions?to=9999-12-31, open to any signed-in user). Use checked_add;
the value is then reported as ignored like any other bad date.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEiXYYXVETRewQNUQF7xTn
Anything other than "approve" was read as a deny, and anything other than
"certify" as a flag, which withholds the role and ends the subject's
sessions. Both are irreversible. Accept only the two values each form sends
and refuse the rest, as the policy-change handler already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEiXYYXVETRewQNUQF7xTn
It was the one profile file written with std::fs::write: an interrupted write
left a truncated host-CA trust file, and its mode followed the umask.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEiXYYXVETRewQNUQF7xTn
@jfcmartins
jfcmartins force-pushed the claude/focused-thompson-6j6ly0 branch from 98d41bf to e10fd6a Compare November 16, 2026 16:33
@jfcmartins
jfcmartins merged commit daa7f20 into main Nov 16, 2026
14 checks passed
@jfcmartins
jfcmartins deleted the claude/focused-thompson-6j6ly0 branch November 16, 2026 16:51
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.

2 participants