Skip to content

security(lsp): bound transport framing, payloads, concurrency, and slow readers (#2034) - #2185

Merged
EffortlessSteven merged 2 commits into
mainfrom
codex/lsp-transport-bounds
Jul 22, 2026
Merged

EffortlessSteven merged 2 commits into
mainfrom
codex/lsp-transport-bounds

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

Implements #2034's transport/resource policy for ripr lsp --stdio. Investigation of vendored tower-lsp-server 0.23.0 established the real seams: the codec has no max-payload knob and none can be installed via public API, but Server::new(stdin, stdout, socket) is generic over AsyncRead/AsyncWrite — the sanctioned interception seam — and Server::concurrency_level is public.

Enforced bounds (chosen limits justified in docs/LSP_TRANSPORT_BOUNDS.md):

  • Framing: byte-transparent BoundedStdinReader — 8 KiB header block, 16 MiB declared message cap (largest legit ingress is didOpen/didSave full text; egress is already budget-capped, so ingress dominates). Trips before the codec waits for a declared body; tokio-util's fused-error semantics then emit one bounded -32700 and the process exits cleanly. Integer-overflow/negative/malformed headers fail deterministically.
  • Typed payloads (payload_bounds.rs, at handler entry before any state mutation): initialization_options ≤ 64 KiB; previousResultIds ≤ 4096 entries / 4096 B URI / 1024 B value (was O(n²) find + unbounded clone); executeCommand args ≤ 8 entries / 64 KiB. Rejection is a bounded -32602 with a static message — no attacker echo.
  • Concurrency: explicit 4 (the transport's own implicit default), keeping $/cancelRequest serviceable; internal queue 100 noted as residual.
  • Slow reader: 120 s write-stall deadline (any successful write resets) errors the write half and trips a shared flag that wakes the stdin adapter — the session terminates cleanly instead of wedging forever on an idle client.

Documented residuals (with reasons, in the doc): no wire-level frame recovery (transport fuses by design), internal queue constant not configurable without forking, no per-message write deadlines without forking, riprAgent bounds deferred until handlers exist, processId monitoring is #2030's scope.

Closes #2034

Adversarial coverage (real-binary, reusing the #1930 harness)

11 real-binary tests: oversized declared Content-Length with no body, oversized header block, integer-overflow and negative Content-Length, 5000-deep nesting, 5000 duplicate previousResultIds (then a legit set + hover succeeds), oversized result-id value, oversized executeCommand args, oversized initialization options, a 96-request coalesced burst (>header cap across one read), cancel under load, EOF during overload. Two in-process end-to-end tests over the real serve_streams composition pin the one-bounded-error-then-clean-stop and stopped-reader behavior.

A self-found bug is fixed with regressions: the first observe() desynced on coalesced frames (burst_of_small_frames_in_one_read_passes, body_bytes_that_look_like_headers_do_not_desync).

Verification (independent of builder)

  • cargo test -p ripr — 3647 passed, 0 failed
  • cargo test -p ripr --test lsp_lifecycle — 25 passed
  • cargo clippy -p ripr --all-targets -- -D warnings — clean
  • cargo fmt --check — clean
  • cargo xtask precommit / goldens check / dogfood — all exit 0

Notes

  • serve_stdio_call_presence_observer (structural source observer) updated to pin the new bounded composition.
  • No new RIPR-SPEC number allocated (single-writer resource); the PR slice (.allow/spec-system/slices/lsp-transport-bounds.v1.toml) + doc carry the evidence trail.

…ow readers (#2034)

ripr lsp --stdio had no explicit ingress/concurrency/egress policy:
tower-lsp's codec trusts Content-Length with no message cap, handlers
accepted unbounded initialization options, previousResultIds, and
executeCommand arguments, and a stopped reader could wedge the process
forever. A byte-transparent BoundedStdinReader now trips above an 8 KiB
header block or a 16 MiB declared message before the codec waits for the
body (one bounded -32700 then clean exit, per tokio-util's fused-error
semantics); typed validators reject oversized payloads with bounded
-32602 errors that echo no attacker input and mutate no state;
concurrency is explicit at the transport's own default of 4 (keeps
cancelRequest serviceable); and a 120 s write-stall deadline errors the
write half and wakes the stdin adapter so a stopped reader ends the
session cleanly instead of wedging. Adversarial coverage rides the
existing real-binary lsp_lifecycle harness: oversized/overflowing/
negative Content-Length, header flood, 5000-deep nesting, 5000-entry
duplicate previousResultIds, oversized executeCommand args and
initialization options, a 96-frame coalesced burst, cancel under load,
and EOF during overload. Residuals are documented in
docs/LSP_TRANSPORT_BOUNDS.md (no wire-level frame recovery, internal
queue constant, no per-message write deadline without forking).
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f48358f2-5790-4ac3-9d34-e221c5de3ab3

📥 Commits

Reviewing files that changed from the base of the PR and between 6f58ae0 and b6753bd.

📒 Files selected for processing (1)
  • crates/ripr/src/lsp/transport_bounds.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • EffortlessMetrics/ripr (auto-detected)
  • EffortlessMetrics/perl-lsp (auto-detected)
  • EffortlessMetrics/unsafe-review (auto-detected)
  • EffortlessMetrics/ub-review (auto-detected)

Summary by CodeRabbit

  • New Features
    • Added bounded LSP stdio transport handling to cap message/header sizes, limit in-flight request concurrency, and stop stalled sessions safely.
    • Added typed request/payload validation for initialization options, diagnostic previousResultIds, and executeCommand arguments, rejecting oversized/deeply nested inputs early.
  • Documentation
    • Published and indexed guidance for LSP transport and payload limits.
  • Tests
    • Extended lifecycle and adversarial coverage to confirm bounded JSON-RPC error behavior and prompt termination under malformed or abusive traffic.

Walkthrough

Adds bounded LSP stdio framing, request concurrency, stdout stall handling, and typed payload validation. The change wires these controls into the server, adds adversarial lifecycle and unit tests, and documents the limits and claim boundaries.

Changes

LSP transport bounds

Layer / File(s) Summary
Transport policy and integration
.allow/spec-system/slices/..., crates/ripr/src/lsp.rs, crates/ripr/src/lsp/tests.rs, docs/*
Defines the transport policy, routes stdio through bounded streams with explicit concurrency, and documents the configured limits and scope.
Bounded transport adapters
crates/ripr/src/lsp/transport_bounds.rs
Adds bounded frame parsing, shared session termination, stdout stall deadlines, and adapter/composition tests.
Typed payload validation
crates/ripr/src/lsp/payload_bounds.rs, crates/ripr/src/lsp/backend.rs
Validates initialization options, diagnostic result IDs, and executeCommand arguments before downstream work, using fail-closed serialized-size estimation.
Lifecycle and adversarial coverage
crates/ripr/tests/lsp_lifecycle.rs
Tests malformed framing, oversized payloads, deep JSON, concurrent requests, cancellation, serviceability, and clean shutdown behavior.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant LspClient
  participant BoundedTransport
  participant LspServer
  participant PayloadBounds
  LspClient->>BoundedTransport: Send framed request
  BoundedTransport->>LspServer: Admit bounded stream
  LspServer->>PayloadBounds: Validate typed arguments
  PayloadBounds-->>LspServer: Accept or InvalidParams
  LspServer-->>BoundedTransport: Send response
  BoundedTransport-->>LspClient: Response or bounded shutdown
Loading

Possibly related PRs

Poem

A rabbit found frames at the edge of the stream,
And bounded each payload before it could teem.
“No stalled output shall burrow too deep—”
Said the server, then settled to sleep.
Tests hopped through errors, healthy and bright.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed, but it does not follow the required template and omits most mandatory sections like Source-of-truth Links, Scope Classification, and Proof. Rewrite the PR description using the repository template and fill the missing sections with concrete links, scope, proof, rollback, and traceability details.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: bounded LSP transport, payload, concurrency, and slow-reader handling for #2034.
Linked Issues check ✅ Passed The PR implements the bounded stdio transport, payload validation, concurrency limit, slow-reader handling, docs, and adversarial tests required by #2034.
Out of Scope Changes check ✅ Passed All changes align with #2034's transport, payload, concurrency, backpressure, docs, spec, and test scope; no unrelated feature work is evident.
Docstring Coverage ✅ Passed Docstring coverage is 81.03% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/lsp-transport-bounds

Comment @coderabbitai help to get the list of available commands.

@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: 6f58ae098d

ℹ️ 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 crates/ripr/src/lsp/transport_bounds.rs Resolved
Review (codex P2): a trip that landed between a reader's is_tripped
check and its waker registration stranded the new waker — trip had
already drained the queue. Registration now checks the flag under the
same lock: already-tripped wakes by ref immediately; otherwise the
pending trip drains the registration next. Both orderings are pinned by
tests.
@EffortlessSteven
EffortlessSteven merged commit f5f150d into main Jul 22, 2026
24 checks passed
@EffortlessSteven
EffortlessSteven deleted the codex/lsp-transport-bounds branch July 22, 2026 04:18
@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.92145% with 27 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/ripr/src/lsp/transport_bounds.rs 96.45% 18 Missing ⚠️
crates/ripr/src/lsp/payload_bounds.rs 92.96% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

EffortlessSteven added a commit that referenced this pull request Aug 30, 2026
…headline entries (#3591)

* docs(changelog): consolidate Unreleased headings and add the missing headline entries

The Unreleased section carried duplicate Added/Fixed headings and
omitted the release's headline features. Consolidate to one Added /
Changed / Fixed sequence (0.10.0 convention) and add verified entries
for:

- ripr mcp --stdio server and startup routing (#3088, #3525, #3587)
- ripr rerun changed-test targeted analysis (#1520)
- the binary-first evidence/gate surface: ripr plus, pr-summary,
  pr-evidence, annotations, impacted-evidence (#1476/#1460/#1468/#1467/#1474)
- --suppression-policy and --exception-policy policy flags (#1475/#1477)
- the cache management surface: status, clear, atomic writes
  (#1822/#2865/#2738)
- the LSP capability wave: pull diagnostics, listActionableItems,
  transport bounds (#1669/#3012/#2185)
- analysis performance: per-file fact cache, rayon parallel parse,
  artifact reuse (#2039/#2322/#2250)

Every cited PR verified MERGED via the GitHub API. Also corrects the
stale 0.10.0 release-date line (crates.io publication 2026-06-15;
GitHub release draft remains unfinalized).

* docs(changelog): drop the superseded duplicate MCP entry (#3591 review)

The pre-existing Added block already carried an MCP entry from the
#3525 merge; keep the expanded consolidated entry (startup routing,
verbose handling, review fixes) and remove the older shorter one.
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.

security(lsp): bound JSON-RPC framing, payload size, request concurrency, and output backpressure

1 participant