jackc / jackc/pgx

Sensitive connection string information part of parse error

Open
#1,271 5 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
14.3k
Forks
1.1k
Avg merge
6d 9h
Merged PRs (30d)
11

Description

The error `pgconn.parseConfigError` returned from `pgconn.ParseConfig` includes the full connection string in plain text (including the provided password).
Sensitive information, like the password, should not be visible in plaintext.

## Example:
```go
connString := "postgresql://postgres:Hello121\\@127.0.0.1:5432/postgres"
_, err := pgconn.ParseConfig(connString)
fmt.Println(err.Error())
```

Result:
```text
cannot parse `postgresql://postgres:xxxxxx@127.0.0.1:5432/postgres`: failed to parse as URL (parse "postgresql://postgres:Hello121\\@127.0.0.1:5432/postgres": net/url: invalid userinfo)
```

The above described incident can easily happen, if one passes the connection string via an environment variable with a password that is not url encoded.

As matter of effect, if the returned error gets logged in a production environment, the connection string, including the provided password, gets stored in the logging backend.

e.g.:
```shell
POSTGRES_PASSWORD='not_\_url_/encoded_|password'
/my-service --conn-string "postgresql://postgres:${POSTGRES_PASSWORD}@127.0.0.1:5432/postgres"
```

Contributor guide

Open the contributing guide

Research direction

Start at pgconn.ParseConfig and follow how pgconn.parseConfigError formats failures from invalid connection strings. Reproduce the example and verify that parse errors no longer expose the supplied password or full connection string, including the environment-variable case.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.