You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: JsonFileAgentStateStore allows state keys to escape the configured root directory #4290
JsonFileAgentStateStore uses the caller-provided state key directly when constructing the .json, .jsonl, and .hash paths. User and session identifiers are encoded through safeSegment(...), but state keys are not.
A key containing .. segments or an absolute path can therefore escape the configured rootDirectory. This affects both writes and deletes. If an application or extension passes untrusted input as a state key, the process can write or delete files outside the configured state directory, subject to the process filesystem permissions.
TestState can be any simple State implementation, for example record TestState(String value) implements State {}.
The same path construction is used by getListPath(...) and getHashPath(...), so list state and list metadata are affected too.
Expected behavior
All state files should remain below the configured rootDirectory, regardless of the state key. A key containing path separators, .., or an absolute path should either be rejected with a clear validation error or encoded as a single safe filename segment.
Error messages
No exception is thrown. The operation succeeds and writes or deletes the path outside the configured root.
Environment
AgentScope-Java Version: 2.1.0-SNAPSHOT, main at cd8a21c4a
Java Version: 25
OS: macOS
Additional context
The issue is in JsonFileAgentStateStore.getStatePath(...), getListPath(...), and getHashPath(...), where sessionDir.resolve(key + suffix) is used directly. The existing session-ID encoding does not protect the state-key path.
A central state-key validation or encoding helper, plus regression tests for single-state save, list-state save, and delete, should cover the fix.
Activity