Skip to content

Commit

Permalink
fix(trufflehog): report the correct line numbers (#531)
Browse files Browse the repository at this point in the history
Trufflehog can report wildly incorrect line numbers for secrets, and
even report multiple incorrect issues for a given secret. This PR
changes our trufflehog parser to scan the file for the secret and report
the correct line number. As the trufflehog can report duplicates, we
only output a lint issue once for a given secret.

This is tested with `wrong_line_number.in.ts`, which trufflehog reports
4 issues on incorrect lines for 2 identical secrets. The parser finds
these two secrets on their separate lines.

This only fixes the issue for trufflehog filesystem - I'm not sure if
this an issue in trufflehog git, and the files may be changed/deleted
since the past.
  • Loading branch information
puzzler7 authored Nov 9, 2023
1 parent 419e8e3 commit 091d31d
Show file tree
Hide file tree
Showing 13 changed files with 681 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// trunk-upgrade-validation:RELEASE

exports[`Testing linter actionlint test CUSTOM 1`] = `
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// trunk-upgrade-validation:RELEASE

exports[`Testing linter codespell test basic 1`] = `
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// trunk-upgrade-validation:RELEASE

exports[`Testing linter codespell test dictionary 1`] = `
{
Expand Down
1 change: 0 additions & 1 deletion linters/ktlint/test_data/ktlint_v1.0.0_basic.fmt.shot
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// trunk-upgrade-validation:RELEASE

exports[`Testing formatter ktlint test basic 1`] = `
"class MainActivity : AppCompatActivity() {
Expand Down
1 change: 0 additions & 1 deletion linters/ktlint/test_data/ktlint_v1.0.0_complex.fmt.shot
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// trunk-upgrade-validation:RELEASE

exports[`Testing formatter ktlint test complex 1`] = `
"class TestBaselineExtraErrorFile {
Expand Down
1 change: 0 additions & 1 deletion linters/ktlint/test_data/ktlint_v1.0.0_utf8.fmt.shot
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// trunk-upgrade-validation:RELEASE

exports[`Testing formatter ktlint test utf8 1`] = `
"package demo
Expand Down
1 change: 0 additions & 1 deletion linters/mypy/test_data/mypy_v1.6.0_CUSTOM.check.shot
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// trunk-upgrade-validation:RELEASE

exports[`Testing linter mypy test CUSTOM 1`] = `
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// trunk-upgrade-validation:RELEASE

exports[`Testing linter remark-lint test basic 1`] = `
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// trunk-upgrade-validation:RELEASE

exports[`Testing formatter remark-lint test basic 1`] = `
"* this is a list item
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// trunk-upgrade-validation:RELEASE

exports[`Testing linter sourcery test basic 1`] = `
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing linter trufflehog test wrong_line_number 1`] = `
{
"issues": [
{
"code": "URI",
"file": "test_data/wrong_line_number.in.ts",
"isSecurity": true,
"level": "LEVEL_HIGH",
"line": "587",
"linter": "trufflehog",
"message": "Secret detected: https://admin:********@the-internet.herokuapp.com",
"targetType": "ALL",
},
{
"code": "URI",
"file": "test_data/wrong_line_number.in.ts",
"isSecurity": true,
"level": "LEVEL_HIGH",
"line": "592",
"linter": "trufflehog",
"message": "Secret detected: https://admin:********@the-internet.herokuapp.com",
"targetType": "ALL",
},
],
"lintActions": [
{
"command": "lint",
"fileGroupName": "ALL",
"linter": "trufflehog",
"paths": [
"test_data/wrong_line_number.in.ts",
],
"verb": "TRUNK_VERB_CHECK",
},
],
"taskFailures": [],
"unformattedFiles": [],
}
`;
Loading

0 comments on commit 091d31d

Please sign in to comment.