Skip to content
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

feat(js): add missing TLS rule for Node #316

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/canary_integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
"javascript/express",
"javascript/hapi",
"javascript/lang",
"javascript/node",
"javascript/react",
"javascript/third_parties",
"ruby/lang",
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
"javascript/express",
"javascript/hapi",
"javascript/lang",
"javascript/node",
"javascript/react",
"javascript/third_parties",
"ruby/lang",
Expand Down
24 changes: 24 additions & 0 deletions rules/javascript/node/missing_tls_validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
patterns:
- $<_>.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
- $<_>.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";
languages:
- javascript
severity: warning
metadata:
description: Missing TLS validation
remediation_message: |
## Description

When establishing a connection, it is important to validate the SSL/TLS certificate in order to mitigate
man-in-the-middle attacks, data interception and related security risks.

Disabling SSL/TLS certification validation is a serious security risk that puts your application at risk.

## Remediations

❌ Do not set the NODE_TLS_REJECT_UNAUTHORIZED variable to zero

cwe_id:
- 295
id: javascript_node_missing_tls_validation
documentation_url: https://docs.bearer.com/reference/rules/javascript_node_missing_tls_validation
20 changes: 20 additions & 0 deletions tests/javascript/node/missing_tls_validation/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const {
createNewInvoker,
getEnvironment,
} = require("../../../helper.js")
const { ruleId, ruleFile, testBase } = getEnvironment(__dirname)

describe(ruleId, () => {
const invoke = createNewInvoker(ruleId, ruleFile, testBase)

test("missing_tls_validation", () => {
const testCase = "app.js"

const results = invoke(testCase)

expect(results).toEqual({
Missing: [],
Extra: []
})
})
})
13 changes: 13 additions & 0 deletions tests/javascript/node/missing_tls_validation/testdata/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function bad() {
// bearer:expected javascript_node_missing_tls_validation
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
}

function bad2() {
// bearer:expected javascript_node_missing_tls_validation
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = '0';
}

function ok() {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '1';
}
Loading