fix(security): reject ':' in tenant ids, count only POSTs for eve rate limit#5
Merged
Merged
Conversation
…e limit
Harden the per-user key boundary and fix the eve rate-limit double-count,
plus stale-doc cleanup. Folded into the existing tenant-isolation changeset.
Tenant isolation
- AgentMemory/ChatHistory/ToolCache now reject a ':' (the key separator) in
userId/sessionId/toolName. The whole isolation model rests on the key shape
`<prefix>:<userId>:<...>`, and only emptiness was validated — a ':' let keys
collide across users (e.g. user "a"+session "b:c" reached user "a:b"+session
"c" via the direct-key getChat/saveChat/deleteChat/forget paths).
- Added unit tests for the rejection across all three primitives.
eve rate limiting
- createRateLimitAuth counts only POST requests. eve drives each turn as two
authenticated requests (the message POST + a follow-up GET .../stream) and
the auth walk runs on both, so a turn was charged twice. Now one turn = one
token; session-read GETs fall through unthrottled. Documented in the README
and docstring; updated tests (a bare Request defaults to GET).
Docs
- Document deriving userId from a verified auth source (Clerk, Auth.js,
Supabase Auth, Auth0, ...), never a client-supplied value; added DEMO-ONLY
warnings to the ai-sdk-demo routes that trust an x-user-id header.
- Fixed stale references: search-tools `{@link withIndex}` -> ReactiveSearchIndex;
ai-sdk memory "scope" -> "userId"; corrected CLAUDE.md's superseded
namespace key-naming note.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Hardens the per-user tenant boundary and fixes the eve rate-limit double-count,
plus a sweep of stale docs/docstrings found in review. Folded into the existing
harden-tenant-isolationchangeset (no new changeset).Tenant isolation — reject
:in idsThe whole isolation model rests on the key shape
<prefix>:<userId>:<...>, butonly emptiness was validated. A
:in an id let keys collide across users — e.g.user
"a"+ session"b:c"resolves to the same Redis key as user"a:b"+session
"c", so the direct-key paths (getChat/saveChat/deleteChat/forget)could read or overwrite another user's data. The search-backed methods were safe
(they filter on the
userIdfield), which is why it was easy to miss.AgentMemory,ChatHistory,ToolCachenow reject a:inuserId/sessionId/toolNameup front (alongside the existing non-empty check).eve rate limiting — count only POSTs
eve drives each turn as two authenticated requests — the message
POSTplusa follow-up
GET …/streamthat opens the reply stream — and the auth walk runs onboth, so
createRateLimitAuthwas charging every turn twice (aslidingWindow(20)was really ~10 turns/min).
createRateLimitAuthnow throttles onlyPOSTrequests, so one turn = onetoken; session-read
GETs fall through unthrottled.GETis no longer rate-limited (it requires a validsession id to reach). Documented in the README + docstring.
Requestdefaults toGET).Docs
userIdfrom a verified server-side auth source (Clerk,Auth.js/NextAuth, Supabase Auth, Auth0, …), never a client-supplied value;
added
⚠️ DEMO ONLYwarnings to the ai-sdk-demo routes that trust anx-user-idheader.@upstash/agentkit-sdkfrom the eve README install command — it'salready a regular dependency, not something users install.
search-tools{@link withIndex}→ReactiveSearchIndex; ai-sdk memory "scope" → "userId"; corrected CLAUDE.md'ssuperseded
namespacekey-naming note.Testing
GET-skip tests);
pnpm typecheckandpnpm lintclean.Notes
:-rejection is a behavior change (callers passing colon-bearing ids nowthrow), but it lands within the already-unreleased breaking
harden-tenant-isolationline, so it's captured in that changeset rather than a new one.