-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(java): airbrake library (CWE-201) (#252)
- Loading branch information
Showing
3 changed files
with
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
imports: | ||
- java_shared_lang_datatype | ||
patterns: | ||
- pattern: $<AIRBRAKE>.report($<DATA_TYPE>$<...>); | ||
filters: | ||
- variable: AIRBRAKE | ||
regex: \A(io\.airbrake\.javabrake\.)?Airbrake\z | ||
- variable: DATA_TYPE | ||
detection: java_shared_lang_datatype | ||
- pattern: $<AIRBRAKE_NOTICE>.$<METHOD>($<_>, $<DATA_TYPE>); | ||
filters: | ||
- variable: AIRBRAKE_NOTICE | ||
detection: java_third_parties_airbrake_javabrake_notice | ||
- variable: METHOD | ||
values: | ||
- setContext | ||
- setParam | ||
- variable: DATA_TYPE | ||
detection: java_shared_lang_datatype | ||
auxiliary: | ||
- id: java_third_parties_airbrake_javabrake_notice | ||
patterns: | ||
- pattern: $<AIRBRAKE>.buildNotice(); | ||
filters: | ||
- variable: AIRBRAKE | ||
regex: \A(io\.airbrake\.javabrake\.)?Airbrake\z | ||
languages: | ||
- java | ||
skip_data_types: | ||
- "Unique Identifier" | ||
metadata: | ||
description: Leakage of sensitive data to Airbrake | ||
remediation_message: | | ||
## Description | ||
Leaking sensitive data to third-party loggers is a common cause of data | ||
leaks and can lead to data breaches. This rule looks for instances of | ||
sensitive data sent to Airbrake. | ||
## Remediations | ||
✅ When logging errors or events, ensure all sensitive data is removed. | ||
## Resources | ||
- [Airbrake Docs](https://docs.airbrake.io/docs/platforms/java/) | ||
cwe_id: | ||
- 201 | ||
associated_recipe: Airbrake | ||
id: java_third_parties_airbrake_javabrake | ||
documentation_url: https://docs.bearer.com/reference/rules/java_third_parties_airbrake_javabrake |
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,18 @@ | ||
const { | ||
createNewInvoker, | ||
getEnvironment, | ||
} = require("../../../helper.js") | ||
const { ruleId, ruleFile, testBase } = getEnvironment(__dirname) | ||
|
||
describe(ruleId, () => { | ||
const invoke = createNewInvoker(ruleId, ruleFile, testBase) | ||
|
||
test("airbrake_javabrake", () => { | ||
const testCase = "main.java" | ||
|
||
const results = invoke(testCase) | ||
|
||
expect(results.Missing).toEqual([]) | ||
expect(results.Extra).toEqual([]) | ||
}) | ||
}) |
31 changes: 31 additions & 0 deletions
31
tests/java/third_parties/airbrake_javabrake/testdata/main.java
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,31 @@ | ||
// Use bearer:expected java_third_parties_airbrake_javabrake to flag expected findings | ||
import io.airbrake.javabrake.Airbrake; | ||
import io.airbrake.javabrake.Notice; | ||
|
||
public class AirbrakeJavabrake() { | ||
public static void bad(User user) { | ||
try { | ||
do(); | ||
} catch (IOException e) { | ||
// bearer:expected java_third_parties_airbrake_javabrake | ||
Airbrake.report(e + " for " + user.username); | ||
} | ||
} | ||
|
||
public static void bad(User user) { | ||
Notice notice = Airbrake.buildNotice(e); | ||
// bearer:expected java_third_parties_airbrake_javabrake | ||
notice.setContext("user", user.username); | ||
// bearer:expected java_third_parties_airbrake_javabrake | ||
notice.setParam("email", user.email); | ||
Airbrake.send(notice); | ||
} | ||
|
||
public static void ok() { | ||
try { | ||
do(); | ||
} catch (IOException e) { | ||
Airbrake.report(e); | ||
} | ||
} | ||
} |