-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Cédric Fabianski <[email protected]> Co-authored-by: Cédric Fabianski <[email protected]>
- Loading branch information
1 parent
ceead2f
commit 0fb2db6
Showing
9 changed files
with
513 additions
and
60 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
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
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,157 @@ | ||
imports: | ||
- go_shared_lang_datatype | ||
patterns: | ||
- pattern: | | ||
$<CALLER>.$<METHOD>($<...>$<INPUT>$<...>) | ||
filters: | ||
- either: | ||
- variable: CALLER | ||
detection: go_lang_logger_leak_logger | ||
- variable: CALLER | ||
detection: go_lang_logger_leak_zerolog | ||
- variable: METHOD | ||
regex: \A(Fatal|Panic|Print)(f|ln)?\z | ||
- not: | ||
variable: INPUT | ||
detection: string_literal | ||
scope: cursor | ||
- not: | ||
variable: INPUT | ||
detection: go_shared_lang_datatype | ||
scope: result | ||
- pattern: | | ||
$<CALLER>.$<EVENT>().$<METHOD>($<...>$<INPUT>$<...>); | ||
filters: | ||
- either: | ||
- variable: CALLER | ||
detection: go_lang_logger_leak_logger | ||
- variable: CALLER | ||
detection: go_lang_logger_leak_zerolog | ||
- variable: EVENT | ||
regex: \A(Info|Debug|Error|Trace|Fatal|Panic|Warn)\z | ||
- variable: METHOD | ||
values: | ||
- Msg | ||
- Msgf | ||
- not: | ||
variable: INPUT | ||
detection: string_literal | ||
scope: cursor | ||
- not: | ||
variable: INPUT | ||
detection: go_shared_lang_datatype | ||
scope: result | ||
- pattern: | | ||
$<CALLER>.$<METHOD>($<...>$<INPUT>$<...>); | ||
filters: | ||
- either: | ||
- variable: CALLER | ||
detection: go_lang_logger_leak_logrus | ||
- variable: CALLER | ||
detection: go_lang_logger_leak_seelog | ||
- variable: METHOD | ||
regex: \A(WithFields\.)?(Info|Debug|Error|Trace|Fatal|Panic|Warn)\z | ||
- not: | ||
variable: INPUT | ||
detection: string_literal | ||
scope: cursor | ||
- not: | ||
variable: INPUT | ||
detection: go_shared_lang_datatype | ||
scope: result | ||
- pattern: | | ||
$<CALLER>.$<METHOD>($<...>$<INPUT>$<...>); | ||
filters: | ||
- variable: CALLER | ||
detection: go_lang_logger_leak_glog | ||
- variable: METHOD | ||
regex: \A(Info|Warning|Error|Fatal)(Contex)?(Depth)?(f)?\z | ||
- not: | ||
variable: INPUT | ||
detection: string_literal | ||
scope: cursor | ||
- not: | ||
variable: INPUT | ||
detection: go_shared_lang_datatype | ||
scope: result | ||
- pattern: | | ||
$<ZAP>.$<METHOD>($<...>$<INPUT>$<...>); | ||
filters: | ||
- variable: ZAP | ||
detection: go_lang_logger_leak_zap | ||
- variable: METHOD | ||
regex: \A(WithFields\.)?(Info|Log|Error|Fatal|DPanic|Warn)\z | ||
- not: | ||
variable: INPUT | ||
detection: string_literal | ||
scope: cursor | ||
- not: | ||
variable: INPUT | ||
detection: go_shared_lang_datatype | ||
scope: result | ||
auxiliary: | ||
- id: go_lang_logger_leak_logger | ||
patterns: | ||
- log | ||
- log.New(); | ||
- log.Default(); | ||
- import $<!>"log" | ||
- | | ||
import ( | ||
$<!>"log" | ||
) | ||
- id: go_lang_logger_leak_zerolog | ||
patterns: | ||
- import $<!>"github.com/rs/zerolog" | ||
- | | ||
import ( | ||
$<!>"github.com/rs/zerolog" | ||
) | ||
- id: go_lang_logger_leak_logrus | ||
patterns: | ||
- logrus.New(); | ||
- import $<!>"github.com/sirupsen/logrus" | ||
- | | ||
import ( | ||
$<!>"github.com/sirupsen/logrus" | ||
) | ||
- id: go_lang_logger_leak_zap | ||
patterns: | ||
- zap.$<_>().Sugar() | ||
- zap.$<_>() | ||
- id: go_lang_logger_leak_seelog | ||
patterns: | ||
- import $<!>"github.com/cihub/seelog" | ||
- | | ||
import ( | ||
$<!>"github.com/cihub/seelog" | ||
) | ||
- id: go_lang_logger_leak_glog | ||
patterns: | ||
- import $<!>"github.com/golang/glog" | ||
- | | ||
import ( | ||
$<!>"github.com/golang/glog" | ||
) | ||
languages: | ||
- go | ||
severity: warning | ||
metadata: | ||
description: "Leakage of information in logger message" | ||
remediation_message: | | ||
## Description | ||
Leaking data to loggers is a common cause of data leaks and can lead to data breaches. This rule looks for instances of dynamic data or variables sent to loggers. | ||
## Remediations | ||
❌ Avoid using variables or dynamic data in logger messages: | ||
```go | ||
logger.info(f"User is: '{user.email}'") | ||
``` | ||
cwe_id: | ||
- 532 | ||
id: go_lang_logger_leak | ||
documentation_url: https://docs.bearer.com/reference/rules/go_lang_logger_leak | ||
cloud_code_suggestions: true |
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
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 |
---|---|---|
@@ -1,30 +1,15 @@ | ||
const { | ||
createNewInvoker, | ||
getEnvironment, | ||
} = require("../../../helper.js") | ||
const { createNewInvoker, getEnvironment } = require("../../../helper.js") | ||
const { ruleId, ruleFile, testBase } = getEnvironment(__dirname) | ||
|
||
describe(ruleId, () => { | ||
const invoke = createNewInvoker(ruleId, ruleFile, testBase) | ||
|
||
|
||
test("bad", () => { | ||
const testCase = "bad.go" | ||
test("logger", () => { | ||
const testCase = "main.go" | ||
|
||
const results = invoke(testCase) | ||
const results = invoke(testCase) | ||
|
||
expect(results.Missing).toEqual([]) | ||
expect(results.Extra).toEqual([]) | ||
}) | ||
|
||
|
||
test("ok", () => { | ||
const testCase = "ok.go" | ||
|
||
const results = invoke(testCase) | ||
|
||
expect(results.Missing).toEqual([]) | ||
expect(results.Extra).toEqual([]) | ||
}) | ||
|
||
}) | ||
expect(results.Missing).toEqual([]) | ||
expect(results.Extra).toEqual([]) | ||
}) | ||
}) |
Oops, something went wrong.