T09 · Insecure Skill Coding Practices
- Location
scripts/script.sh:8- Finding
Unescaped User Input Corrupts JSONL Records
- Content
View full analysis
> "$DATA_DIR/data.jsonl" } ``` ### Technical Analysis The `_save_entry` function directly interpolates `cmd` and `val` into a JSON object without applying JSON escaping. Shell quoting prevents ordinary shell word splitting, but it does not make the resulting content valid or safe JSON. An entry containing double quotes, backslashes, carriage returns, or newline characters can terminate or alter the intended JSON string. In particular, embedded newlines can create additional physical records in the JSONL file. Subsequent commands parse the file using line-oriented `grep` and `cut` operations rather than a JSON parser, so injected or malformed content can be displayed, searched, counted, or exported as if it were legitimate data. ### Attack Path 1. An attacker or untrusted caller supplies an entry containing JSON delimiters or newline characters to `scripts/script.sh add`. 2. `cmd_add` passes the supplied text to `_save_entry`. 3. `_save_entry` writes the text directly into `$DATA_DIR/data.jsonl` without JSON escaping. 4. The input produces malformed JSON or additional apparent JSONL records. 5. The `list`, `search`, `status`, `stats`, or `export` commands subsequently process the corrupted records as trusted lockout data. ### Impact Assessment Exploitation does not grant additional operating-system privileges or directly execute commands. Its scope is the configured lockout data file and all outputs derived from that file. An attacker able to invoke the tool can corrupt, falsify, or structurally alter stored records. Because the project presents itself as a lockout/tagout safe ...[truncated 115 chars]- Remediation
View remediation
> "$DATA_DIR/data.jsonl" ``` - Validate records when reading them and reject malformed JSON rather than parsing it with `grep` and `cut`. - Consider rejecting newline and other control characters if multiline entries are not an intended feature. - Write updates atomically and apply restrictive file permissions appropriate for safety-related records. ]]>
