[HIGH] [UPD-1] BackupService Creates Backup Directory and Files with World-Readable Permissions
Audit Finding: UPD-1
- Severity:
HIGH - Category: Update
- File:
/home/z/my-project/ownpay/src/Update/BackupService.php:73,79,216
Description
createFullBackup() calls @mkdir($backupPath, 0755, true) (line 73) — the backup directory is world-readable/executable. Inside it, dumpDatabase() writes database.sql via either mysqldump > $outputPath (line 167, inherits umask, typically 0644) or file_put_contents($outputPath, $sql) (line 216, also umask-based, typically 0644). The manifest.json (line 79) is likewise world-readable. The database dump contains every row of every table: merchant PII, user password hashes, API key hashes, encrypted credentials, webhook secrets, and audit logs. The backup directory is under storage/backups/ which is outside public/ (so not directly web-accessible), but on shared hosting or any multi-tenant server, every other system user can read the dump.
Impact
Any co-located user on the server (e.g., another tenant on a shared VPS, a low-privilege service account compromised via a different vector) can read the full database dump and extract all credentials. The database.sql file is the single highest-value asset on the filesystem.
Reproduction
sudo -u www-data php -r "require 'vendor/autoload.php'; (new \OwnPay\Update\BackupService())->createFullBackup();"
ls -la storage/backups/backup_*/
# -rw-r--r-- www-data www-data database.sql <-- world-readable
# As another user:
cat /var/www/ownpay/storage/backups/backup_*/database.sql | grep password_hash
Recommended Fix
Create the backup directory with 0700 permissions. After writing database.sql and manifest.json, explicitly chmod($file, 0600). For the code.zip, chmod($outputPath, 0600). If the backup must be group-accessible, use 0750/0640 and ensure the group is a trusted backup group, not the default web-server group.
Discovered during comprehensive codebase audit. See /home/z/my-project/worklog.md for full audit context.
Duplicate Issue — Closed
This issue is a duplicate of #378 (same audit finding UPD-1 — both issues share the same title, file path, and description).
The fix has been implemented and is ready for review in PR #521: https://github.com/own-pay/OwnPay/pull/521
Tracking will continue under the canonical issue #378, which is referenced by the PR's Closes #378 line and will be auto-closed when the PR merges.
Closing this duplicate as not_planned to keep the audit tracker clean.
Duplicate Issue — Closed
This issue is a duplicate of #378 (same audit finding UPD-1 — both issues share the same title, file path, and description).
The fix has been implemented and is ready for review in PR #521: https://github.com/own-pay/OwnPay/pull/521
Tracking will continue under the canonical issue #378, which is referenced by the PR's Closes #378 line and will be auto-closed when the PR merges.
Closing this duplicate as not_planned to keep the audit tracker clean.
Duplicate Issue — Closed
This issue is a duplicate of #378 (same audit finding UPD-1 — both issues share the same title, file path, and description).
The fix has been implemented and is ready for review in PR #521: https://github.com/own-pay/OwnPay/pull/521
Tracking will continue under the canonical issue #378, which is referenced by the PR's Closes #378 line and will be auto-closed when the PR merges.
Closing this duplicate as not_planned to keep the audit tracker clean.