Skip to content

fix: redact full password when it contains @ sign#785

Open
Yanhu007 wants to merge 1 commit into
amacneil:mainfrom
Yanhu007:fix/redact-password-with-at-sign
Open

fix: redact full password when it contains @ sign#785
Yanhu007 wants to merge 1 commit into
amacneil:mainfrom
Yanhu007:fix/redact-password-with-at-sign

Conversation

@Yanhu007
Copy link
Copy Markdown

Fixes #784

Problem

redactLogString uses [^@]+ to match the password portion, stopping at the first @. When a password contains @ (e.g. pass@word), only the part before the first @ is redacted, leaking the rest in error messages:

Input:  postgres://user:oRAND44@leaked_part@host:5432/db
Output: postgres://user:********@leaked_part@host:5432/db  ← password leaked!

Fix

Change [^@]+ to .+ (greedy) so the regex matches everything up to the last @, redacting the entire password:

Output: postgres://user:********@host:5432/db  ← fully redacted

Added test case for passwords containing @.

The redactLogString regex uses [^@]+ to match the password,
which stops at the first @ character. If the password contains
an @ (e.g. 'pass@word'), only the part before the first @ is
redacted, leaking the rest of the password in error messages.

Use .+ (greedy) instead to match everything up to the LAST @,
ensuring the entire password is redacted regardless of content.

Add test case for password containing @ sign.

Fixes amacneil#784
@sofuture
Copy link
Copy Markdown
Collaborator

Will this overmatch if there are @ later in the connection string for some reason? i.e. postgresql://user:password@host:5432/mydb?foo=b@r

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DBmate prints password if unable to parse string

2 participants