Skip to content

Commit

Permalink
read frpm process.env NODE_TLS_REJECT_UNAUTHORIZED when strictSSL is …
Browse files Browse the repository at this point in the history
…not defined
  • Loading branch information
Bruno Oliveira committed Sep 19, 2024
1 parent 253f3b9 commit 95c9171
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ const conditionalHeaders = [
const configureOptions = (opts) => {
const { strictSSL, ...options } = { ...opts }
options.method = options.method ? options.method.toUpperCase() : 'GET'
options.rejectUnauthorized = strictSSL !== false

if (strictSSL === undefined || strictSSL === null) {
options.rejectUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED !== '0'
} else {
options.rejectUnauthorized = strictSSL !== false
}

if (!options.retry) {
options.retry = { retries: 0 }
Expand Down
24 changes: 24 additions & 0 deletions test/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,30 @@ t.test('configure options', async (t) => {
'should treat strictSSL: null as true just like tls.connect')
})

t.test('when NODE_TLS_REJECT_UNAUTHORIZED is defined', async (t) => {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'

Check failure

Code scanning / CodeQL

Disabling certificate validation High test

Disabling certificate validation is strongly discouraged.

t.same(configureOptions({ }).rejectUnauthorized, false,
'should return rejectUnauthorized false when NODE_TLS_REJECT_UNAUTHORIZED="0" ' +
'and strictSSL is undefined')

t.same(configureOptions({ strictSSL: null }).rejectUnauthorized, false,
'should return rejectUnauthorized false when NODE_TLS_REJECT_UNAUTHORIZED="0" ' +
'and strictSSL is null')

t.same(configureOptions({ strictSSL: true }).rejectUnauthorized, true,
'should return rejectUnauthorized true when NODE_TLS_REJECT_UNAUTHORIZED="0" ' +
'and strictSSL is true')

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '1'

t.same(configureOptions({ strictSSL: false }).rejectUnauthorized, false,
'should return rejectUnauthorized false when NODE_TLS_REJECT_UNAUTHORIZED="1" ' +
'and strictSSL is false')

process.env.NODE_TLS_REJECT_UNAUTHORIZED = undefined
})

t.test('should set dns property correctly', async (t) => {
t.test('no property given', async (t) => {
const actualOpts = { method: 'GET' }
Expand Down

0 comments on commit 95c9171

Please sign in to comment.