GHSA-3w55-933p-8pv5 Strands Agents: Local Privilege Escalation via Symlink Attack in Default Session File Storage
- Published
- Updated
- Exploit status
- No public exploit known
Description
Summary
The FileSessionManager defaults to storing session data in /tmp/strands/sessions/ (a world-writable directory) using predictable file paths and a write pattern (open(path + ".tmp", "w") → os.replace()) that follows symbolic links. A local attacker can exploit this to overwrite arbitrary files or inject malicious session data for persistent prompt injection.
Vulnerability Details
Component: strands-py/src/strands/session/file_session_manager.py
Root Cause:
- Default storage directory is
tempfile.gettempdir() + "/strands/sessions/"(line 58) — resolves to/tmp/strands/sessions/on Linux/macOS - The
_write_file()method (lines 116-123) writes to a predictable.tmppath without symlink protection:tmp = f"{path}.tmp" with open(tmp, "w", encoding="utf-8", newline="\n") as f: json.dump(data, f, indent=2, ensure_ascii=False) os.replace(tmp, path) open()follows symlinks — a pre-placed symlink at the.tmppath causes writes to an arbitrary target file- No integrity verification (HMAC/signature) on session files — tampered data is loaded as-is
Attack Vectors
1. Arbitrary File Overwrite (Local Privilege Escalation)
- Attacker pre-creates
/tmp/strands/sessions/session_<id>/(or monitors for new directories via inotify) - Attacker creates a symlink:
session.json.tmp→/home/victim/.bashrc(or any writable file) - Victim application writes session data → follows symlink → overwrites target file with JSON content
- Attacker achieves code execution on next shell login (or targets
.ssh/authorized_keys, cron files, etc.)
2. Persistent Prompt Injection via Session Tampering
- Attacker writes crafted message files into the session directory
- Victim application restores the session → loads attacker-controlled conversation history
- Injected messages instruct the agent to execute attacker commands on every future interaction
- No integrity check prevents this — the SDK trusts all session files at face value
Impact
- Arbitrary file overwrite — local attacker can write attacker-controlled content to any file writable by the victim process
- Local privilege escalation — via overwriting shell configs, SSH keys, cron jobs, or systemd user services
- Persistent agent compromise — via session data injection, the agent follows attacker instructions indefinitely
Reproduction
import os, json, tempfile, shutil
# Setup: simulate the vulnerable write pattern
session_dir = "/tmp/strands/sessions/session_test/"
os.makedirs(session_dir, exist_ok=True)
# Attacker: create symlink at the .tmp write path
target_file = "/tmp/symlink_attack_proof.txt"
with open(target_file, "w") as f:
f.write("ORIGINAL - should not be overwritten\n")
symlink_path = os.path.join(session_dir, "session.json.tmp")
if os.path.exists(symlink_path):
os.unlink(symlink_path)
os.symlink(target_file, symlink_path)
# Victim: FileSessionManager._write_file() equivalent
with open(symlink_path, "w", encoding="utf-8", newline="\n") as f:
json.dump({"session_id": "test", "injected": True}, f, indent=2)
# Verify: target file overwritten
with open(target_file) as f:
print(f"Target file content: {f.read()}")
# Output: {"session_id": "test", "injected": true}
# Cleanup
os.unlink(symlink_path)
os.unlink(target_file)
shutil.rmtree(session_dir)
Suggested Fix
- Use a user-private default directory —
~/.strands/sessions/or$XDG_DATA_HOME/strands/sessions/instead of/tmp/ - Use
os.open()withO_NOFOLLOW | O_CREAT | O_WRONLY— refuses to follow symlinks - Use
tempfile.mkstemp()for atomic writes instead of predictable.tmpsuffix - Verify directory ownership matches the current user before writing
- Add optional integrity verification (HMAC) on session files to detect tampering
Upgrade path
1 package: 1 fixed.
| Package | Affected | Fixed in | Status |
|---|---|---|---|
| pypi strands-agents(PyPI) | < 1.48.0; = 0.0.1; = 0.1.0; = 0.1.1 +63 more | 1.48.0 | Fixed |
Affected products
| Product | Affected versions | Fixed in |
|---|---|---|
| pypi strands-agents(PyPI) | < 1.48.0 | 1.48.0 |
| pypi strands-agents(PyPI) | = 0.0.1 | No fix listed |
| pypi strands-agents(PyPI) | = 0.1.0 | No fix listed |
| pypi strands-agents(PyPI) | = 0.1.1 | No fix listed |
| pypi strands-agents(PyPI) | = 0.1.2 | No fix listed |
| pypi strands-agents(PyPI) | = 0.1.3 | No fix listed |
| pypi strands-agents(PyPI) | = 0.1.4 | No fix listed |
| pypi strands-agents(PyPI) | = 0.1.5 | No fix listed |
| pypi strands-agents(PyPI) | = 0.1.6 | No fix listed |
| pypi strands-agents(PyPI) | = 0.1.7 | No fix listed |
| pypi strands-agents(PyPI) | = 0.1.8 | No fix listed |
| pypi strands-agents(PyPI) | = 0.1.9 | No fix listed |
| pypi strands-agents(PyPI) | = 0.2.0 | No fix listed |
| pypi strands-agents(PyPI) | = 0.2.1 | No fix listed |
| pypi strands-agents(PyPI) | = 0.3.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.0.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.0.1 | No fix listed |
| pypi strands-agents(PyPI) | = 1.1.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.10.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.11.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.12.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.13.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.14.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.15.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.16.0 | No fix listed |
Show 42 more
| Product | Affected versions | Fixed in |
|---|---|---|
| pypi strands-agents(PyPI) | = 1.17.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.18.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.19.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.2.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.20.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.21.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.22.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.23.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.24.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.25.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.26.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.27.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.28.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.29.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.3.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.30.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.31.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.32.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.33.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.34.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.34.1 | No fix listed |
| pypi strands-agents(PyPI) | = 1.35.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.36.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.37.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.38.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.39.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.4.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.40.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.41.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.42.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.43.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.44.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.45.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.46.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.47.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.5.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.6.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.7.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.7.1 | No fix listed |
| pypi strands-agents(PyPI) | = 1.8.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.9.0 | No fix listed |
| pypi strands-agents(PyPI) | = 1.9.1 | No fix listed |
References
- github.com vendor-advisory
- github.com patch
- github.com patch
- github.com product
- github.com
- github.com