Skip to content

tls: preserve servername on resumed sessions#62067

Open
jorgitin02 wants to merge 1 commit intonodejs:mainfrom
jorgitin02:fix/57175-tls-session-servername
Open

tls: preserve servername on resumed sessions#62067
jorgitin02 wants to merge 1 commit intonodejs:mainfrom
jorgitin02:fix/57175-tls-session-servername

Conversation

@jorgitin02
Copy link

Summary

  • Persist SNI on server sessions and ticket appdata so resumed handshakes retain the original hostname.
  • Add session-id-based fallback lookup in the TLS servername getter when OpenSSL reports no SNI on resumed sessions.
  • Keep behavior validated by a focused Reusing TLS sessions causes to socket.servername being false with Repro #57175 verification suite and existing TLS session/SNI regression tests.

Fixes: #57175

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/crypto
  • @nodejs/security-wg

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Mar 1, 2026
Copy link
Member

@anonrig anonrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't land without a single test.

OpenSSL's SSL_get_servername() returns NULL on server-side TLS 1.3
resumed sessions because it reads from ssl->ext.hostname (not populated
on resumption) rather than session->ext.hostname (which is persisted).

The root cause is that Node.js's SNI callback (SelectSNIContextCallback)
returns SSL_TLSEXT_ERR_NOACK when no SNI context switch is needed, which
prevents OpenSSL from storing the hostname in the session. Without the
hostname in the session, SSL_SESSION_get0_hostname() also returns NULL.

Fix this with two minimal changes:

1. In SelectSNIContextCallback, explicitly call SSL_SESSION_set1_hostname()
   to persist the SNI in the session before ticket serialization.

2. In ncrypto::GetServerName(), fall back to SSL_SESSION_get0_hostname()
   when SSL_get_servername() returns NULL.

Fixes: nodejs#59202

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jorgitin02 jorgitin02 force-pushed the fix/57175-tls-session-servername branch from a9cecb6 to 5487a28 Compare March 2, 2026 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reusing TLS sessions causes to socket.servername being false with Repro

3 participants