File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,7 +32,10 @@ import {
3232 tryReadStart ,
3333} from 'node-internal:internal_net' ;
3434import { JSStreamSocket } from 'node-internal:internal_tls_jsstream' ;
35- import { checkServerIdentity } from 'node-internal:internal_tls' ;
35+ import {
36+ checkServerIdentity ,
37+ convertALPNProtocols ,
38+ } from 'node-internal:internal_tls' ;
3639import type {
3740 ConnectionOptions ,
3841 TlsOptions ,
@@ -194,8 +197,12 @@ export function TLSSocket(
194197 }
195198
196199 if ( tlsOptions . ALPNProtocols !== undefined ) {
197- // Does not apply to Cloudflare Workers.
198- throw new ERR_OPTION_NOT_IMPLEMENTED ( 'options.ALPNProtocols' ) ;
200+ // connect()/startTls() does not expose ALPN selection yet.
201+ // Undici's buildConnector always passes ALPNProtocols for TLS connections,
202+ // so rejecting it breaks clients like @elastic /elasticsearch. Accept the
203+ // option and preserve Node.js input validation behavior.
204+ const normalizedAlpn = { ALPNProtocols : Buffer . alloc ( 0 ) } ;
205+ convertALPNProtocols ( tlsOptions . ALPNProtocols , normalizedAlpn ) ;
199206 }
200207
201208 if ( tlsOptions . SNICallback !== undefined ) {
Original file line number Diff line number Diff line change @@ -753,6 +753,34 @@ export const testConvertALPNProtocols = {
753753 } ,
754754} ;
755755
756+ export const testConnectAcceptsAlpnProtocols = {
757+ async test ( _ctrl , env ) {
758+ const socket = tls . connect ( {
759+ port : env . ECHO_SERVER_PORT ,
760+ ALPNProtocols : [ 'http/1.1' ] ,
761+ } ) ;
762+
763+ await once ( socket , 'secureConnect' ) ;
764+ socket . destroy ( ) ;
765+ } ,
766+ } ;
767+
768+ export const testConnectRejectsInvalidAlpnProtocolLength = {
769+ async test ( ) {
770+ throws (
771+ ( ) =>
772+ tls . connect ( {
773+ port : 42 ,
774+ lookup ( ) { } ,
775+ ALPNProtocols : [ new String ( 'a' ) . repeat ( 500 ) ] ,
776+ } ) ,
777+ {
778+ code : 'ERR_OUT_OF_RANGE' ,
779+ }
780+ ) ;
781+ } ,
782+ } ;
783+
756784export const testStartTlsBehaviorOnUpgrade = {
757785 async test ( ctrl , env ) {
758786 const { promise, resolve, reject } = Promise . withResolvers ( ) ;
You can’t perform that action at this time.
0 commit comments