Skip to content

fix(server-utils): Sanitize PostgreSQL dollar-quoted strings in `db.q… - #24248

Merged
s1gr1d merged 1 commit into
developfrom
sig/db-tests-improvements
Sep 10, 2026
Merged

fix(server-utils): Sanitize PostgreSQL dollar-quoted strings in `db.q…#24248
s1gr1d merged 1 commit into
developfrom
sig/db-tests-improvements

Conversation

@s1gr1d

@s1gr1d s1gr1d commented Sep 9, 2026

Copy link
Copy Markdown
Member

Follow-up for #24089 to add some more sanitization tests.

The tests found a leak. sanitizeSqlQuery handles '...' but not PostgreSQL's $$...$$, so WHERE email = $$jane@example.com$$ went out raw and getSqlQuerySummary read the tail as a table name. It now takes a dollar-quoted body as one unit, for standard only, since MySQL has no dollar quoting and allows $ in
identifiers.

Also fixed: N'Jane' left its N behind, and SQLite ?1 became ??.

SQL Server [bracketed] identifiers containing a quote still desync the scanner. That needs an mssql dialect, so it gets its own PR.

Sources:

@s1gr1d
s1gr1d requested a review from a team as a code owner September 9, 2026 13:15
@s1gr1d
s1gr1d requested review from Lms24, logaretm and stephanie-anderson and removed request for a team and stephanie-anderson September 9, 2026 13:15
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 28.81 kB - -
@sentry/browser - with treeshaking flags 27.12 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.01 kB - -
@sentry/browser (incl. Tracing) 49.27 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 49.28 kB - -
@sentry/browser (incl. Tracing, Profiling) 52.21 kB - -
@sentry/browser (incl. Tracing, Replay) 88.81 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.99 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 93.49 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 106.44 kB - -
@sentry/browser (incl. Feedback) 46.3 kB - -
@sentry/browser (incl. sendFeedback) 33.87 kB - -
@sentry/browser (incl. FeedbackAsync) 38.99 kB - -
@sentry/browser (incl. Metrics) 29.84 kB - -
@sentry/browser (incl. Logs) 30.1 kB - -
@sentry/browser (incl. Metrics & Logs) 30.78 kB - -
@sentry/react 30.57 kB - -
@sentry/react (incl. Tracing) 51.64 kB - -
@sentry/vue 36.07 kB - -
@sentry/vue (incl. Tracing) 51.56 kB - -
@sentry/svelte 28.85 kB - -
CDN Bundle 30.56 kB - -
CDN Bundle (incl. Tracing) 49.81 kB - -
CDN Bundle (incl. Logs, Metrics) 32.83 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 51.77 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.48 kB - -
CDN Bundle (incl. Tracing, Replay) 87.35 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 89.26 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 93.28 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 95.27 kB - -
CDN Bundle - uncompressed 90.47 kB - -
CDN Bundle (incl. Tracing) - uncompressed 148.36 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.04 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 154.32 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 226.3 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 267.95 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 273.9 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 281.65 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 287.59 kB - -
@sentry/nextjs (client) 54.09 kB - -
@sentry/sveltekit (client) 49.73 kB - -
@sentry/core/server 36.99 kB - -
@sentry/core/browser 13.55 kB - -
@sentry/node 128.05 kB +0.15% +180 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 81.61 kB - -
@sentry/node - without tracing 88.73 kB +0.03% +22 B 🔺
@sentry/node - without channel injection 107.28 kB +0.15% +160 B 🔺
@sentry/aws-serverless 97.12 kB +0.03% +25 B 🔺
@sentry/cloudflare (withSentry) - minified 202.36 kB +0.16% +311 B 🔺
@sentry/cloudflare (withSentry) 503.59 kB +0.14% +683 B 🔺

View base workflow run

@Lms24 Lms24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice follow-up, thanks!

@s1gr1d
s1gr1d added this pull request to stack #24251 September 9, 2026 13:33
Base automatically changed from sig/db-bugbot-and-helper to develop September 9, 2026 15:25
@s1gr1d
s1gr1d requested a review from a team as a code owner September 9, 2026 15:25
@s1gr1d
s1gr1d requested review from mydea and nicohrubec and removed request for a team September 9, 2026 15:25
@s1gr1d
s1gr1d force-pushed the sig/db-tests-improvements branch from f6d1a96 to 1fd6184 Compare September 9, 2026 15:25
@s1gr1d
s1gr1d merged commit c270736 into develop Sep 10, 2026
444 of 450 checks passed
@s1gr1d
s1gr1d deleted the sig/db-tests-improvements branch September 10, 2026 08:10
s1gr1d added a commit that referenced this pull request Sep 10, 2026
Follow-up for #24248,
which left the SQL Server case open.

The sanitizer had no state for T-SQL `[bracketed]` identifiers, so a
quote inside one desynced it: `SELECT * FROM [dbo].[user's] WHERE email
= 'jane@example.com'` leaked the address into `db.query.text` and
`db.query.summary`.

There is now an `mssql` dialect that reads `[...]` as an identifier, and
tedious, knex and Prisma route to it through a new
`toSqlDialect()` helper.

Two older leaks turned up while testing it: an identifier run ending in
an escaped closer (`[a]]`, `""`) was treated as closed and copied out
whole, and T-SQL money literals (`$1000`) survived because the integer
pattern protects PostgreSQL `$n` placeholders.

Known limit: SQLite accepts `[...]` too, but shares the `standard`
dialect with PostgreSQL, where reading brackets as identifiers would
keep `ARRAY['secret']` raw.

Sources:
- T-SQL identifiers:
https://learn.microsoft.com/en-us/sql/relational-databases/databases/database-identifiers
- T-SQL constants (money, `N'...'`):
https://learn.microsoft.com/en-us/sql/t-sql/data-types/constants-transact-sql
- SQLite double-quoted strings:
https://sqlite.org/quirks.html#double_quoted_string_literals_are_accepted
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