Skip to content

fix: prevent ClickHouse SQL injection in ListHooksTraces#2037

Open
mfbx9da4 wants to merge 1 commit intomainfrom
fix/clickhouse-sqli-hooks-traces
Open

fix: prevent ClickHouse SQL injection in ListHooksTraces#2037
mfbx9da4 wants to merge 1 commit intomainfrom
fix/clickhouse-sqli-hooks-traces

Conversation

@mfbx9da4
Copy link
Copy Markdown

@mfbx9da4 mfbx9da4 commented Mar 30, 2026

Summary

  • ListHooksTraces in server/internal/telemetry/repo/queries.sql.go constructs ClickHouse queries using filter.Path via fmt.Sprintf without input validation, allowing SQL injection
  • The sibling function ListTelemetryLogs (line 254) already validates paths against validJSONPath regex — this was simply missing from ListHooksTraces
  • A malicious filter.Path like x') OR '1'='1 would be interpolated directly into has(JSONExtractKeys(attributes), '...') and toString(attributes.\...`)` clauses
  • Added the same validJSONPath.MatchString(filter.Path) check to skip invalid paths

Test plan

  • go build ./server/internal/telemetry/... compiles cleanly
  • Verify hook traces listing still works with valid attribute filters
  • Confirm malicious filter paths are silently skipped

Open with Devin

…House SQL injection

ListHooksTraces constructs ClickHouse queries using filter.Path via
fmt.Sprintf without validating the input, unlike ListTelemetryLogs which
checks against validJSONPath regex. A malicious filter.Path like
"x') OR '1'='1" would be interpolated directly into SQL clauses
(JSONExtractKeys, attributes access), allowing data exfiltration or
query manipulation. Add the same validJSONPath check used elsewhere.
@mfbx9da4 mfbx9da4 requested a review from a team as a code owner March 30, 2026 22:14
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 30, 2026

⚠️ No Changeset found

Latest commit: ed02e9e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
gram-docs-redirect Ready Ready Preview, Comment Mar 30, 2026 10:14pm

Request Review

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 1 additional finding in Devin Review.

Open in Devin Review

Comment on lines 1494 to 1496
materializedCol, isMaterialized := materializedColumns[filter.Path]
var columnRef string
if isMaterialized {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 Inconsistent @-prefix path handling between ListLogs and ListHooksTraces

ListLogs (line 257) delegates column resolution to resolveAttributeColumn() which translates @-prefixed paths to toString(attributes.app.<path>). In contrast, ListHooksTraces (lines 1494-1501) does its own inline resolution that lacks @-prefix handling — an @user.region path would produce toString(attributes.\@user.region`)instead of the intendedtoString(attributes.app.user.region). This is a pre-existing inconsistency not introduced by this PR, but the new validJSONPathregex at line 1491 does accept@-prefixed paths (per the regex at queries.sql.go:25), so callers could pass such paths expecting them to work correctly. Additionally, the exists/not_existsbranches at lines 1524 and 1533 would pass the raw@user.regionstring intoJSONExtractKeys, which likely wouldn't match. Consider refactoring ListHooksTracesto useresolveAttributeColumn` for consistency.

(Refers to lines 1494-1501)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants