Skip to content

fix(redshift-alpha): backslashes in user passwords and comments are not preserved - #39306

Merged
mergify[bot] merged 2 commits into
aws:mainfrom
ozelalisen:redshift-alpha-escape-literal-backslashes
Oct 16, 2026
Merged

mergify[bot] merged 2 commits into
aws:mainfrom
ozelalisen:redshift-alpha-escape-literal-backslashes

Conversation

@ozelalisen

Copy link
Copy Markdown
Member

Reason for this change

Redshift reads backslash escapes in plain string literals. A backslash in a user password or a table or column comment could be stored altered or make the statement fail.

Description of changes

  • Escape backslashes in quoteLiteral before doubling single quotes, so the value reaches Redshift as written.
  • Apply this to the CREATE USER and ALTER USER password and to the COMMENT ON TABLE and COMMENT ON COLUMN text.
  • Leave stored passwords and comments unchanged on upgrade. The next time a comment is sent, an escape such as \n in it is stored literally.
  • Add an acknowledgeable synthesis warning when User excludeCharacters doesn't include ', ", / or @, which the CREATE USER documentation disallows in clear-text passwords.
  • Leave \ out of that warning, although the documentation lists it, because Redshift accepted a password containing an escaped \.

Describe any new or updated permissions being added

No new permissions.

Description of how you validated changes

  • Build, lint and 291 unit tests pass.
  • Regenerated the six integ snapshots that embed the query provider; their templates change only in its asset hash.
  • On a development account, a build with this change stored backslashes in table and column comments exactly on create and update, and created a user who could log in with a backslash password.
  • ALTER USER was not run live.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

…ot preserved

Redshift reads backslash escapes in plain string literals. A backslash in a user password or a table or column comment could be stored altered or make the statement fail.

- Escape backslashes in `quoteLiteral` before doubling single quotes, so the value reaches Redshift as written.
- Apply this to the CREATE USER and ALTER USER password and to the COMMENT ON TABLE and COMMENT ON COLUMN text.
- Leave stored passwords and comments unchanged on upgrade. The next time a comment is sent, an escape such as `\n` in it is stored literally.
- Add an acknowledgeable synthesis warning when `User` `excludeCharacters` doesn't include `'`, `"`, `/` or `@`, which the [CREATE USER](https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_USER.html) documentation disallows in clear-text passwords.
- Leave `\` out of that warning, although the documentation lists it, because Redshift accepted a password containing an escaped `\`.

Validation:

- Build, lint and 291 unit tests pass.
- Regenerated the six integ snapshots that embed the query provider; their templates change only in its asset hash.
- On a development account, a build with this change stored backslashes in table and column comments exactly on create and update, and created a user who could log in with a backslash password.
- ALTER USER was not run live.
@github-actions github-actions Bot added the p2 label Oct 15, 2026
@aws-cdk-automation
aws-cdk-automation requested a review from a team October 15, 2026 14:50
@mergify mergify Bot added the contribution/core This is a PR that came from AWS. label Oct 15, 2026
@mergify
mergify Bot deployed to automation October 15, 2026 14:51 Active
@mergify
mergify Bot deployed to automation October 15, 2026 14:51 Active
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ This pull request description does not follow the correct template structure.

PRs without a linked issue will receive lower priority for review and merging. Please update the description to follow the PR template and include a line like Closes #123 in the Issue section. If no existing issue matches your change, create one first.

@aws-cdk-automation aws-cdk-automation left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(This review is outdated)

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
This security report is NOT a review blocker. Please try merge from main to avoid findings unrelated to the PR.
To suppress a specific rule, see Suppressing Rules.


TestsPassed ✅SkippedFailed
Security Guardian Results168 ran168 passed
TestResult
No test annotations available

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
This security report is NOT a review blocker. Please try merge from main to avoid findings unrelated to the PR.
To suppress a specific rule, see Suppressing Rules.


TestsPassed ✅SkippedFailed
Security Guardian Results with resolved templates168 ran168 passed
TestResult
No test annotations available

@maintainer-for-aws

maintainer-for-aws Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Automated review

A maintainer will still review this — treat the notes below as a starting point.

📌 Commit 78687b8

Note: part of this change couldn't be included in this automated review, so it may be incomplete.

This PR fixes backslash handling in the experimental @aws-cdk/aws-redshift-alpha module: the private quoteLiteral helper now doubles embedded backslashes before doubling single quotes, so generated passwords and table/column comments reach Redshift exactly as written, and the User constructor gains an acknowledgeable synth-time warning when excludeCharacters omits characters Redshift disallows in clear-text passwords.

The change is small, additive, and well-formed. The escaping order is correct (quote-doubling inserts no backslash, so no re-escaping), the new warning is non-blocking and correctly skipped for Token-valued input, and no public API surface or default is broken. Unit tests directly assert the generated SQL and the warning branches. The large remainder of the diff is regenerated integ snapshots reflecting only the query-provider asset-hash change. The one open item is deploy-time verification of the backslash round-trip, noted below.

🔴 0 blocking · 🟡 1 recommended · ⚪ 0 optional

Files with findings (1)
File Findings
packages/@aws-cdk/aws-redshift-alpha/lib/private/database-query-provider/escape.ts 🟡 1

Generated automatically. React 👍 or 👎 to tell us whether this review helped, so we can improve these reviews.

@maintainer-for-aws maintainer-for-aws Bot 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.

See the review summary comment for the overview; the notes below are inline.

Comment on lines +21 to +23
*/
export function quoteLiteral(literal: string): string {
return `'${literal.replace(/'/g, "''")}'`;
return `'${literal.replace(/\\/g, '\\\\').replace(/'/g, "''")}'`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Recommended — The quoteLiteral fix escapes backslashes before doubling single quotes, changing how the Redshift query-provider Custom Resource formats password and COMMENT SQL. That correctness is only observable at deploy time, because the SQL executes inside the provider Lambda, so no synth snapshot can catch it — the six regenerated integ snapshots are only asset-hash churn. The existing integ stacks exercise no backslash: the exclude-characters stack passes an excludeCharacters set that already contains all five characters, and the database stack uses only plain comments. Combined with the author's note that the ALTER USER password path was not run live, the end-to-end round-trip this PR fixes has no real-deploy verification (INTEGRATION_TESTS.md).

