Skip to content

Verify the server certificate against an IP host instead of localhost - #1309

Merged
porsager merged 1 commit into
porsager:masterfrom
efeesrefinal:fix/tls-ip-host
Nov 5, 2026
Merged

porsager merged 1 commit into
porsager:masterfrom
efeesrefinal:fix/tls-ip-host

Conversation

@efeesrefinal

Copy link
Copy Markdown
Contributor

With ssl: 'verify-full' (or ssl: true) and an IP as the host, the certificate is checked against localhost. upgrade passes no host to tls.connect and leaves servername empty for an IP. Node then falls back to socket._host, which it only sets after a DNS lookup, and ends at 'localhost'.

On PostgreSQL 15 and Node 22, connecting to 127.0.0.1:

Certificate master With the fix
DNS:localhost only accepted rejected, ERR_TLS_CERT_ALTNAME_INVALID
IP:127.0.0.1 rejected, Host: localhost accepted

So a certificate for localhost from a trusted CA passes for any IP, and a correct certificate for the IP fails. Direct TLS is not affected, as it passes host.

Added a unit test to tests/unit/socket.js and a changelog entry. The test fails without the change, and the unit tests pass with it. I did not run the integration suite.

@porsager

porsager commented Nov 5, 2026

Copy link
Copy Markdown
Owner

🎉

@porsager
porsager merged commit 45b226f into porsager:master Nov 5, 2026
65 of 74 checks passed
ivan added a commit to ludios/postgres that referenced this pull request Nov 14, 2026
… lacks

- "Every option is checked" was false: only the numbers, the on-or-off
  options, ssl, sslnegotiation and target_session_attrs are, and a
  misspelt option name is ignored.
- Upstream's idle_timeout of 30 days does not close a connection: it
  starts a timer every millisecond. Only max_lifetime closes at once.
  This fork cuts such a timeout to 24.8 days, which the text now says.
- Upstream is not without output or hooks: it prints notices and
  replication errors, and has the same tracing channels.
- "Its API is upstream's apart from what this section lists" promised
  a complete list. The lists now say that they are not complete, and
  the second one has the fixes that upstream made after the fork point
  (porsager#1309, porsager#1304, porsager#1321, porsager#1320, the daylight saving gap), the settings
  that only upstream accepts, the looser types, `json` on a transform
  and the deleted test runners.
- The sql.listen, COPY and names bullets say what happens, instead of
  only naming the situations.

Model-output: Claude Mythos 5.2

Session-file: ~/.claude/projects/-home-at-code-js-postgres/626cf68e-b4b7-407c-8737-9fe2b26565d7.jsonl

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
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