Skip to content

Commit 0502df6

Browse files
committed
fix(security): sanitize telemetry JSONL inputs against injection
SKILL, OUTCOME, SESSION_ID, SOURCE, and EVENT_TYPE values go directly into printf %s for JSONL output. If any contain double quotes, backslashes, or newlines, the JSON breaks — or worse, injects arbitrary fields. Fix: strip quotes, backslashes, and control characters from all string fields before JSONL construction via json_safe() helper.
1 parent 7e0b879 commit 0502df6

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

bin/gstack-telemetry-log

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ fi
151151
# ─── Construct and append JSON ───────────────────────────────
152152
mkdir -p "$ANALYTICS_DIR"
153153

154+
# Sanitize string fields for JSON safety (strip quotes, backslashes, control chars)
155+
json_safe() { printf '%s' "$1" | tr -d '"\\\n\r\t' | head -c 200; }
156+
SKILL="$(json_safe "$SKILL")"
157+
OUTCOME="$(json_safe "$OUTCOME")"
158+
SESSION_ID="$(json_safe "$SESSION_ID")"
159+
SOURCE="$(json_safe "$SOURCE")"
160+
EVENT_TYPE="$(json_safe "$EVENT_TYPE")"
161+
154162
# Escape null fields
155163
ERR_FIELD="null"
156164
[ -n "$ERROR_CLASS" ] && ERR_FIELD="\"$ERROR_CLASS\""

0 commit comments

Comments
 (0)