T09 · Insecure Skill Coding Practices
- Location
scripts/dashboard.sh:53- Finding
Arbitrary Python Code Execution Through an Unescaped Stored Timestamp
- Content
View full analysis
/dev/null | head -1 | sed 's/.*: *"\([^"]*\)".*/\1/') # Convert timestamp to relative time (with improved error handling) REL_TIME="" if [ -n "$TIMESTAMP" ] && command -v python3 > /dev/null 2>&1; then REL_TIME=$(python3 -c " from datetime import datetime try: ts = '${TIMESTAMP}'.replace('Z', '+00:00') td = datetime.utcnow() - datetime.fromisoformat(ts) mins = int(td.total_seconds() // 60) if mins < 1: print('just now') elif mins < 60: print(f'{mins}m ago') elif mins < 1440: print(f'{mins//60}h {mins%60}m ago') else: print(f'{mins//1440}d ago') except Exception: pass " 2>/dev/null) fi ``` ### Technical Analysis The dashboard extracts `timestamp` from the file referenced by `~/.memory/contextkeeper/current-state.json` using text-processing utilities rather than a JSON parser. It then directly interpolates the extracted value into Python source code inside a single-quoted Python string. A timestamp containing a single quote can terminate that string and introduce additional Python statements. Shell quoting does not make this safe because the interpolation occurs while Bash constructs the argument passed to `python3 -c`. Consequently, a malicious checkpoint can cause arbitrary Python code to execute when the dashboard is opened. The normal checkpoint generator creates a fixed-format timestamp. Exploitation therefore requires an attacker or another process to modify the persistent state file or redirect the `current-state.json` symlink to crafted content. The dashboard explicitly accepts and reads that symlink, making stored state a security boundary that should not be trusted as executable source. ### Attack Path 1. The attacker obtains the ability to cre ...[truncated 1014 chars]- Remediation
View remediation
