T09 · Insecure Skill Coding Practices
- Location
scripts/poll-share-notes.sh:16- Finding
Arbitrary Python Code Injection Through Bear Note Data and Configurable State Path
- Content
View full analysis
/dev/null || echo '[]') # Extract note IDs already processed PROCESSED=$(python3 -c "import json; print(json.dumps(json.load(open('$STATE_FILE'))['processed']))") # Filter to unprocessed notes and output python3 -c " import json, sys raw = json.loads('''$RAW''') processed = set(json.loads('''$PROCESSED''')) # grizzly returns a list; adapt to its actual output shape notes = raw if isinstance(raw, list) else raw.get('notes', raw.get('results', [])) new_notes = [n for n in notes if n.get('id') or n.get('identifier','') not in processed] ids = [] out = [] for n in new_notes: nid = n.get('id') or n.get('identifier','') ids.append(nid) out.append({ 'id': nid, 'title': n.get('title',''), 'content': n.get('text') or n.get('content') or n.get('body',''), 'tags': n.get('tags', []) }) # Update state state = json.load(open('$STATE_FILE')) state['processed'] = list(set(state['processed']) | set(ids)) json.dump(state, open('$STATE_FILE','w')) json.dump(out, sys.stdout) " ``` ### Technical Analysis The script interpolates untrusted values directly into source code supplied to `python3 -c`: - Bear data returned by `grizzly` is embedded inside a triple-quoted Python string as `json.loads('''$RAW''')`. - The environment-configurable `BEAR_SHARE_STATE` path is embedded inside quoted Python expressions such as `open('$STATE_FILE')`. - Processed-state JSON is similarly embedded into generated Python source. These values are treated as program text rather than data. A Bear field containing a triple-quote sequence can terminate the intended Python string and insert additional Python statements. A malicious state path containing quote c ...[truncated 1543 chars]- Remediation
View remediation
