T09 · Insecure Skill Coding Practices
- Location
scripts/script.sh:58- Finding
Unescaped User-Controlled Data in JSON and CSV Exports
- Content
View full analysis
"$out" local first=1 for f in "$DATA_DIR"/*.log; do [ -f "$f" ] || continue local name=$(basename "$f" .log) while IFS='|' read -r ts val; do [ $first -eq 1 ] && first=0 || echo "," >> "$out" printf ' {"type":"%s","time":"%s","value":"%s"}' "$name" "$ts" "$val" >> "$out" done < "$f" done echo "\n]" >> "$out" ;; csv) echo "type,time,value" > "$out" for f in "$DATA_DIR"/*.log; do [ -f "$f" ] || continue local name=$(basename "$f" .log) while IFS='|' read -r ts val; do echo "$name,$ts,$val" >> "$out"; done < "$f" done ;; ``` ### Technical Analysis The export implementation directly interpolates log-file values into JSON and CSV without applying format-specific encoding. For JSON output, embedded quotation marks, backslashes, control characters, or newlines are not escaped. A crafted value can therefore terminate the intended JSON string and inject additional properties or objects. The use of `echo "\n]"` is also not portable and can place a literal `\n` sequence outside a JSON string, resulting in invalid JSON. For CSV output, fields containing commas, quotation marks, carriage returns, or newlines are not quoted according to CSV rules. Values beginning with spreadsheet formula indicators such as `=`, `+`, `-`, or `@` are written unchanged. When the resulting file is opened in spreadsheet software, such values may be interpreted as formulas rather ...[truncated 1727 chars]- Remediation
View remediation
