Skip to content

Commit

Permalink
feat(JS rules): add CWE-525 bad caching policy for expressjs JWT not …
Browse files Browse the repository at this point in the history
…revoked (#695)

feat: add cwe-525 bad caching policy / express JWT not revoked
  • Loading branch information
elsapet authored Mar 1, 2023
1 parent 8fe75d7 commit 0d94455
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 0 deletions.
4 changes: 4 additions & 0 deletions integration/rules/javascript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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);
}
);

0 comments on commit 0d94455

Please sign in to comment.