GeezerVison is showing github.com — https: encode all TLS fields in agent names by ShogunPanda · Pull Request #67641 · nodejs/node
https: encode all TLS fields in agent names
#67641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.js
(3)
All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
https: encode all TLS fields in agent names
`https.Agent#getName()` joined several TLS options with `:` without
encoding them, so a value containing `:` could shift into the next field
and produce the same name as a different set of options. A `DataView`
passed as `dhparam` was also reduced to its type name.
Encode the remaining string, boolean, number, buffer and array valued
options, including `sigalgs`, with `getTlsOptionKey()`, which prefixes
the type and the length, like the options that were already encoded.
Assisted-By: OpenAI GPT-5.6 Sol <openai/gpt-5.6-sol>
Signed-off-by: Paolo Insogna <[email protected] >
Loading branch information
Uh oh!
There was an error while loading. Please reload this page.
commit dde5f87c8d066648bf8f24558c6e3dae1de68516
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -30,7 +30,6 @@ const {
ArrayPrototypeSplice,
ArrayPrototypeUnshift,
FunctionPrototypeCall,
JSONStringify,
NumberParseInt,
ObjectAssign,
ObjectSetPrototypeOf,
Expand Down
Expand Up
@@ -606,7 +605,7 @@ Agent.prototype.getName = function getName(options = kEmptyObject) {
name += ':' ;
if ( options . ciphers )
name += options . ciphers ;
name += getTlsOptionKey ( options . ciphers ) ;
name += ':' ;
if ( options . key ) {
Expand All
@@ -622,51 +621,51 @@ Agent.prototype.getName = function getName(options = kEmptyObject) {
name += ':' ;
if ( options . rejectUnauthorized !== undefined )
name += options . rejectUnauthorized ;
name += getTlsOptionKey ( options . rejectUnauthorized ) ;
name += ':' ;
if ( options . servername && options . servername !== options . host )
name += options . servername ;
name += getTlsOptionKey ( options . servername ) ;
name += ':' ;
if ( options . minVersion )
name += options . minVersion ;
name += getTlsOptionKey ( options . minVersion ) ;
name += ':' ;
if ( options . maxVersion )
name += options . maxVersion ;
name += getTlsOptionKey ( options . maxVersion ) ;
name += ':' ;
if ( options . secureProtocol )
name += options . secureProtocol ;
name += getTlsOptionKey ( options . secureProtocol ) ;
name += ':' ;
if ( options . crl )
name += getTlsOptionKey ( options . crl ) ;
name += ':' ;
if ( options . honorCipherOrder !== undefined )
name += options . honorCipherOrder ;
name += getTlsOptionKey ( options . honorCipherOrder ) ;
name += ':' ;
if ( options . ecdhCurve )
name += options . ecdhCurve ;
name += getTlsOptionKey ( options . ecdhCurve ) ;
name += ':' ;
if ( options . dhparam )
name += options . dhparam ;
name += getTlsOptionKey ( options . dhparam ) ;
name += ':' ;
if ( options . secureOptions !== undefined )
name += options . secureOptions ;
name += getTlsOptionKey ( options . secureOptions ) ;
name += ':' ;
if ( options . sessionIdContext )
name += options . sessionIdContext ;
name += getTlsOptionKey ( options . sessionIdContext ) ;
name += ':' ;
if ( options . sigalgs )
name += JSONStringify ( options . sigalgs ) ;
name += getTlsOptionKey ( options . sigalgs ) ;
name += ':' ;
if ( options . secureContext )
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -56,30 +56,29 @@ const updatedValues = new Map([
[ 'sessionIdContext' , 'sessionIdContext' ] ,
] ) ;
let value ;
// Every variation must be pooled under its own name, and repeating a
// variation must reuse the name it had.
const requested = new Set ( ) ;
let expectedNames = 1 ;
function variations ( iter , port , cb ) {
return common . mustCall ( ( res ) => {
res . resume ( ) ;
https . globalAgent . once ( 'free' , common . mustCall ( ( ) => {
// Verify that the most recent connection is in the freeSockets pool.
// Verify that the connections are in the freeSockets pool, one name for
// each distinct set of options.
const keys = Object . keys ( https . globalAgent . freeSockets ) ;
if ( value ) {
assert . ok (
keys . some ( ( val ) => val . startsWith ( value . toString ( ) + ':' ) ||
val . endsWith ( ':' + value . toString ( ) ) ||
val . includes ( ':' + value . toString ( ) + ':' ) ) ,
`missing value: ${ value . toString ( ) } in ${ keys } `
) ;
}
assert . strictEqual ( keys . length , expectedNames , `unexpected ${ keys } ` ) ;
const next = iter . next ( ) ;
if ( next . done ) {
https . globalAgent . destroy ( ) ;
server . close ( ) ;
} else {
// Save `value` for check the next time.
const [ key , val ] = next . value ;
value = val ;
if ( ! requested . has ( key ) ) {
requested . add ( key ) ;
expectedNames ++ ;
}
https . get ( { ...getBaseOptions ( port ) , [ key ] : val } ,
variations ( iter , port , cb ) ) ;
}
Expand All
@@ -90,5 +89,7 @@ function variations(iter, port, cb) {
server . listen ( 0 , common . mustCall ( ( ) => {
const port = server . address ( ) . port ;
https . globalAgent . keepAlive = true ;
https . get ( getBaseOptions ( port ) , variations ( updatedValues . entries ( ) , port ) ) ;
const all = [ ...updatedValues . entries ( ) ] ;
const entries = [ ...all , all [ 0 ] ] ;
https . get ( getBaseOptions ( port ) , variations ( entries . values ( ) , port ) ) ;
} ) ) ;
Original file line number
Diff line number
Diff line change
Expand Up
@@ -47,10 +47,10 @@ const options = {
assert . strictEqual (
agent . getName ( options ) ,
'0.0.0.0:443:192.168.1.1:s2:ca:s4:cert:ciphers:s3:key::' +
's3:pfx::false:localhost:::secureProtocol:' +
'a3:7:v1:Yw==:7:v1:cg==:7:v1:bA==:false:ecdhCurve:dhparam:0 :' +
'sessionIdContext:" sigalgs" :::::::::'
'0.0.0.0:443:192.168.1.1:s2:ca:s4:cert:s7: ciphers:s3:key::' +
's3:pfx::b5: false:s9: localhost:::s14 :secureProtocol:' +
'a3:7:v1:Yw==:7:v1:cg==:7:v1:bA==:b5: false:s9: ecdhCurve:s7:dhparam :' +
'n1:0:s16: sessionIdContext:s7: sigalgs:::::::::'
) ;
{
Expand Down
Expand Up
@@ -156,4 +156,43 @@ assert.strictEqual(
agent . getName ( { ...baseOptions , session : Buffer . from ( 'one' ) } ) ,
agent . getName ( { ...baseOptions , session : Buffer . from ( 'two' ) } )
) ;
// Values containing the field delimiter must not shift across fields.
const collisions = [
[ { servername : 'a:b' } , { servername : 'a' , minVersion : 'b:' } ] ,
[ { minVersion : 'a:b' } , { minVersion : 'a' , maxVersion : 'b:' } ] ,
[ { maxVersion : 'a:b' } , { maxVersion : 'a' , secureProtocol : 'b:' } ] ,
[ { rejectUnauthorized : 'false:a' } ,
{ rejectUnauthorized : 'false' , servername : 'a:' } ] ,
[ { honorCipherOrder : 'a:b' } , { honorCipherOrder : 'a' , ecdhCurve : 'b:' } ] ,
[ { ecdhCurve : 'a:b' } , { ecdhCurve : 'a' , dhparam : 'b:' } ] ,
[ { dhparam : 'a:b' } , { dhparam : 'a' , secureOptions : 'b:' } ] ,
[ { secureOptions : '1:a' } , { secureOptions : 1 , sessionIdContext : 'a:' } ] ,
[ { sessionIdContext : 'a:b' } , { sessionIdContext : 'a' , sigalgs : 'b:' } ] ,
[ { sigalgs : [ 'a:b' ] } , { sigalgs : [ 'a' , 'b' ] } ] ,
[ { servername : 'a' , rejectUnauthorized : false , ecdhCurve : 'P-256:P-384' } ,
{ rejectUnauthorized : 'false:a' , honorCipherOrder : 'P-256' ,
ecdhCurve : 'P-384' } ] ,
] ;
for ( const [ first , second ] of collisions ) {
assert . notStrictEqual (
agent . getName ( { ...baseOptions , ...first } ) ,
agent . getName ( { ...baseOptions , ...second } ) ,
`${ JSON . stringify ( first ) } collides with ${ JSON . stringify ( second ) } `
) ;
}
// The type of a value is part of its key.
assert . notStrictEqual (
agent . getName ( { ...baseOptions , rejectUnauthorized : false } ) ,
agent . getName ( { ...baseOptions , rejectUnauthorized : 'false' } )
) ;
assert . notStrictEqual (
agent . getName ( { ...baseOptions , dhparam : new DataView ( new ArrayBuffer ( 2 ) ) } ) ,
agent . getName ( {
...baseOptions ,
dhparam : new DataView ( new Uint8Array ( [ 1 , 2 ] ) . buffer ) ,
} )
) ;
}
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.