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 Values read from the log files are incorporated directly into JSON and CSV output without format-appropriate encoding. For JSON exports, characters such as double quotes, backslashes, carriage returns, and control characters are not escaped. An attacker-controlled value can terminate the intended JSON string, inject additional properties or objects, or make the document invalid. The output should be generated using a conforming JSON serializer rather than string interpolation. For CSV exports, fields are neither quoted nor escaped. Commas, quotes, and newlines can create additional fields or records. More importantly, values beginning with spreadsheet formula prefixes such as `=`, `+`, `-`, or `@` may be interpreted as formulas when the CSV file is opened in spreadsheet software. Depending on the spreadsheet applicati ...[truncated 2461 chars]- Remediation
View remediation
