Skip to content

fix(db): escape backslashes in PostgreSQL text[] literals - #333

Merged
BaaRai merged 1 commit into
BaaRai:mainfrom
Coff0xc:fix/pg-text-array-escape
Nov 18, 2026
Merged

BaaRai merged 1 commit into
BaaRai:mainfrom
Coff0xc:fix/pg-text-array-escape

Conversation

@Coff0xc

@Coff0xc Coff0xc commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

marshalStringArray builds PostgreSQL text[] literals and escaped " but not \. In array syntax a backslash still escapes the following quote, so a bound-domain / technology / record value of x\",evil,\"y can close the current element and inject another. It is still a bound parameter (no SQL statement injection), but metadata can be forged or the write can fail.

Escape backslashes before quotes, the same order as marshalJSONBArray.

Tested: go test ./db -run TestMarshalStringArray pass.

Copilot AI balanced review requested due to automatic review settings November 18, 2026 11:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@BaaRai BaaRai left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The escape order is right: backslashes are doubled before quotes, so x\",evil stays a single element, matching marshalJSONBArray. The test pins the injection case. Thanks.

marshalStringArray quoted double quotes but not backslashes. In a
Postgres array element a backslash escapes the following quote, so a
value such as x\",evil,\"y could close the current element and inject
another. Double backslashes first, matching marshalJSONBArray.
@BaaRai
BaaRai force-pushed the fix/pg-text-array-escape branch from c09f34a to 7681bac Compare November 18, 2026 16:09
@BaaRai
BaaRai merged commit b6b9284 into BaaRai:main Nov 18, 2026
5 checks passed
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.

3 participants