Closed as not planned
Closed as not planned
Copy link
Labels
ai:pr-readyAI-created PR is ready for review | AI 生成的 PR 已等待评审AI-created PR is ready for review | AI 生成的 PR 已等待评审area:api云服务 / FastAPI / OpenAPI / MCP云服务 / FastAPI / OpenAPI / MCPstatus:in-progressSomeone or AI is working on it | 人工或 AI 正在处理Someone or AI is working on it | 人工或 AI 正在处理status:staleAuto-marked stale after 30d inactivity; closes 7d later unless exempt.Auto-marked stale after 30d inactivity; closes 7d later unless exempt.types:bugSomething isn't working | 功能异常Something isn't working | 功能异常
Description
Bug Description
_get_client_key in src/memos/api/middleware/rate_limit.py tries to rate-limit by API key when the Authorization header starts with krlk_:
auth_header = request.headers.get("Authorization", "")
if auth_header.startswith("krlk_"):
return f"ratelimit:key:{auth_header[:20]}"Real requests send Authorization: Bearer krlk_..., so the header never starts with krlk_ and this branch is unreachable. Every request — including ones carrying a valid API key — falls through to IP-based limiting, and behind a shared egress IP all keyed clients share one bucket.
Expected Behavior
Strip the Bearer scheme before checking the key prefix, so keyed requests get a per-key rate-limit bucket.
Environment
MemOS main, python 3.14.
Additional Context
Fix + red/green-verified tests ready; PR to follow referencing this issue.
Metadata
Metadata
Labels
ai:pr-readyAI-created PR is ready for review | AI 生成的 PR 已等待评审AI-created PR is ready for review | AI 生成的 PR 已等待评审area:api云服务 / FastAPI / OpenAPI / MCP云服务 / FastAPI / OpenAPI / MCPstatus:in-progressSomeone or AI is working on it | 人工或 AI 正在处理Someone or AI is working on it | 人工或 AI 正在处理status:staleAuto-marked stale after 30d inactivity; closes 7d later unless exempt.Auto-marked stale after 30d inactivity; closes 7d later unless exempt.types:bugSomething isn't working | 功能异常Something isn't working | 功能异常
Activity
Memtensor-AI commentedon Sep 28, 2026
🤖 AutoDev has picked up this issue and started working on it.
Task ID:
4c2787d77a027c1dWorking branch:
bugfix/autodev-2428-20260928163751188Target branch:
latest dev* branchWorkflow: opsp (analysis → coding → testing → PR)
I will post the PR link here once done. If I need more information, I will ask in the comments.
fix: strip Bearer prefix from Authorization header for rate limit key…
Memtensor-AI commentedon Sep 28, 2026
✅ AutoDev task
4c2787d77a027c1dcompleted.Summary: Fixed rate limiter middleware to correctly recognize Bearer tokens for per-key rate limiting. Previously, the middleware checked if the Authorization header started with "krlk_" directly, but real requests use the standard OAuth2 format "Authorization: Bearer krlk_...", causing all keyed requests to fall through to IP-based limiting. This meant clients behind shared NAT/proxy IPs incorrectly shared rate limit buckets.
The fix strips the Bearer scheme prefix (case-insensitive) before checking for the API key prefix, enabling proper per-key rate limiting. Added comprehensive test coverage with 7 new tests verifying Bearer token extraction, lowercase bearer support, backward compatibility with direct keys, and IP fallback behavior.
All 120 existing API tests passed with no regressions. Linting and formatting verified clean. The fix is minimal, focused, and maintains backward compatibility while correctly implementing the intended per-key rate limiting feature.
Base branch:
mainBranch:
bugfix/autodev-2428-20260928163751188Commit:
f080c2dPR: #2432
Assigned to: @syzsunshine219
Reviewers: @bittergreen
fix(api): strip Bearer scheme so keyed requests reach per-key rate-li…
fix(api): strip Bearer scheme so keyed requests reach per-key rate-li…
github-actions commentedon Oct 30, 2026
This issue has been automatically marked as stale due to inactivity.
github-actions commentedon Nov 7, 2026
This issue has been automatically closed due to inactivity.