Skip to content

fix(server): hide database password from backup process arguments - #30757

Open
NoiceHax wants to merge 1 commit into
immich-app:mainfrom
NoiceHax:fix/issue-30333
Open

fix(server): hide database password from backup process arguments#30757
NoiceHax wants to merge 1 commit into
immich-app:mainfrom
NoiceHax:fix/issue-30333

Conversation

@NoiceHax

@NoiceHax NoiceHax commented Aug 14, 2026

Copy link
Copy Markdown

Description

When DB_URL is set, the whole connection string was passed to pg_dump and psql as a plain argument, so the password in it showed up in ps for anyone able to list processes. The password was already going through PGPASSWORD as well, so the copy in the arguments was not needed.

Now the password is taken out of the URL before it becomes an argument, both the user:pass part and a ?password= query parameter, and only PGPASSWORD carries it. URL gives the userinfo password back percent-encoded, so it is decoded first because libpq wants the raw value.

Fixes #30333

How Has This Been Tested?

Two new unit tests in server/src/services/database-backup.service.spec.ts. One checks pg_dump is spawned with a password-free URL and PGPASSWORD set to the decoded password. The other checks the password query parameter is stripped. Three existing inline snapshots changed because the URL no longer carries the password. Both new tests fail on main.

Checklist:

  • I have carefully read CONTRIBUTING.md
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if applicable
  • I have no unrelated changes in the PR.
  • I have confirmed that any new dependencies are strictly necessary.
  • I have written tests for new code (if applicable)
  • I have followed naming conventions/patterns in the surrounding code
  • All code in src/services/ uses repositories implementations for database calls, filesystem operations, etc.
  • All code in src/repositories/ is pretty basic/simple and does not have any immich specific logic (that belongs in src/services/)

Please describe to which degree, if any, an LLM was used in creating this pull request.

This code was written alongside AI. The change and its tests were reviewed against the behaviour described in the linked issue before opening, and I am happy to walk through the reasoning or rework any part of it.

When `DB_URL` is used, the connection string was forwarded verbatim to the
spawned `pg_dump`/`psql` processes, so the password contained in it was
readable by anyone able to list processes. The credentials are now stripped
from the URL (both the userinfo section and the `password` parameter) and only
handed over through `PGPASSWORD`, which is already being set. The value is
percent-decoded first, since libpq expects the raw password in the environment
variable.

Closes immich-app#30333
@immich-push-o-matic

immich-push-o-matic Bot commented Aug 14, 2026

Copy link
Copy Markdown

Label error. Requires exactly 1 of: changelog:.*. Found: 🗄️server, auto-closed:template. A maintainer will add the required label.

@github-actions

Copy link
Copy Markdown
Contributor

This PR has been automatically closed as the description doesn't follow our template. After you edit it to match the template, the PR will automatically be reopened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DB backup job passes password in the open to the spawned process if DB_URL is used

1 participant