Repository navigation
Conversation
_get_client_key checked that the Authorization header starts with krlk_, but real requests send 'Bearer krlk_...', so the per-key branch was unreachable and every request fell into the shared IP bucket. Strip the scheme before the prefix check while keeping raw-key headers working. Fixes MemTensor#2428
🤖 Open Code ReviewTarget: PR #2430 🔍 OpenCodeReview found 1 issue(s) in this PR. 1.
|
✅ Automated Test Results: PASSEDAll tests passed (5/5 executed). memos_python_core/changed-repo-python: 5/5. Duration: 1s [advisory, non-gating] AI-generated tests on branch test/auto-gen-6bd078db5da45e3d-20260929005034: 20/20 passed — these do NOT affect the PR verdict; review the branch manually. Branch: |
|
This PR has been automatically marked as stale due to inactivity. |
|
This PR has been automatically closed due to inactivity. |
Fixes #2428
Summary
_get_client_keyinsrc/memos/api/middleware/rate_limit.pykeys the rate-limit bucket by API key when theAuthorizationheader starts withkrlk_:Real requests send
Authorization: Bearer krlk_..., so the header never starts withkrlk_and this branch is unreachable — every request, including ones carrying a valid API key, falls into the shared IP bucket (a single egress IP behind a proxy therefore shares one bucket across all keyed clients).Fix
Strip the
Bearerscheme before the prefix check; a rawkrlk_...header keeps working unchanged:Regression test
Added
tests/api/test_rate_limit_key.py:Bearer krlk_...case fails against the old implementation (falls back to the IP key) and passes with the fixbearer, the legacy raw-key header, non-key tokens, and the missing-header fallbackruff check(repo-pinned 0.11.8) passes on both touched files.AI Disclosure