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(python): add airbrake third parties rule (CWE-201) #431

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
67 changes: 67 additions & 0 deletions rules/python/third_parties/airbrake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
imports:
- python_shared_lang_datatype
- python_shared_lang_import1
patterns:
- pattern: $<NOTIFIER>.$<METHOD>($<...>$<DATA_TYPE>$<...>)
filters:
- variable: NOTIFIER
detection: python_third_parties_airbrake_notifier
scope: cursor
- variable: METHOD
values:
- notify
- notify_sync
- variable: DATA_TYPE
detection: python_shared_lang_datatype
scope: result
- pattern: $<NOTICE>[$<...>][$<...>] = $<...>$<DATA_TYPE>$<...>
filters:
- variable: NOTICE
detection: python_third_parties_airbrake_build_notice
scope: cursor
- variable: DATA_TYPE
detection: python_shared_lang_datatype
scope: result
auxiliary:
- id: python_third_parties_airbrake_notifier
patterns:
- pattern: $<NOTIFIER>($<...>)
filters:
- variable: NOTIFIER
detection: python_shared_lang_import1
scope: cursor
filters:
- variable: MODULE1
values: [pybrake]
- variable: NAME
values: [Notifier]
- id: python_third_parties_airbrake_build_notice
patterns:
- pattern: $<NOTIFIER>.build_notice($<...>)
filters:
- variable: NOTIFIER
detection: python_third_parties_airbrake_notifier
scope: cursor
languages:
- python
severity: medium
skip_data_types:
- Unique Identifier
metadata:
description: Leakage of sensitive data to Airbrake
remediation_message: |
## Description

Leaking sensitive data to third-party loggers like Airbrake is a common cause of data leaks and can lead to data breaches.

## Remediations

- **Do** ensure all sensitive data is removed when logging errors or events to Airbrake

## References
- [Airbrake Docs](https://docs.airbrake.io/docs/platforms/python/)
cwe_id:
- 201
associated_recipe: Airbrake
id: python_third_parties_airbrake
documentation_url: https://docs.bearer.com/reference/rules/python_third_parties_airbrake
20 changes: 20 additions & 0 deletions tests/python/third_parties/airbrake/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const {
createNewInvoker,
getEnvironment,
} = require("../../../helper.js")
const { ruleId, ruleFile, testBase } = getEnvironment(__dirname)

describe(ruleId, () => {
const invoke = createNewInvoker(ruleId, ruleFile, testBase)

test("airbrake", () => {
const testCase = "main.py"

const results = invoke(testCase)

expect(results).toEqual({
Missing: [],
Extra: []
})
})
})
12 changes: 12 additions & 0 deletions tests/python/third_parties/airbrake/testdata/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pybrake

notifier = pybrake.Notifier()

# bearer:expected python_third_parties_airbrake
notifier.notify(user.email)
# bearer:expected python_third_parties_airbrake
notice = notifier.notify_sync(user.email)
elsapet marked this conversation as resolved.
Show resolved Hide resolved

notice = notifier.build_notice()
# bearer:expected python_third_parties_airbrake
notice['params']['my_param'] = user.email
Loading