Skip to content
SSRF Write-up Advanced

Inside PostHog: SSRF, ClickHouse SQL Escape and Default Postgres Creds to RCE

PostHog's webhook save endpoint did not validate the destination URL, and the Rust webhook worker did not re-validate it, giving a persistent SSRF. The SSRF was used to reach ClickHouse's unauthenticated HTTP API, where a PostgreSQL escaping flaw in the postgresql() table function allowed SQL injection and, via COPY FROM PROGRAM, remote code execution on the PostgreSQL container.

mdisec.com

Published on mdisec.com

Dec 15, 2025

Mehmet Ince, on mdisec.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the webhook save endpoint lacked the SSRF validation applied by the test endpoint, and the worker trusted saved URLs without re-checking; separately, ClickHouse escaped single quotes with a backslash when building a PostgreSQL query, which PostgreSQL does not treat as an escape.

Impact

An authenticated user could chain the SSRF and SQL injection to execute operating system commands on the PostgreSQL container, leading to remote code execution.

What the attacker needed

A PostHog account; self-hosted PostHog instance; network access to internal services

How it was found

  1. Send a direct PATCH request to the project API to save a webhook URL pointing to an internal address, bypassing the frontend test.
  2. Create an action with a regex matching all events so the webhook fires on any event.
  3. Send an event to PostHog to trigger the Rust webhook worker, which requests the saved internal URL.
  4. Use the SSRF to reach ClickHouse's HTTP API on port 8123 with a GET request.
  5. Inject into the postgresql() table function's table name to break out of the COPY statement.
  6. Use END to leave the read-only transaction and COPY FROM PROGRAM to run an OS command.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A webhook is a URL that a service calls automatically when something happens. PostHog checked the URL only when you tested it, but not when you saved it, so an attacker could save an internal address and make the server call it. That let the attacker reach an internal database service and run commands on it.

What is SSRF?

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.

Similar reports

View all

Same bug class and techniques, clearest first.

Server-side request forgery (SSRF)

The lesson behind this report.

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.