fix: restrict stateDelta from API endpoints to session scope#359
Open
g0w6y wants to merge 4 commits into
Open
Conversation
Keys prefixed with app: and user: in stateDelta write into shared app-level and cross-session user-level state, which gets merged into every session via getSession(). Restricting the API endpoints to session-scope keys only prevents callers from escalating writes beyond their own session.
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.
What
/runand/run_sseaccept astateDeltafield that is applied tothe session before the agent runs. The session service distinguishes
three state scopes by key prefix:
user:app:There was no restriction on which prefixes callers could use. A caller
could send
{"app:some_key": "value"}and write into the globalapp-level state, which
getSession()merges into every user's sessionvia
mergeStates(). WithDatabaseSessionServicethis is persistedacross server restarts.
Fix
Added
toSessionScopedDelta()which strips any key starting withapp:oruser:before the delta reaches the runner. Session-scopekeys (no prefix) pass through unchanged, so existing behavior for
normal use is unaffected.
Applied to both
/runand/run_sse.Why not filter in the runner or session service
The runner and session service are also used internally by agents and
tools that legitimately write cross-scope state. Filtering at the API
boundary is the right place — only user-supplied input from the HTTP
endpoints needs the restriction.
Testing