File tree 2 files changed +29
-1
lines changed
2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -1544,7 +1544,15 @@ function onConnectSecure() {
1544
1544
this . authorized = false ;
1545
1545
this . authorizationError = verifyError . code || verifyError . message ;
1546
1546
1547
- if ( options . rejectUnauthorized ) {
1547
+ // rejectUnauthorized property can be explicitly defined as `undefined`
1548
+ // causing the assignment to default value (`true`) fail. Before assigning
1549
+ // it to the tlssock connection options, explicitly check if it is false
1550
+ // and update rejectUnauthorized property. The property gets used by
1551
+ // TLSSocket connection handler to allow or reject connection if
1552
+ // unauthorized.
1553
+ // This check is potentially redundant, however it is better to keep it
1554
+ // in case the option object gets modified somewhere.
1555
+ if ( options . rejectUnauthorized !== false ) {
1548
1556
this . destroy ( verifyError ) ;
1549
1557
return ;
1550
1558
}
@@ -1629,6 +1637,13 @@ exports.connect = function connect(...args) {
1629
1637
signal : options . signal ,
1630
1638
} ) ;
1631
1639
1640
+ // rejectUnauthorized property can be explicitly defined as `undefined`
1641
+ // causing the assignment to default value (`true`) fail. Before assigning
1642
+ // it to the tlssock connection options, explicitly check if it is false
1643
+ // and update rejectUnauthorized property. The property gets used by TLSSocket
1644
+ // connection handler to allow or reject connection if unauthorized
1645
+ options . rejectUnauthorized = options . rejectUnauthorized !== false ;
1646
+
1632
1647
tlssock [ kConnectOptions ] = options ;
1633
1648
1634
1649
if ( cb )
Original file line number Diff line number Diff line change @@ -71,6 +71,19 @@ function rejectUnauthorized() {
71
71
servername : 'localhost'
72
72
} , common . mustNotCall ( ) ) ;
73
73
socket . on ( 'data' , common . mustNotCall ( ) ) ;
74
+ socket . on ( 'error' , common . mustCall ( function ( err ) {
75
+ rejectUnauthorizedUndefined ( ) ;
76
+ } ) ) ;
77
+ socket . end ( 'ng' ) ;
78
+ }
79
+
80
+ function rejectUnauthorizedUndefined ( ) {
81
+ console . log ( 'reject unauthorized undefined' ) ;
82
+ const socket = tls . connect ( server . address ( ) . port , {
83
+ servername : 'localhost' ,
84
+ rejectUnauthorized : undefined
85
+ } , common . mustNotCall ( ) ) ;
86
+ socket . on ( 'data' , common . mustNotCall ( ) ) ;
74
87
socket . on ( 'error' , common . mustCall ( function ( err ) {
75
88
authorized ( ) ;
76
89
} ) ) ;
You can’t perform that action at this time.
0 commit comments