Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(error-tracking): escape search text and fingerprints in issue events query (#62716)

Catalin Irimiee1ed7ca83acc
diff --git a/products/error_tracking/frontend/queries.test.ts b/products/error_tracking/frontend/queries.test.ts
index b46d030db6fb..fa5dec1ba72e 100644
--- a/products/error_tracking/frontend/queries.test.ts
+++ b/products/error_tracking/frontend/queries.test.ts
@@ -52,6 +52,29 @@ describe('queries', () => {
expect(actual.tags).toEqual({ productKey: ProductKey.ERROR_TRACKING })
})
+ it('escapes quotes in fingerprints and search text', () => {
+ const actual = errorTrackingIssueEventsQuery({
+ fingerprints: ["fp_with_'quote"],
+ filterTestAccounts: false,
+ filterGroup: {
+ type: FilterLogicalOperator.And,
+ values: [
+ {
+ type: FilterLogicalOperator.And,
+ values: [],
+ },
+ ],
+ },
+ searchQuery: "O'Brien",
+ dateRange: { date_from: '-7d', date_to: null },
+ columns: ['*'],
+ })
+
+ const where = (actual.where ?? []).join(' ')
+ expect(where).toContain("'fp_with_\\'quote'")
+ expect(where).toContain("'%O\\'Brien%'")
+ })
+
it('tags issue breakdown insight queries as error tracking', () => {
const actual = errorTrackingIssueBreakdownQuery({
breakdownProperty: '$browser',
diff --git a/products/error_tracking/frontend/queries.ts b/products/error_tracking/frontend/queries.ts
index 6afc4798c302..089b39e51c97 100644
--- a/products/error_tracking/frontend/queries.ts
+++ b/products/error_tracking/frontend/queries.ts
@@ -12,7 +12,7 @@ import {
NodeKind,
ProductKey,
} from '~/queries/schema/schema-general'
-import { HogQLQueryString, hogql, setLatestVersionsOnQuery } from '~/queries/utils'
+import { HogQLQueryString, escapeHogQLString, hogql, setLatestVersionsOnQuery } from '~/queries/utils'
import {
AnyPropertyFilter,
BaseMathType,
@@ -158,14 +158,14 @@ export const errorTrackingIssueEventsQuery = ({
const group = filterGroup.values[0] as UniversalFiltersGroup
const properties = [...group.values] as AnyPropertyFilter[]
- let where_string = `properties.$exception_fingerprint in [${fingerprints.map((f) => `'${f}'`).join(', ')}] AND isNotNull(properties.$exception_issue_id)`
+ let where_string = `properties.$exception_fingerprint in [${fingerprints.map((f) => escapeHogQLString(f)).join(', ')}] AND isNotNull(properties.$exception_issue_id)`
if (searchQuery) {
// This is an ugly hack for the fact I don't think we support nested property filters in
// the eventsquery
where_string += ' AND ('
const chunks: string[] = []
SEARCHABLE_EXCEPTION_PROPERTIES.forEach((prop) => {
- chunks.push(`ilike(toString(properties.${prop}), '%${searchQuery}%')`)
+ chunks.push(`ilike(toString(properties.${prop}), ${escapeHogQLString(`%${searchQuery}%`)})`)
})
where_string += chunks.join(' OR ')
where_string += ')'