Skip to content

Log the client address when a request is rejected - #476

Merged
QuentinFuxa merged 2 commits into
mainfrom
dev/log-rejected-client-address
Nov 14, 2026
Merged

QuentinFuxa merged 2 commits into
mainfrom
dev/log-rejected-client-address

Conversation

@QuentinFuxa

@QuentinFuxa QuentinFuxa commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Rejected requests were logged without the peer address, and capacity rejections and REST token failures were not logged at all. An operator could not trace repeated attempts or feed them to fail2ban or a proxy rule. This follows the remarks in discussion #463.

Changes:

  • Token rejections on /asr, /v1/listen and /v1/audio/transcriptions log a warning ending with (client=ADDRESS). The REST route did not log before.
  • The session limit middleware logs a warning with the same suffix when it refuses an upgrade.
  • The token is never logged.
  • docs/deployment.md describes the log lines. The Nginx example now sets X-Forwarded-For to $remote_addr, so a client cannot choose the logged address, and shows a per-address limit_conn, since the session cap is shared by all clients of a worker.

The address is the direct peer. Behind a proxy it is the forwarded address only when --forwarded-allow-ips trusts that proxy, which is Uvicorn's existing behaviour.

Validation:

  • The existing rejection scenarios in tests/test_session_limits.py and tests/test_server.py now assert the logged address and that a wrong token does not appear in the log. They fail without the change (6 failures) and pass with it.
  • Against a real Uvicorn server with 127.0.0.1 as trusted proxy, a request carrying X-Forwarded-For: 203.0.113.7 logs client=203.0.113.7. With proxy headers off it logs client=127.0.0.1.
  • Ruff passes.

Not validated: the Nginx directives were not run against an Nginx instance.

This does not add a per-client session cap inside WLK. Behind a shared proxy address that would need its own design.

Token and capacity rejections were logged without the peer address, so
repeated attempts could not be traced or banned from the server log.
Rejections on /asr, /v1/listen and /v1/audio/transcriptions now end with
(client=ADDRESS), and capacity rejections are logged as well. The token
is never logged.

The Nginx example forwards X-Forwarded-For so the logged address is the
real client when the proxy is trusted.
The Nginx example now overwrites X-Forwarded-For with the address Nginx
saw instead of appending to a client-supplied value, and shows a
per-address connection limit, since the session cap is shared by all
clients of a worker.
@QuentinFuxa
QuentinFuxa merged commit 843b12f into main Nov 14, 2026
9 checks passed
@QuentinFuxa
QuentinFuxa deleted the dev/log-rejected-client-address branch November 14, 2026 10:10
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