Skip to content

Bound the inbound request id before it reaches the logs and spans - #852

Draft
jcelliott wants to merge 1 commit into
mainfrom
je/bound-inbound-request-id
Draft

Bound the inbound request id before it reaches the logs and spans#852
jcelliott wants to merge 1 commit into
mainfrom
je/bound-inbound-request-id

Conversation

@jcelliott

Copy link
Copy Markdown
Contributor

An x-oxen-request-id header was adopted verbatim, with no limit on length or content. The value is returned on the response, written to both access-log lines, and recorded on every span of the request as oxen.request_id, so an untrusted caller could inflate all three, and a value carrying tabs or spaces (which a header may) blurs the access-log format.

An id is now adopted only when it is 1 to 128 characters of A-Za-z0-9, -, or _ — the shape of a UUID or a URL-safe base64 id, with room to spare. Anything else is replaced with a generated one, the same path a request arriving without the header already takes. Every consumer reads the id from this one function, so the response header, the two log lines, the task-local context and the span attribute all get the checked value.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5e5780df-7319-4f59-bfcd-4f12cea5082c

📥 Commits

Reviewing files that changed from the base of the PR and between 152b9f7 and fdbc6cb.

📒 Files selected for processing (1)
  • crates/oxen-server/src/middleware.rs

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved request tracking reliability by validating request IDs and generating replacements when values are missing or invalid.
    • Added safeguards for malformed, empty, oversized, or unsupported request ID values.
    • Enhanced diagnostic logging without exposing invalid request ID contents.

Walkthrough

The middleware validates inbound request IDs. It preserves nonempty ASCII alphanumeric, hyphen, and underscore values up to 128 bytes. It generates UUIDs for missing or malformed headers and logs rejected header byte lengths. Tests cover accepted and rejected formats.

Changes

Request ID validation

Layer / File(s) Summary
Validate and test request IDs
crates/oxen-server/src/middleware.rs
extract_or_generate_request_id validates length and characters, replaces invalid values with generated UUIDs, and logs rejected header lengths at debug level. Tests cover valid UUID, URL-safe, maximum-length, oversized, empty, whitespace-containing, and punctuation-containing IDs.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states that inbound request IDs are bounded before logging and tracing.
Description check ✅ Passed The description accurately explains request ID validation, fallback behavior, and consistent use across consumers.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch je/bound-inbound-request-id

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/oxen-server/src/middleware.rs`:
- Around line 35-37: Update the request-ID extraction in the middleware to
distinguish a missing OXEN_REQUEST_ID header from a UTF-8 conversion failure:
log header.len() when to_str() fails, then generate a replacement ID, while
preserving the existing missing-header behavior. Add a test using
HeaderValue::from_bytes that verifies opaque-byte headers trigger the
conversion-error log and replacement flow.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3dcc1bbd-d0d4-4a35-9cdc-eb5b5066e947

📥 Commits

Reviewing files that changed from the base of the PR and between 0a0b98c and 152b9f7.

📒 Files selected for processing (1)
  • crates/oxen-server/src/middleware.rs

Comment thread crates/oxen-server/src/middleware.rs Outdated
An `x-oxen-request-id` header was adopted verbatim, with no limit on
length or content — a 20,000-character id was accepted and echoed back.
The value is returned on the response, written to both access-log lines,
and recorded on every span of the request as `oxen.request_id`, so an
untrusted caller could inflate all three, and a value carrying tabs or
spaces (which a header may) blurs the access-log format.

An id is now adopted only when it is 1 to 128 characters of `A-Za-z0-9`,
`-`, or `_` — the shape of a UUID or a URL-safe base64 id, with room to
spare. Anything else is replaced with a generated one, the same path a
request arriving without the header already takes. Every consumer reads
the id from this one function, so the response header, the two log lines,
the task-local context and the span attribute all get the checked value.

A replacement is reported at `debug` with the id's byte length, including
when the header is not valid UTF-8 — a case that otherwise reads to the
log like no header at all, and whose value cannot be printed anyway.
@jcelliott
jcelliott force-pushed the je/bound-inbound-request-id branch from 152b9f7 to fdbc6cb Compare August 10, 2026 19:57
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