Repository navigation
fix(security): pg_dump without a shell, its password out of argv; the Electron backup path quoted (0.7.12) - #53
Conversation
…t of its arguments; quote the Electron backup path PostgresExporter built pg_dump's command as a shell string, so an output path or connection string holding a quote or $(...) ran a command, and the password showed in the process list. execFile with an argument array now carries each value as one argument, and a URL's password goes in PGPASSWORD. The Electron main adapter's VACUUM INTO left its path's quotes unescaped, so a path with an apostrophe broke every backup. Tests: the invocation's arguments and environment, execFile called without a shell, a hostile path against a real PostgreSQL server writing no stray file, and a backup under an O'Brien folder. Released as 0.7.12.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reached
This review includes 6 billable files and costs up to $1.50.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 19 minutes for your next included review. View limit details
Comment |
Reviewer's GuideThis release removes shell-based pg_dump invocation by passing arguments through execFile and relocating PostgreSQL URL passwords to PGPASSWORD, hardens Electron VACUUM INTO path quoting, and validates both fixes with unit, integration, and end-to-end tests. Sequence diagram for shell-free PostgreSQL exportsequenceDiagram
participant Exporter as PostgresExporter
participant Invocation as pgDumpInvocation
participant Process as pg_dump
Exporter->>Invocation: pgDumpInvocation(connectionString, outputPath)
Invocation-->>Exporter: file, args, env
Exporter->>Process: execFile(file, args, {env})
Note over Process: URL password is in PGPASSWORD, paths remain one argument
Process-->>Exporter: dump output or completion
Sequence diagram for quoted Electron cloud backupsequenceDiagram
participant Adapter as ElectronMainAdapter
participant SQLite as innerAdapter
participant Cloud as backup.provider
Adapter->>Adapter: backupPath.replace(/'/g, "''")
Adapter->>SQLite: exec(VACUUM INTO quoted backupPath)
SQLite-->>Adapter: backup created
Adapter->>Cloud: upload(backupPath, remotePath)
Cloud-->>Adapter: upload complete
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
PR Summary by QodoSecure PostgreSQL exports and fix quoted Electron backup paths
AI Description
Diagram
High-Level Assessment
Files changed (6)
|
Code Review by Qodo
1. URL query passwords remain visible in ps
|
| env.PGPASSWORD = decodeURIComponent(url.password); | ||
| url.password = ''; | ||
| } | ||
| dbname = url.toString(); |
There was a problem hiding this comment.
1. Url query passwords remain visible in ps 🐞 Bug ⛨ Security
pgDumpInvocation removes only url.password, leaving a password query parameter in the URL assigned to dbname. When an exporter receives a connection string such as postgresql://user@host/db?password=secret, both export methods pass that secret in the --dbname process argument.
Agent Prompt
## Issue description
PostgreSQL URLs can supply a password through a `password` query parameter. `pgDumpInvocation` removes only the userinfo password, so a query password remains visible in the `--dbname` argument.
## Fix Focus Areas
- src/exporters/PostgresExporter.ts[21-29]
- tests/postgresExporter.spec.ts[14-31]
## Recommended Fix
Extract a query-supplied password into `PGPASSWORD` and remove that parameter from the URL before constructing `--dbname`. Preserve the effective credential when both query and userinfo passwords are present, and test that neither password appears in the argument array.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 22ff2a0cdb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (url.password !== '') { | ||
| env.PGPASSWORD = decodeURIComponent(url.password); | ||
| url.password = ''; |
There was a problem hiding this comment.
Remove query-string passwords from pg_dump arguments
For a valid libpq URI such as postgresql://user@host/db?password=secret, the password is stored in url.searchParams, not url.password, so this branch leaves it in --dbname and visible in the process list. Because libpq permits connection parameters in the URI query string, extract and remove the password query parameter and pass it through PGPASSWORD as well.
Useful? React with 👍 / 👎.
| const env: NodeJS.ProcessEnv = { ...process.env }; | ||
| let dbname = connectionString; | ||
| if (/^postgres(?:ql)?:\/\//i.test(connectionString)) { | ||
| const url = new URL(connectionString); |
There was a problem hiding this comment.
Preserve valid multi-host PostgreSQL URIs
When an exporter receives a valid multi-host URI with per-host ports, such as postgresql://user:secret@host1:5432,host2:5433/db, this new URL call throws TypeError: Invalid URL before pg_dump starts. libpq explicitly supports comma-separated host/port pairs, and the previous implementation passed these strings through unchanged, so password extraction needs to preserve libpq's broader URI grammar rather than require WHATWG URL parsing.
Useful? React with 👍 / 👎.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Reported by trojanos-7a: PostgresExporter ran
pg_dump "<connection string>" --file="<path>"through execSync, so exportToFile('/tmp/x"; touch /tmp/pwned; echo "') ran touch, and a connection string holding a quote or $(...) did the same; the password showed in ps while pg_dump ran.Summary by Sourcery
Harden PostgreSQL exports and Electron cloud backups against unsafe or quoted file and connection paths.
Bug Fixes:
pg_dumpwithout a shell and keeping URL passwords out of process arguments.VACUUM INTOsucceeds for paths containing quotes.Enhancements:
Tests:
Chores: