mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #1847] [Feature]: Log authentication failures with the client source IP (for fail2ban / rate limiting) #727
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#727
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @wszhoho on GitHub (Oct 10, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1847
What do you want to do?
Please log authentication failures (HTTP 401) with the client's source IP address, so that external tools such as fail2ban can detect and ban clients that keep trying wrong API keys against the server.
Background / current behavior
The server protects
/v1/*with an API key (api_keyin the config, or--api-key/STRATA_API_KEY). When authentication fails,_authorized()inserve/server.pyonly replies with a 401 JSON body (typeauthentication_error, messagemissing or wrong API key) and returns. No log line is written, and crucially no client IP is recorded.Because there is nothing to match on, a self-hosted deployment cannot use
fail2ban(or any IP-based rate limiting) to defend against brute-force attempts on the API key, even though the server is typically exposed on the public internet (e.g. behind a router DNAT to port 8080).What already works elsewhere / the pattern that would help
llama.cpp's server logs exactly this line on a bad key:and a fail2ban
filter+nftablesjail matches that line to ban the offender. Strata's 401 path currently produces no such log line at all.Suggested outcome (goal, not a specific implementation)
A single line to
stderron an authentication failure that includes the client IP (the code already hasself.client_address[0]available in the handler). Format similar to llama.cpp would let the same fail2ban filter work unchanged for both servers.Environment
127.0.0.1:8080@Niko1221 commented on GitHub (Oct 13, 2026):
Thanks for the report. To keep the tracker current we are closing issues older than three days: 0.1.44 is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1.
If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.
@wszhoho commented on GitHub (Oct 16, 2026):
Reopening request: this was closed by the stale-issue sweep rather than a fix — I diffed
_authorized()between v0.1.41 and v0.1.44.1 and it is byte-for-byte identical, so the silent-401 path described above still produces no log line on current releases.I've submitted a fix in #2712: one line on the auth-failure branch that logs
unauthorized: Invalid API Key from <client ip>to stderr, worded verbatim like llama.cpp's line so an existing fail2ban filter works against both servers unchanged. It applies cleanly to v0.1.44.1 (serve/server.py,_authorized()).Happy to adjust wording/format or add anything you'd need (e.g. gating it behind a config flag). Thanks!