Skip to content

Escape output file path in SQL dump shell commands#593

Open
flightlesstux wants to merge 1 commit intopassbolt:masterfrom
flightlesstux:fix/sql-export-shell-escape-output-path
Open

Escape output file path in SQL dump shell commands#593
flightlesstux wants to merge 1 commit intopassbolt:masterfrom
flightlesstux:fix/sql-export-shell-escape-output-path

Conversation

@flightlesstux
Copy link

Problem

mysqlDump(), mariaDbDump(), and postgresDump() in SqlExportCommand all construct a shell command using exec(). Every argument passed to the dump utilities is correctly wrapped with escapeshellarg() — except the output redirection path:

// Before — $dir and $file are unescaped
$cmd .= ' ' . escapeshellarg($config['database']) . ' > ' . $dir . $file;

A path containing shell metacharacters (;, |, &&, backticks) can break out of the redirection context and execute arbitrary shell commands in the context of the web server process.

Fix

Wrap the concatenated output path with escapeshellarg() to match the treatment of all other arguments:

// After
$cmd .= ' ' . escapeshellarg($config['database']) . ' > ' . escapeshellarg($dir . $file);

Applied consistently to all three dump methods: mysqlDump, mariaDbDump, postgresDump.

Impact

  • Eliminates the injection surface in the output path across all supported database backends
  • No functional change when paths contain only safe characters

mysqlDump(), mariaDbDump(), and postgresDump() all passed the
output redirection path ($dir . $file) directly into an exec()
shell command without escaping. Every other argument in the same
commands was already wrapped with escapeshellarg(), leaving only
the output path unprotected.

A path containing shell metacharacters (semicolons, pipes,
backticks, etc.) could be leveraged for command injection. Although
the path is derived from server configuration rather than direct
user input, defence-in-depth requires all shell arguments to be
properly escaped.

Wrap $dir . $file with escapeshellarg() in all three dump methods.
@CLAassistant
Copy link

CLAassistant commented Mar 12, 2026

CLA assistant check
All committers have signed the CLA.

@flightlesstux
Copy link
Author

recheck

@flightlesstux
Copy link
Author

@cla-assistant recheck

@ishanvyas22
Copy link
Member

Hey @flightlesstux, thanks for the PR. We have created an internal ticket to have a look at this (PB-50120).

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