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 rules): add CWE-525 bad caching policy for expressjs JWT not revoked #695

Merged
merged 1 commit into from
Mar 1, 2023
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
4 changes: 4 additions & 0 deletions integration/rules/javascript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func TestJavascriptExpressExternalFileUpload(t *testing.T) {
getRunner(t).runTest(t, javascriptRulesPath+"express/external_file_upload")
}

func TestJavascriptExpressJwtNotRevoked(t *testing.T) {
getRunner(t).runTest(t, javascriptRulesPath+"express/jwt_not_revoked")
}

func TestJavascriptExpressExposedDirListing(t *testing.T) {
t.Parallel()
getRunner(t).runTest(t, javascriptRulesPath+"express/exposed_dir_listing")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
patterns:
- pattern: |
expressjwt($<HASH_CONTENT>)
filters:
- variable: HASH_CONTENT
detection: javascript_express_jwt_not_revoked_secret_datatype
- not:
variable: HASH_CONTENT
detection: javascript_express_jwt_not_revoked_is_revoked
languages:
- javascript
auxiliary:
- id: javascript_express_jwt_not_revoked_secret_datatype
patterns:
- pattern: |
{ $<...>secret: $<DATA_TYPE>$<...> }
filters:
- variable: DATA_TYPE
detection: datatype
- id: javascript_express_jwt_not_revoked_is_revoked
patterns:
- pattern: |
{ $<...>isRevoked: $<_>$<...> }
trigger: presence
severity:
default: "warning"
metadata:
description: "Unrevoked JWT detected."
remediation_message: |
## Description
The best practice caching policy is to revoke JWTs especially when these contain senstitive information.

<!--
## Remediations
Coming soon.
## Resources
Coming soon.
-->
cwe_id:
- 525
id: "javascript_express_jwt_not_revoked"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
warning:
- rule:
cwe_ids:
- "525"
id: javascript_express_jwt_not_revoked
description: Unrevoked JWT detected.
documentation_url: https://docs.bearer.com/reference/rules/javascript_express_jwt_not_revoked
line_number: 5
filename: express_jwt_not_revoked.js
category_groups:
- PII
parent_line_number: 5
parent_content: 'expressjwt({ secret: currentUser.email, algorithms: ["HS256"] })'


Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{}


Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expressjwt } from "express-jwt";

app.get(
"/unrevoked",
expressjwt({ secret: currentUser.email, algorithms: ["HS256"] }),
function (req, res) {
if (!req.auth.admin) return res.sendStatus(401);
res.sendStatus(200);
}
);

app.get(
"/unrevoked",
expressjwt({ secret: "some-secret", algorithms: ["HS256"] }),
function (req, res) {
if (!req.auth.admin) return res.sendStatus(401);
res.sendStatus(200);
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { expressjwt } from "express-jwt";

app.get(
"/revoked",
expressjwt({ secret: currentUser.email, isRevoked: this.customRevokeCall(), algorithms: ["HS256"] }),
function (req, res) {
if (!req.auth.admin) return res.sendStatus(401);
res.sendStatus(200);
}
);