Bound the inbound request id before it reaches the logs and spans - #852
Bound the inbound request id before it reaches the logs and spans#852jcelliott wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe 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. ChangesRequest ID validation
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
crates/oxen-server/src/middleware.rs
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.
152b9f7 to
fdbc6cb
Compare
An
x-oxen-request-idheader 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 asoxen.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.