Skip to content

Use sslrootcert, sslcert and sslkey from a url instead of sending them to the server - #1308

Merged
porsager merged 2 commits into
porsager:masterfrom
efeesrefinal:fix/sslrootcert-url
Nov 5, 2026
Merged

porsager merged 2 commits into
porsager:masterfrom
efeesrefinal:fix/sslrootcert-url

Conversation

@efeesrefinal

@efeesrefinal efeesrefinal commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

?sslrootcert=system is documented in the README, but on PostgreSQL it fails with unrecognized configuration parameter "sslrootcert", as every query parameter that isn't an option is sent as a startup parameter. ?sslrootcert=/path/to/ca.pem fails the same way, while the same settings work in psql.

The three parameters are no longer sent. system works as documented, and files are read into ca, cert and key. As in libpq, a root certificate with require or verify-ca checks the CA but not the host name, and verify-full or ssl: true checks both. With a file and no sslmode I use require, so a CA given in the url doesn't end in a plain connection, which is stricter than libpq's prefer. sslmode=disable still wins.

Tested on PostgreSQL 15 and Node 22 for system, verify-full, verify-ca, require, no sslmode, disable and a wrong CA, which is rejected. I tested sslcert and sslkey only as parsing, not against a server that asks for a client certificate. Unit tests pass, including four new ones. I did not run the integration suite.

@porsager

porsager commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Thanks Efe, this matches libpq nicely: a CA with require/verify-ca checks the CA, verify-full also checks the host name, and a wrong CA is rejected.

One thing: with ssl: true in the options and ?sslrootcert= in the url, the host name check is dropped, though ssl: true alone verifies fully. Could true be treated like 'verify-full'?

: ssl === true || ssl === 'verify-full' ? files

@efeesrefinal

Copy link
Copy Markdown
Contributor Author

Done, with a test and a changelog entry. ?ssl=true in the url had the same problem, as it arrives as the string 'true', so I covered that too. On PostgreSQL 15, with a certificate for another host, ssl: true and ?ssl=true were both accepted before this change and now fail with ERR_TLS_CERT_ALTNAME_INVALID. A wrong CA is still rejected.

@efeesrefinal efeesrefinal mentioned this pull request Nov 5, 2026
@porsager

porsager commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Thanks !

@porsager
porsager merged commit 4ffacc8 into porsager:master Nov 5, 2026
105 of 111 checks passed
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.

2 participants