CVE-2026-17566: CWE-78 Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') in pgadmin.org pgAdmin 4
pgAdmin 4's Import/Export Data tool builds a psql \copy (...) command line by interpolating a user-supplied SQL query into a Jinja template and passing the rendered line to psql via --command. To stop an attacker from breaking out of the (...) wrapper, create_import_export_job() (route POST /import_export/job/<sid>, gated only by the ordinary, commonly-granted tools_import_export_data permission) validated the query with a hand-written parenthesis-balance checker, _is_query_parens_balanced(). That checker always treated a backslash before a single quote (\') as escaping the quote, i.e. as if standard_conforming_strings were off. PostgreSQL has defaulted standard_conforming_strings to on since 9.1 (2010), the default on every PostgreSQL version pgAdmin 4 currently supports (13-18); under that default psql's own \copy tokenizer treats \ as an ordinary character, so a single quote immediately after it closes the string literal. A query such as SELECT 'a\') TO PROGRAM 'echo pwned' x' was therefore accepted as "balanced" by pgAdmin's checker (which believed the ) was still inside the string), while psql, run through the actual rendered command line, closes the string at that point and treats the following ) as the end of the wrapping \copy (...) subquery, exposing an attacker-chosen TO PROGRAM '<command>' clause that psql executes via popen() -- independent of a subsequent syntax error later on the same line. This is the same class of bug as CVE-2025-12762/CVE-2025-13780 (RCE via psql meta-command/COPY injection during PLAIN-format dump restore), reached through an independently written defense in a different module (Import/Export Data rather than Restore) that had its own, different logic bug (inverted backslash-escape semantics rather than a BOM-defeated regex anchor). The fix rejects any backslash inside a single-quoted string in the query outright, rather than picking one of the two possible psql interpretations. This is intentionally conservative: because the correct interpretation of \ depends on the target server's standard_conforming_strings setting, which the checker cannot reliably know at validation time, refusing the query is safer than guessing. This issue affects pgAdmin 4: from the introduction of _is_query_parens_balanced() before 9.18.
AI Analysis
Technical Summary
pgAdmin 4's Import/Export Data tool constructs psql \copy commands by interpolating user SQL queries into a Jinja template and executing them via psql --command. To prevent command injection, a parenthesis-balance checker (_is_query_parens_balanced()) validates queries by assuming backslash escapes a single quote (standard_conforming_strings off). However, PostgreSQL defaults standard_conforming_strings to on since version 9.1, causing psql to treat backslash as a normal character and close string literals differently. This mismatch allows crafted queries like SELECT 'a\') TO PROGRAM 'echo pwned' x to bypass validation and inject arbitrary OS commands executed by psql via popen(). The vulnerability affects pgAdmin 4 versions before 9.18. The fix rejects queries containing backslashes inside single-quoted strings to avoid ambiguity, as the checker cannot reliably determine the server's standard_conforming_strings setting at validation time.
Potential Impact
Successful exploitation allows an attacker with the tools_import_export_data permission to execute arbitrary OS commands on the system running pgAdmin 4, leading to complete compromise of confidentiality, integrity, and availability of the affected system. The vulnerability enables remote code execution via injection of OS commands into psql's TO PROGRAM clause during data import/export operations.
Mitigation Recommendations
Patch status is not yet confirmed — check the vendor advisory for current remediation guidance. The vendor fixed the issue by rejecting any backslash inside single-quoted strings in queries to prevent ambiguous parsing. Until an official fix is available, restrict access to the tools_import_export_data permission and avoid using the Import/Export Data feature with untrusted input. Monitor vendor channels for updates and apply official patches once released.
CVE-2026-17566: CWE-78 Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') in pgadmin.org pgAdmin 4
Description
pgAdmin 4's Import/Export Data tool builds a psql \copy (...) command line by interpolating a user-supplied SQL query into a Jinja template and passing the rendered line to psql via --command. To stop an attacker from breaking out of the (...) wrapper, create_import_export_job() (route POST /import_export/job/<sid>, gated only by the ordinary, commonly-granted tools_import_export_data permission) validated the query with a hand-written parenthesis-balance checker, _is_query_parens_balanced(). That checker always treated a backslash before a single quote (\') as escaping the quote, i.e. as if standard_conforming_strings were off. PostgreSQL has defaulted standard_conforming_strings to on since 9.1 (2010), the default on every PostgreSQL version pgAdmin 4 currently supports (13-18); under that default psql's own \copy tokenizer treats \ as an ordinary character, so a single quote immediately after it closes the string literal. A query such as SELECT 'a\') TO PROGRAM 'echo pwned' x' was therefore accepted as "balanced" by pgAdmin's checker (which believed the ) was still inside the string), while psql, run through the actual rendered command line, closes the string at that point and treats the following ) as the end of the wrapping \copy (...) subquery, exposing an attacker-chosen TO PROGRAM '<command>' clause that psql executes via popen() -- independent of a subsequent syntax error later on the same line. This is the same class of bug as CVE-2025-12762/CVE-2025-13780 (RCE via psql meta-command/COPY injection during PLAIN-format dump restore), reached through an independently written defense in a different module (Import/Export Data rather than Restore) that had its own, different logic bug (inverted backslash-escape semantics rather than a BOM-defeated regex anchor). The fix rejects any backslash inside a single-quoted string in the query outright, rather than picking one of the two possible psql interpretations. This is intentionally conservative: because the correct interpretation of \ depends on the target server's standard_conforming_strings setting, which the checker cannot reliably know at validation time, refusing the query is safer than guessing. This issue affects pgAdmin 4: from the introduction of _is_query_parens_balanced() before 9.18.
CVSS v3.1
Score 9.9critical
Affected software
pgadmin.org
pgAdmin 4
Run on your own infrastructure? Check whether these packages are installed with threat-finder — our free open-source scanner.
Weaknesses
AI-Powered Analysis
Machine-generated threat intelligence
Technical Analysis
pgAdmin 4's Import/Export Data tool constructs psql \copy commands by interpolating user SQL queries into a Jinja template and executing them via psql --command. To prevent command injection, a parenthesis-balance checker (_is_query_parens_balanced()) validates queries by assuming backslash escapes a single quote (standard_conforming_strings off). However, PostgreSQL defaults standard_conforming_strings to on since version 9.1, causing psql to treat backslash as a normal character and close string literals differently. This mismatch allows crafted queries like SELECT 'a\') TO PROGRAM 'echo pwned' x to bypass validation and inject arbitrary OS commands executed by psql via popen(). The vulnerability affects pgAdmin 4 versions before 9.18. The fix rejects queries containing backslashes inside single-quoted strings to avoid ambiguity, as the checker cannot reliably determine the server's standard_conforming_strings setting at validation time.
Potential Impact
Successful exploitation allows an attacker with the tools_import_export_data permission to execute arbitrary OS commands on the system running pgAdmin 4, leading to complete compromise of confidentiality, integrity, and availability of the affected system. The vulnerability enables remote code execution via injection of OS commands into psql's TO PROGRAM clause during data import/export operations.
Mitigation Recommendations
Patch status is not yet confirmed — check the vendor advisory for current remediation guidance. The vendor fixed the issue by rejecting any backslash inside single-quoted strings in queries to prevent ambiguous parsing. Until an official fix is available, restrict access to the tools_import_export_data permission and avoid using the Import/Export Data feature with untrusted input. Monitor vendor channels for updates and apply official patches once released.
Technical Details
- Data Version
- 5.2
- Assigner Short Name
- PostgreSQL
- Date Reserved
- 2026-07-27T14:43:12.802Z
- Cvss Version
- 3.1
- State
- PUBLISHED
Threat ID: 6a6cf74ebf32cb7a34294bc7
Added to database: 07/31/2026, 19:28:14 UTC
Last enriched: 07/31/2026, 19:40:50 UTC
Last updated: 09/14/2026, 10:01:29 UTC
Views: 57
Community Reviews
0 reviewsCrowdsource mitigation strategies, share intel context, and vote on the most helpful responses. Sign in to add your voice and help keep defenders ahead.
Want to contribute mitigation steps or threat intel context? Sign in or create an account to join the community discussion.
Actions
Updates to AI analysis require Pro Console access. Upgrade inside Console → Billing.
Need more coverage?
Upgrade to Pro Console for AI refresh and higher limits.
For incident response and remediation, OffSeq services can help resolve threats faster.
Latest Threats
Check if your credentials are on the dark web
Instant breach scanning across billions of leaked records. Free tier available.