Skip to content

fix(database): tighten Postgres init script filename handling - #9681

Merged
andrasbacsai merged 1 commit into
nextfrom
fix/postgres-init-script-hardening
Apr 20, 2026
Merged

andrasbacsai merged 1 commit into
nextfrom
fix/postgres-init-script-hardening

Conversation

@andrasbacsai

Copy link
Copy Markdown
Member

Summary

  • Add validateFilenameSafe() helper in bootstrap/helpers/shared.php that rejects directory separators, traversal sequences, null bytes, glob/tilde/quote chars, and inherits all shell-metachar checks from validateShellSafePath().
  • Use the new helper when accepting new or renamed Postgres init script filenames in app/Livewire/Project/Database/Postgresql/General.php.
  • At the write/delete sites (StartPostgresql::generate_init_scripts() and the Livewire delete path) normalise legacy values with basename() + escapeshellarg() instead of hard-validating, so previously saved rows keep deploying and operators can still clean them up.
  • Add unit tests for the helper and extend the Postgres init-script regression suite.

Test plan

  • php artisan test --compact --filter=ValidateFilenameSafe
  • php artisan test --compact --filter=PostgresqlInitScriptSecurityTest
  • Create a Postgres database in dev, add an init script with a plain filename (e.g. init.sql) and deploy — file lands in docker-entrypoint-initdb.d/ and the DB boots.
  • Try renaming the script to a filename containing /, .., *, or a space — Livewire surfaces the validation error.
  • With a legacy row that has an unsafe filename, confirm the database still starts (values sanitised at write time) and that the row can be deleted from the UI.

🤖 Generated with Claude Code

Validate new init-script filenames against path traversal and shell
metacharacters via a new validateFilenameSafe() helper, and harden the
write/delete paths with basename() + escapeshellarg() so legacy rows
still deploy and can be cleaned up without regressions.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@andrasbacsai
andrasbacsai merged commit 1cf6c7d into next Apr 20, 2026
4 checks passed
@andrasbacsai
andrasbacsai deleted the fix/postgres-init-script-hardening branch April 20, 2026 19:27
@andrasbacsai andrasbacsai mentioned this pull request Apr 21, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant