Skip to content

SQL literal redaction: comments, backslash escapes and dollar quotes shift quote pairing #109

Closed

Description

@krassx

redactSqlLiterals (packages/performance/src/span-sanitizer.ts) pairs quotes left to right, so a quote character that is not a string delimiter shifts the pairing and a literal after it is left in the clear. This is pre-existing on main (found by the review of #104, which did not change the pairing rule), so it is recorded here rather than fixed there.

Repros (each secretN survives redaction; redactSqlLiterals(statement)):

  1. Apostrophe in a block comment: /* don't */ SELECT * FROM t WHERE a = 'secretA'
  2. Apostrophe in a line comment: -- it's\nSELECT * FROM t WHERE a = 'secretB'
  3. Backslash-escaped quote (MySQL, Postgres with standard_conforming_strings = off): INSERT INTO t VALUES ('O\'Brien','secretC')
  4. Dollar quoting (Postgres): SELECT $$it's$$, 'secretD'

Likely shape of a fix: tokenise instead of pairing quotes, i.e. skip -- and /* */ comments, treat \' as an escape where the dialect allows it, and recognise $tag$ ... $tag$ bodies; whichever tokens it cannot classify should fail closed (redact to the end of the statement).

Related, already handled in #104: a statement cut by a length cap inside a literal (the open trailing literal is now replaced).

Activity

  1. 24 remaining items

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions