Skip to content

Harden request logging and proxy trust - #92

Merged
Helio-206 merged 1 commit into
prodfrom
agent/log-proxy-hardening
Aug 17, 2026
Merged

Harden request logging and proxy trust#92
Helio-206 merged 1 commit into
prodfrom
agent/log-proxy-hardening

Conversation

@Helio-206

Copy link
Copy Markdown
Collaborator

Scope

  • Generate server-side X-Request-ID values and reject client correlation-ID spoofing, including early security responses.
  • Disable forwarded-header trust by default; enable it only through explicit TRUSTED_PROXY_IPS / OCR_TRUSTED_PROXY_IPS allowlists.
  • Remove raw exception details, upstream OCR response bodies, query strings, rejected validation values, and unsafe filenames from logs/public error paths.
  • Align the optional GPU OCR profile with API-key auth, CORS configuration, loopback binding, and the configured application entrypoint.

Validation

  • ./mvnw -B test — 30 tests passed.
  • python3 -m compileall -q app tests — passed.
  • docker-compose config with local validation variables — passed.
  • git diff --check — passed.

Related: #72

@Helio-206
Helio-206 marked this pull request as ready for review August 17, 2026 21:03
@Helio-206
Helio-206 merged commit d354e12 into prod Aug 17, 2026
2 checks passed
@Helio-206
Helio-206 deleted the agent/log-proxy-hardening branch August 17, 2026 21:03

@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: 1a007f7de9

ℹ️ 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".


# Default command - run with uvicorn
CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"]
CMD ["python", "-m", "app.main"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid importing the app twice at container startup

With the default Docker/Compose configuration, ENABLE_METRICS is true and this command first executes app.main as __main__; main() then asks Uvicorn to import app.main:app again in the same single-worker process. The second import re-registers the module-level Prometheus counters under the same names, causing ValueError: Duplicated timeseries in CollectorRegistry and preventing the OCR container from starting. Keep the direct Uvicorn entrypoint or otherwise ensure the application module is initialized only once.

Useful? React with 👍 / 👎.

Comment on lines +119 to +120
response = await call_next(request)
response.headers["X-Request-ID"] = request_id

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Add the request ID to unhandled-error responses

When an endpoint raises an unhandled exception before producing a response, call_next() propagates out of this middleware and the header assignment is skipped; Starlette's outer server-error middleware then invokes the registered Exception handler and returns a 500 without X-Request-ID. Consequently, the failures for which correlation is most useful cannot be matched to the request ID written to the server log. Attach the ID in the global exception response as well, or ensure this middleware adds it on the exception path.

Useful? React with 👍 / 👎.

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