Repository navigation
fix: don't trust incoming request IDs by default - #696
Conversation
`server.request_id.trust_incoming` defaulted to true, so every FOCA app took a valid `X-Request-ID` from any client, into logs, the response header and audit events. Default to false, also in the middleware, so that deployments behind a proxy that sets or checks the header opt in. Gateways took the client's value unconditionally in 0.20; the migration guide names that change and its effect on audit events and records. Closes #695 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Say that the header isn't used as the identifier rather than ignored, as inbound requests keep it for plugins; name both conditions of opting in in the Helm guide, and records of gateways among what clients could choose. Warn against copying the opt-in of the gateway example. Check the generated identifier of audit events and the default of the model. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThis PR changes request ID handling from trusted-by-default to generated-by-default: middleware and configuration now ignore client-supplied IDs unless explicitly enabled for a suitably isolated proxy deployment, with tests covering the behavioral impact and documentation updated for logging, auditing, gateways, plugins, Helm, and migration. Sequence diagram for generated request ID handlingsequenceDiagram
participant Client
participant RequestIdMiddleware
participant App
participant Logs
participant Audit
participant Gateway
Client->>RequestIdMiddleware: HTTP request with X-Request-ID
alt trust_incoming is false
RequestIdMiddleware->>RequestIdMiddleware: Generate request ID
else trust_incoming is true
RequestIdMiddleware->>RequestIdMiddleware: Validate X-Request-ID
alt valid request header
RequestIdMiddleware->>RequestIdMiddleware: Use incoming request ID
else invalid or missing header
RequestIdMiddleware->>RequestIdMiddleware: Generate request ID
end
end
RequestIdMiddleware->>App: Forward request with request ID context
App->>Logs: Record request ID
App->>Audit: Record request ID
App->>Gateway: Record request ID
App-->>Client: Response with X-Request-ID
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #696 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 65 65
Lines 8523 8523
=========================================
Hits 8523 8523
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="docs/configuration/server.md" line_range="92-93" />
<code_context>
+By default, each request gets a new random identifier, and what clients send in the
+header isn't used as the identifier. `header` can't be a standard header such as `Content-Length`.
+
+Set `trust_incoming: true` if a proxy in front of the app sets or checks the header,
+and clients can't reach the app past it, e.g., to have the proxy's identifier in the
+app's logs. The app then takes the identifier from the request header if it has at most
+128 letters, digits and `._:-`, and otherwise generates one. Without such a proxy,
</code_context>
<issue_to_address>
**Clients control trusted request IDs**
When a proxy validates the header but forwards a client's value while `trust_incoming` is enabled, `RequestIdMiddleware` accepts any syntactically valid incoming value, so clients still choose the response, log, audit, and gateway-record identifiers.
Clarify that the option is safe only when the proxy replaces the incoming value and clients cannot reach the app directly.
Also at `docs/helm-chart.md:256-257`, `docs/migration-0.21.md:140-141`, `foca/context.py:81-82`.
</issue_to_address>
### Comment 2
<location path="docs/migration-0.21.md" line_range="149-152" />
<code_context>
+This changes the behaviour of gateways: the `request_id()` of `foca.plugins.adapter`
+took a valid `X-Request-ID` of any client in 0.20, unconditionally, and now follows
+[`server.request_id`](configuration/server.md#request-ids). By default, the field
+`request_id` of [pipeline runs and their records](plugins.md#provenance) therefore has the
+generated identifier, not what the client sent. Clients and dashboards that look up
+these records by their own value need to take the identifier from the response header
+instead, or a deployment that meets the conditions above sets the option to `true`.
## Command-line tool
</code_context>
<issue_to_address>
**Worker records lack request IDs**
When a gateway processes a request through its Celery worker, the worker path calls `PluginHost.start` without `request_id`, so its pipeline records still have no request identifier and cannot be correlated using the HTTP response header, contrary to the migration guidance.
Qualify the migration guidance for synchronous gateway requests and explain that worker-based gateways must explicitly propagate an identifier if they want it recorded and correlated.
</issue_to_address>Linked issues
#695 fix: don't trust incoming request IDs by default · 3 of 3 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Default server.request_id.trust_incoming to false and let deployments behind a proxy that handles the header opt in. |
✅ Met | The configuration model and RequestIdMiddleware default to false; the app passes the configured value to the middleware, which accepts valid incoming IDs when enabled. |
| 2 | Rewrite the garbled paragraph in docs/configuration/server.md. |
✅ Met | The section now explains the default, opt-in conditions, validation of incoming IDs, and the risk of proxies passing through client values. |
| 3 | In docs/migration-0.21.md, name the option and its effect on audit events, including the change for gateways whose old behaviour was unconditional. |
✅ Met | The migration guide identifies the option, explains its effect on audit events and gateway records, and describes gateways' unconditional use of valid client IDs in 0.20. |
Sourcery assessment
Needs a human reviewer. 1 finding to address first, and deployments that relied on a proxy or client’s X-Request-ID will instead get a generated ID unless they opt in, so audit and gateway provenance records may contain IDs that their existing lookups cannot correlate to. Reverting restores the old behavior for future requests, but it does not change records already written.
Blocking findings: docs/configuration/server.md:93
A proxy that only checks the format of the header leaves the choice to clients, as the app takes any valid value: it must replace or reject what they send. Also say that runs in Celery tasks only have the identifier that the app passes on. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
server.request_id.trust_incomingnow defaults tofalse, in the configuration model and inRequestIdMiddleware. Each request gets a generated identifier, unless a deployment behind a proxy that sets or checks the header opts in. So clients no longer choose the identifier in logs, the response header, audit events and the records of gateways.Closes #695
docs/configuration/server.md;docs/migration-0.21.mdnames the option, its effect on audit events and the change for gateways, whoserequest_id()took a client's value unconditionally in 0.20; adjustsdocs/configuration/log.md,docs/plugins.mdanddocs/helm-chart.md.trust_incoming: Trueexplicitly for its integration test, with the overlayno-trust.yamlfor the other value. Its comment now warns against copying that.inbound_from_request()still copies a client'sX-Request-IDinto the inbound headers, as before. The docs now say so, rather than claiming that the header is ignored.Verification
test_not_trusted,TestApp::test_default,test_request_id_of_client, adaptertest_request_id), then passed.coverage run -m pytestagainst a MongoDB 7.0.34 of its own, on the first commit: 4250 passed, 2 skipped, 100% coverage. After the review fixes (docs, comments, tests): the affected test files, 421 passed.ruff check,ruff format --check,mypy,mkdocs build --strict,ast-grep scan,semgrep, and pre-commit on the 14 changed files: passed.tests/integration_gateway_tests.py(needs Docker) and the Helm chart tests; these ran in CI.CI passed, including all test jobs,Integration test,Chart,Chart install,Lint, image scans and CodeQL.mypy,ruff,mkdocs build --strictand pre-commit passed locally; CI ran again before the merge.nginx.tmpl(map of$http_x_request_id) onmain.Declined review findings
server.mdonly and link to it from the migration guide and the Helm guide (low): the migration guide is what the issue asks to name this in, and it should stand on its own for people upgrading.X-Request-IDfrom the inbound headers in the adapter (low, offered as an alternative): it changes what plugins see, beyond this issue. Documented instead.🤖 Generated with Claude Code