Suggested change: Add a user with a backslash-bearing password and a table/column COMMENT containing a backslash to one of the existing integ stacks, with a deploy-time assertion (an awsApiCall with an ExpectedResult, e.g. reading the stored comment back via the Redshift Data API) confirming the backslash survives the round-trip. If a live Redshift deploy is genuinely impractical, apply the pr-linter/exempt-integ-test label with a note that the handler unit tests stand in for it.

@ozelalisen ozelalisen Oct 15, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Unit tests cover this: they assert the exact SQL for passwords and for table and column comments that contain backslashes.

@aws-cdk-automation aws-cdk-automation added the pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes. label Oct 15, 2026
@alvazjor alvazjor self-assigned this Oct 16, 2026

@alvazjor alvazjor left a comment

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.

LGTM

@ozelalisen ozelalisen added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Oct 16, 2026
@aws-cdk-automation
aws-cdk-automation dismissed their stale review October 16, 2026 16:27

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@mergify

mergify Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify

mergify Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-16 16:28 UTC · Rule: default-squash · triggered by rule automatic merge
  • 🚫 Left the queue — 2026-10-16 16:29 UTC · at fe18a0e50ef4a82d848ec40cae6d0c98ba30a37d

This pull request spent 48 seconds in the queue, with no time running CI.

Reason

The pull request can't be updated

GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/integration-test-approval-deployment.yml without workflows permission
GitHub only lets Mergify write to .github/workflows/ with the workflows permission. An organization owner can accept Mergify's pending permissions at https://dashboard.mergify.com/orgs/aws/repositories.

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify

mergify Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-16 17:23 UTC · Rule: default-squash · triggered by rule automatic merge
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-10-16 17:24 UTC · at 1f752b67bfdd52181273e9ffb17ae9005c16b9f9 · squash

This pull request spent 23 seconds in the queue, including 2 seconds running CI.

Required conditions to merge

@mergify
mergify Bot merged commit 1f752b6 into aws:main Oct 16, 2026
23 of 24 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 16, 2026
@ozelalisen
ozelalisen deleted the redshift-alpha-escape-literal-backslashes branch October 17, 2026 12:28

This branch was successfully deployed

1 active deployment
automation — 78687b87 Deployed Oct 16, 2026 by ozelalisen via validate-pr #373005
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

contribution/core This is a PR that came from AWS. p2 pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes. pr-linter/exempt-integ-test The PR linter will not require integ test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants