mirror of
https://github.com/tiennm99/coolify.git
synced 2026-04-17 23:20:43 +00:00
fix: enhance security by validating and escaping database names, file paths, and proxy configuration filenames to prevent command injection
This commit is contained in:
83
tests/Unit/DatabaseBackupSecurityTest.php
Normal file
83
tests/Unit/DatabaseBackupSecurityTest.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Database Backup Security Tests
|
||||
*
|
||||
* Tests to ensure database backup functionality is protected against
|
||||
* command injection attacks via malicious database names.
|
||||
*
|
||||
* Related Issues: #2 in security_issues.md
|
||||
* Related Files: app/Jobs/DatabaseBackupJob.php, app/Livewire/Project/Database/BackupEdit.php
|
||||
*/
|
||||
test('database backup rejects command injection in database name with command substitution', function () {
|
||||
expect(fn () => validateShellSafePath('test$(whoami)', 'database name'))
|
||||
->toThrow(Exception::class);
|
||||
});
|
||||
|
||||
test('database backup rejects command injection with semicolon separator', function () {
|
||||
expect(fn () => validateShellSafePath('test; rm -rf /', 'database name'))
|
||||
->toThrow(Exception::class);
|
||||
});
|
||||
|
||||
test('database backup rejects command injection with pipe operator', function () {
|
||||
expect(fn () => validateShellSafePath('test | cat /etc/passwd', 'database name'))
|
||||
->toThrow(Exception::class);
|
||||
});
|
||||
|
||||
test('database backup rejects command injection with backticks', function () {
|
||||
expect(fn () => validateShellSafePath('test`whoami`', 'database name'))
|
||||
->toThrow(Exception::class);
|
||||
});
|
||||
|
||||
test('database backup rejects command injection with ampersand', function () {
|
||||
expect(fn () => validateShellSafePath('test & whoami', 'database name'))
|
||||
->toThrow(Exception::class);
|
||||
});
|
||||
|
||||
test('database backup rejects command injection with redirect operators', function () {
|
||||
expect(fn () => validateShellSafePath('test > /tmp/pwned', 'database name'))
|
||||
->toThrow(Exception::class);
|
||||
|
||||
expect(fn () => validateShellSafePath('test < /etc/passwd', 'database name'))
|
||||
->toThrow(Exception::class);
|
||||
});
|
||||
|
||||
test('database backup rejects command injection with newlines', function () {
|
||||
expect(fn () => validateShellSafePath("test\nrm -rf /", 'database name'))
|
||||
->toThrow(Exception::class);
|
||||
});
|
||||
|
||||
test('database backup escapes shell arguments properly', function () {
|
||||
$database = "test'db";
|
||||
$escaped = escapeshellarg($database);
|
||||
|
||||
expect($escaped)->toBe("'test'\\''db'");
|
||||
});
|
||||
|
||||
test('database backup escapes shell arguments with double quotes', function () {
|
||||
$database = 'test"db';
|
||||
$escaped = escapeshellarg($database);
|
||||
|
||||
expect($escaped)->toBe("'test\"db'");
|
||||
});
|
||||
|
||||
test('database backup escapes shell arguments with spaces', function () {
|
||||
$database = 'test database';
|
||||
$escaped = escapeshellarg($database);
|
||||
|
||||
expect($escaped)->toBe("'test database'");
|
||||
});
|
||||
|
||||
test('database backup accepts legitimate database names', function () {
|
||||
expect(fn () => validateShellSafePath('postgres', 'database name'))
|
||||
->not->toThrow(Exception::class);
|
||||
|
||||
expect(fn () => validateShellSafePath('my_database', 'database name'))
|
||||
->not->toThrow(Exception::class);
|
||||
|
||||
expect(fn () => validateShellSafePath('db-prod', 'database name'))
|
||||
->not->toThrow(Exception::class);
|
||||
|
||||
expect(fn () => validateShellSafePath('test123', 'database name'))
|
||||
->not->toThrow(Exception::class);
|
||||
});
|
||||
Reference in New Issue
Block a user