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(java): third parties rollbar (CWE-201) #266

Merged
merged 1 commit into from
Feb 15, 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
51 changes: 51 additions & 0 deletions rules/java/third_parties/rollbar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
imports:
- java_shared_lang_datatype
- java_shared_lang_instance
patterns:
- pattern: |
$<ROLLBAR>.$<METHOD>($<...>$<DATA_TYPE>$<...>);
filters:
- variable: ROLLBAR
detection: java_third_parties_rollbar_instance
- variable: METHOD
values:
- debug
- error
- info
- setPersonData
- variable: DATA_TYPE
detection: java_shared_lang_datatype
auxiliary:
- id: java_third_parties_rollbar_instance
patterns:
- pattern: $<ROLLBAR>;
filters:
- variable: ROLLBAR
detection: java_shared_lang_instance
scope: cursor
filters:
- variable: JAVA_SHARED_LANG_INSTANCE_TYPE
regex: \A(com\.rollbar\.notifier\.)?Rollbar\z
languages:
- java
skip_data_types:
- "Unique Identifier"
metadata:
description: Leakage of sensitive data to RollBar
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 Rollbar.

## Remediations

When logging errors or events, ensure all sensitive data is removed.

## Resources
- [Rollbar docs](https://docs.rollbar.com/docs/java)
cwe_id:
- 201
associated_recipe: Rollbar
id: java_third_parties_rollbar
documentation_url: https://docs.bearer.com/reference/rules/java_third_parties_rollbar
18 changes: 18 additions & 0 deletions tests/java/third_parties/rollbar/test.js
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("rollbar", () => {
const testCase = "main.java"

const results = invoke(testCase)

expect(results.Missing).toEqual([])
expect(results.Extra).toEqual([])
})
})
35 changes: 35 additions & 0 deletions tests/java/third_parties/rollbar/testdata/main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Use bearer:expected java_third_parties_rollbar to flag expected findings

import com.rollbar.notifier.Rollbar;
import com.rollbar.notifier.config.Config;
import com.rollbar.notifier.config.ConfigBuilder;

public class Foo {
protected void bad(User user) {
Config config = ConfigBuilder.withAccessToken("<post_server_item_access_token>")
.environment("production")
.codeVersion("1.0.0")
.build();
Rollbar rollbar = new Rollbar(config);
// bearer:expected java_third_parties_rollbar
rollbar.error(user.email);
// bearer:expected java_third_parties_rollbar
rollbar.info("This is an info message about " + user.name);
// bearer:expected java_third_parties_rollbar
rollbar.setPersonData(user.uuid,user.name,user.email);
// bearer:expected java_third_parties_rollbar
rollbar.debug("Here is some debug message for " + user.name);
}

public void good(User user) {
Config config = ConfigBuilder.withAccessToken("<post_server_item_access_token>")
.environment("production")
.codeVersion("1.0.0")
.build();
Rollbar rollbar = new Rollbar(config);
rollbar.error("Some error message");
rollbar.info("This is an info message about " + user.uuid);
rollbar.setPersonData(user.uuid);
rollbar.debug("Here is some debug message for " + user.uuid);
}
}
Loading