@@ -28,9 +28,19 @@ const getSNIPrefixParts = (servername: string, rootDomain: string) => {
2828 const serverNamePrefix = servername . endsWith ( rootDomain )
2929 ? servername . slice ( 0 , - rootDomain . length - 1 )
3030 : servername ;
31+
32+ if ( serverNamePrefix === '' ) return [ ] ;
3133 return serverNamePrefix . split ( '.' ) ;
3234} ;
3335
36+ const VALID_SNI_PARTS = new Set ( [
37+ ...Object . keys ( SNI_PROTOCOL_FILTERS ) ,
38+ 'no-tls' ,
39+ 'example'
40+ ] ) ;
41+
42+ const MAX_SNI_PARTS = 3 ;
43+
3444const PROACTIVE_DOMAIN_REFRESH_INTERVAL = 1000 * 60 * 60 * 24 ; // Daily cert check for proactive domains
3545
3646function proactivelyRefreshDomains ( domains : string [ ] , certGenerator : CertGenerator ) {
@@ -73,6 +83,15 @@ export async function createTlsHandler(
7383 } ,
7484 SNICallback : ( domain : string , cb : Function ) => {
7585 const serverNameParts = getSNIPrefixParts ( domain , tlsConfig . rootDomain ) ;
86+
87+ if ( serverNameParts . length > MAX_SNI_PARTS ) {
88+ return cb ( new Error ( `Too many SNI parts (${ serverNameParts . length } )` ) , null ) ;
89+ }
90+
91+ if ( serverNameParts . some ( part => ! VALID_SNI_PARTS . has ( part ) ) ) {
92+ return cb ( new Error ( `Invalid SNI part in '${ domain } '` ) , null ) ;
93+ }
94+
7695 if ( serverNameParts . includes ( 'no-tls' ) ) {
7796 // This closes the unwanted TLS connection without response
7897 return cb ( new Error ( 'Intentionally rejecting TLS connection' ) , null ) ;
0 commit comments