Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

loopdb: postgres password with URL-reserved characters breaks the connection

Aperta Adatta ai principianti
#1,246 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 7 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go, postgres
Ambito
databases

Direzione di ricerca

Inizia da PostgresConfig.DSN e verifica come viene assemblato e registrato l’attuale DSN. Aggiungi la copertura richiesta basata su tabella per le password contenenti caratteri riservati dagli URL, incluso il parsing del risultato con net/url, ed esegui i test Go pertinenti. Il lavoro è completato quando l’utente, la password, l’host e il database analizzati rimangono invariati, inclusa la gestione degli host IPv6.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Title: loopdb: postgres password with URL-reserved characters breaks the connection

Background

PostgresConfig.DSN builds the connection string with fmt.Sprintf, putting the user and password into the URL without escaping them:

dsnTemplate = "postgres://%v:%v@%v:%d/%v?sslmode=%v"

pgx parses this string with net/url, so any URL-reserved character in the password changes how the URL is parsed. For example, / ends the authority section early, so with --postgres.password=ab/cd the string becomes:

postgres://loop:ab/cd@localhost:5432/loop?sslmode=disable

This parses as host loop:ab and path /cd@localhost:5432/loop, so loopd fails to connect. #, ? and % cause similar failures.

Passwords made with common tools such as openssl rand -base64 often contain /. #1088 adds a way to read the password from a file, which encourages exactly this kind of generated password, so this is likely to come up more often.

Proposed fix

Build the DSN with net/url so each part is escaped correctly:

dsn := url.URL{
	Scheme:   "postgres",
	User:     url.UserPassword(s.User, password),
	Host:     net.JoinHostPort(s.Host, strconv.Itoa(s.Port)),
	Path:     s.DBName,
	RawQuery: url.Values{"sslmode": {sslMode}}.Encode(),
}

net.JoinHostPort also brackets IPv6 host literals correctly, which the current template doesn't do. The hidePassword placeholder used when logging stays as it is.

Add a table-driven test for DSN that runs passwords containing /, @, :, #, ?, % and spaces through url.Parse and checks that the user, password, host and database come back unchanged.

Lingua principale
Go
Stelle
593
Fork
138
Merge medio
4g 9h
PR unite (30g)
14

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di lightninglabs/loop

Tutte le issue di lightninglabs/loop

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.