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

Reports commented line as an issue #182

Closed
MVrachev opened this issue May 20, 2019 · 5 comments
Closed

Reports commented line as an issue #182

MVrachev opened this issue May 20, 2019 · 5 comments
Labels
question The issue is a technical question related to the project.

Comments

@MVrachev
Copy link

MVrachev commented May 20, 2019

I have my file test.js.
I use it to run different tests to understand how detect-secrets works.

When I scan this file with the command:
detect-secrets scan test.js

I get as a result:

  "results": {
    "test.js": [
      {
        "hashed_secret": "edbd2994e5980ce68a498791abc1fb9c40f6bb43",
        "line_number": 13,
        "type": "Secret Keyword"
      },
      {
        "hashed_secret": "daefe0b4345a654580dcad25c7c11ff4c944a8c0",
        "line_number": 68,
        "type": "Private Key"
      },
      {
        "hashed_secret": "99b5e14eaf6b7cd863796dab48ae736be2ac6b53",
        "line_number": 77,
        "type": "Basic Auth Credentials"
      }
    ]
  },

The problems on line 13 and 68 are real, but not the one on line 77.

On line 77 I have:
// let basic_auth = 'http://username:whywouldyouusehttpforpasswords@example.com'

Node.js version: v11.9.0

detect-secrets version: 0.12.2

@MVrachev MVrachev changed the title [Bug] Reports commented line as an issue Reports commented line as an issue May 20, 2019
@dgzlopes
Copy link
Contributor

dgzlopes commented May 20, 2019

Hi! You have to use the // pragma: whitelist secret comment for ignoring a particular line of code (Inline Whitelisting on README.md). As a note, support for text after inline whitelisting comments was added on 0.12.3, so maybe you should update.

On the other hand, testing it right now with pragma seems to behave badly as this returns a secret :

// pragma: whitelist secret let basic_auth = 'http://username:whywouldyouusehttpforpasswords@example.com'

But this works fine:

// pragma: whitelist secret let basic_auth = 'http://username:@example.com'

From checking this briefly, whitelisting fails when we have a secret inside a whitelisted comment.

@killuazhu
Copy link
Contributor

killuazhu commented May 20, 2019

@dgzlopes The inline comment needs to be on the same line. For you case, you can use

let basic_auth = 'http://username:@example.com' // pragma: whitelist secret

@dgzlopes
Copy link
Contributor

dgzlopes commented May 20, 2019

Yep @killuazhu, but support for text after inline whitelisting was added (here [0]) so both examples should work! But the first one doesn't work as expected.

I mean, this actually works fine on the last version (by working fine I mean, the additional text is omitted):

// pragma: whitelist secret let basic_auth = 'http://username:@example.com'

[0] #168

@dgzlopes
Copy link
Contributor

dgzlopes commented May 20, 2019

Obviously, the 'common case' is:

var key = "pass" # pragma: whitelist secret

or with after text:

var key = "pass" # pragma: whitelist secret some text

But on the edge case of having a key (this is just an example, but I mean a detect-secrets detectable key) on the comment, it doesn't work:

var key = "pass" # pragma: whitelist secret youusehttpforpasswords

Maybe this needs a look?

@MVrachev
Copy link
Author

Thank you both for your responses!
Even if the code is commented it's still can be hardcoded credentials and it makes sense that detect-secrets scan such code and only through a specific comment to be missed.

@KevinHock KevinHock added the question The issue is a technical question related to the project. label May 22, 2019
killuazhu pushed a commit to IBM/detect-secrets that referenced this issue May 28, 2020
* Flag to output verified false tokens

Supports git-defenders/detect-secrets-discuss/issues/166

* Simplify usage description for flag

* Test code

* Addressed @xianjun second comment

* Addressed @xianjun comments

* Fixes after testing

* Address comments
killuazhu pushed a commit to IBM/detect-secrets that referenced this issue Jul 9, 2020
* Flag to output verified false tokens

Supports git-defenders/detect-secrets-discuss/issues/166

* Simplify usage description for flag

* Test code

* Addressed @xianjun second comment

* Addressed @xianjun comments

* Fixes after testing

* Address comments
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question The issue is a technical question related to the project.
Projects
None yet
Development

No branches or pull requests

4 participants