[PR #2712] [CLOSED] log unauthorized API-key attempts with the client IP (issue #1847) #4227

Closed
opened 2026-11-07 15:34:10 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2712
Author: @wszhoho
Created: 10/16/2026
Status: ❌ Closed

Base: main ← Head: fix/issue-1847-auth-ip-log


📝 Commits (1)

  • 9ea563a log unauthorized API-key attempts with the client IP (issue #1847)

📊 Changes

1 file changed (+4 additions, -0 deletions)

View changed files

📝 serve/server.py (+4 -0)

📄 Description

What this does

Adds a log line on API-key authentication failure that includes the client source IP, so fail2ban (or any log-based rate limiter) can match it and ban brute-force attempts. Closes #1847.

Before this change, _authorized() in serve/server.py replied with a silent 401 JSON body — nothing landed in the journal, so there was nothing for a filter to match on.

print(f"unauthorized: Invalid API Key from {self.client_address[0]}", file=sys.stderr, flush=True)

The wording deliberately mirrors llama.cpp's unauthorized: Invalid API Key from <ip> verbatim (as requested in #1847), so an existing fail2ban filter written for llama.cpp works against Strata's logs unchanged.

Notes:

  • Goes to stderr, consistent with other warnings in this file (e.g. the AMD line at L2845); flush=True keeps journald real-time so fail2ban doesn't miss events.
  • No [strata] prefix on purpose, to keep the line byte-compatible with the stock llama.cpp filter regex.
  • sys is already imported at module level; no new dependencies.

Verification

  • python3 -m py_compile serve/server.py passes.
  • Smoke-tested the patched failure branch in isolation: emits exactly unauthorized: Invalid API Key from 203.0.113.7 on stderr.
  • Not end-to-end tested against a running server (needs GPU/model engine); the change is one print statement on the existing 401 path.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/2712 **Author:** [@wszhoho](https://github.com/wszhoho) **Created:** 10/16/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/issue-1847-auth-ip-log` --- ### 📝 Commits (1) - [`9ea563a`](https://github.com/Niko1221/Strata/commit/9ea563ad7853a1900115afffccf436cdba54e15a) log unauthorized API-key attempts with the client IP (issue #1847) ### 📊 Changes **1 file changed** (+4 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+4 -0) </details> ### 📄 Description ## What this does Adds a log line on API-key authentication failure that includes the client source IP, so fail2ban (or any log-based rate limiter) can match it and ban brute-force attempts. Closes #1847. Before this change, `_authorized()` in `serve/server.py` replied with a silent 401 JSON body — nothing landed in the journal, so there was nothing for a filter to match on. ```python print(f"unauthorized: Invalid API Key from {self.client_address[0]}", file=sys.stderr, flush=True) ``` The wording deliberately mirrors llama.cpp's `unauthorized: Invalid API Key from <ip>` verbatim (as requested in #1847), so an existing fail2ban filter written for llama.cpp works against Strata's logs unchanged. Notes: - Goes to `stderr`, consistent with other warnings in this file (e.g. the AMD line at L2845); `flush=True` keeps journald real-time so fail2ban doesn't miss events. - No `[strata]` prefix on purpose, to keep the line byte-compatible with the stock llama.cpp filter regex. - `sys` is already imported at module level; no new dependencies. ## Verification - `python3 -m py_compile serve/server.py` passes. - Smoke-tested the patched failure branch in isolation: emits exactly `unauthorized: Invalid API Key from 203.0.113.7` on stderr. - Not end-to-end tested against a running server (needs GPU/model engine); the change is one print statement on the existing 401 path. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:34:10 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4227
No description provided.