-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(JS rules): add CWE-525 bad caching policy for expressjs JWT not …
…revoked (#695) feat: add cwe-525 bad caching policy / express JWT not revoked
- Loading branch information
Showing
6 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
pkg/commands/process/settings/rules/javascript/express/jwt_not_revoked.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
15 changes: 15 additions & 0 deletions
15
...wt_not_revoked/.snapshots/TestJavascriptExpressJwtNotRevoked--express_jwt_not_revoked.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] })' | ||
|
||
|
3 changes: 3 additions & 0 deletions
3
...jwt_not_revoked/.snapshots/TestJavascriptExpressJwtNotRevoked--ok_express_jwt_revoked.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{} | ||
|
||
|
19 changes: 19 additions & 0 deletions
19
...ess/settings/rules/javascript/express/jwt_not_revoked/testdata/express_jwt_not_revoked.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
); |
10 changes: 10 additions & 0 deletions
10
...cess/settings/rules/javascript/express/jwt_not_revoked/testdata/ok_express_jwt_revoked.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
); |