fix(databases-on-aws): block psql meta-commands in psql-connect.sh --command#232
Open
anwesham-lab wants to merge 2 commits into
Open
fix(databases-on-aws): block psql meta-commands in psql-connect.sh --command#232anwesham-lab wants to merge 2 commits into
anwesham-lab wants to merge 2 commits into
Conversation
…command The --command sanitizer stripped single-quoted string literals and then rejected statement separators (;) and SQL comments (--, /*), but never checked for a leading backslash. psql dispatches meta-commands on a backslash, and \! runs a local shell command — so a --command value beginning with \! (or \copy, \i, \o, \set) passed both SQL checks and psql executed it as a client-side OS command / file read-write, with no database privilege required. Reject psql meta-commands before the SQL checks: strip single-quoted literals (a backslash inside a literal is data, not a meta-command), then reject any remaining backslash. This blocks the entire meta-command class while still allowing SELECT/INSERT/UPDATE/DDL/EXPLAIN, consistent with the allowlist already applied to --ai-model. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
6143eee to
ca5bd67
Compare
spencercorwin
previously approved these changes
Jul 13, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1490f31 to
fe9e1f1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Harden the
--commandsanitizer inpsql-connect.shso it rejects psql client meta-commands, closing a client-side command-execution path.Related
N/A
Changes
The
--commandsanitizer inplugins/databases-on-aws/scripts/psql-connect.shstripped single-quoted string literals and rejected statement separators (;) and SQL comments (--,/*), but did not check for a leading backslash.psqldispatches meta-commands on a backslash —\!runs a local shell command, and\copy/\i/\operform client-side file read/write — so a--commandvalue beginning with\!passed the SQL checks andpsqlexecuted it locally, with no database privilege required.This change rejects psql meta-commands before the SQL checks: it strips single-quoted literals (a backslash inside a literal is data, not a meta-command), then rejects any remaining backslash. This blocks the entire meta-command class (
\!,\copy,\i,\o,\set) while still allowingSELECT/INSERT/UPDATE/DDL/EXPLAIN, consistent with the allowlist already applied to--ai-model.Verified: meta-command payloads (
\! sh -c ...,\copy ... TO PROGRAM,\i,\o) are blocked; normalSELECT/INSERT/UPDATEare allowed; pre-existing multi-statement (;) and comment (--,/*) blocks remain intact.Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.