jackc / jackc/pgx

Sensitive Password Exposure in Error Message

Open
#2,217 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
14.3k
Forks
1.1k
Avg merge
6d 9h
Merged PRs (30d)
11

Description

**Describe the bug**

When using `pgx.Connect` with the connection string format `"host=%s port=%s user=%s password=%s dbname=%s"`, if the `user` field is left empty, the `password` field is mistakenly interpreted as the `user`. This leads to the following error:
`failed to connect to 'user=password=**** database=***': ****: failed SASL auth: FATAL: password authentication failed for user "password=****" (SQLSTATE 28P01)`

In this case, the `password` is displayed in plain text, which constitutes an unacceptable information disclosure from a security perspective.

**To Reproduce**

Steps to reproduce the behavior:
1. Use the following connection string format: `"host=%s port=%s user=%s password=%s dbname=%s"`.
2. Leave the `user` field empty, and set a valid `password`.
3. Attempt to connect using `pgx.Connect`.

Example code:
```go
package main

import (
"context"
"log"
"os"

"github.com/jackc/pgx/v5"
)

func main() {
connString := "host=localhost port=5432 user= password=secret dbname=mydb"
conn, err := pgx.Connect(context.Background(), connString)
if err != nil {
log.Fatal(err)
}
defer conn.Close(context.Background())
}
```

**Expected behavior**

The connection attempt should fail with a clear error indicating that the user field is empty, without exposing the password in the error message.

**Actual behavior**

The password field is mistakenly interpreted as the user, resulting in an error that exposes the password in plain text:
failed to connect to 'user=password=**** database=***': ****: failed SASL auth: FATAL: password authentication failed for user "password=****"

Contributor guide

Open the contributing guide

Research direction

Start at the pgx.Connect entry point and reproduce the issue with an empty user and a password in the connection string. Trace how the connection string is interpreted and how the connection error is rendered; done means the attempt reports an empty user without exposing the password.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
authentication, database, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.