Skip to content

[Bug bounty] Telemetry script injects unescaped special characters into JSON payload, corrupting PostHog events #179

Description

@arielbarbaro

Stage: connect · Severity: medium (data corruption) · OS: all · Agent: all · plugin/agent: v0.1.52

Summary

The _msan sanitization function in scripts/monk-launcher-telemetry.sh does not properly escape all JSON special characters before injecting values into the hand-built JSON payload. This causes PostHog events to be silently corrupted when property values contain characters like <, >, &, tabs, or control characters.

Root cause

The _msan function in monk-launcher-telemetry.sh line:

_msan() { printf '%s' "$1" | tr -d '"\\' | tr -d '\n\r'; }

This function only strips double-quotes (") and backslashes (\), plus newlines. It does NOT handle other characters that are special in JSON strings:

  • < and > (HTML/XML injection in property values)
  • & (HTML entity issues)
  • Tab characters (\t)
  • Other control characters (0x00-0x1F except 0x0A and 0x0D which are handled)
  • Unicode control characters

Reproduction

  1. Set MONK_PLUGIN_VERSION='test<version>test' as environment variable
  2. Run start-monk-agent.sh which sources monk-launcher-telemetry.sh
  3. The _payload variable becomes: {"plugin_version":"test<version>test",...}
  4. While < and > are technically valid in JSON strings, they cause issues with:
    • XML parsers (if PostHog ever processes events through XML pipelines)
    • HTML display in PostHog UI (XSS vector in event viewer)
  5. More critically, if MONK_POSTHOG_HOST contains a quote: MONK_POSTHOG_HOST='https://test"test.com'
    The payload becomes: {"api_key":"...","event":"...","host":"https://test"test.com",...}
    This is INVALID JSON and the entire event is dropped by PostHog.

Impact

  • PostHog events with special characters are silently corrupted or dropped
  • No error logging when events fail to send
  • Potential XSS vector if PostHog UI renders event properties without escaping
  • Data loss in telemetry analytics

Fix

Replace the hand-built JSON with proper escaping:

_msan() {
  printf '%s' "$1" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/\t/\\t/g' -e 's/\r/\\r/g' -e 's/\n/\\n/g'
}

Or use jq to build the payload properly:

printf '{}' | jq --arg key "$_ph_key" --arg cid "$_cid" \
  --arg mlc "$_mlc" --argjson first "$_first_start" \
  --argjson installed "$_agent_installed" \
  '.api_key=$key | .event="plugin_launcher_started" | .distinct_id=$cid | .launch_client=$mlc | .first_start=$first | .agent_installed=$installed'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions