detect-secrets icon indicating copy to clipboard operation
detect-secrets copied to clipboard

detect-secrets not identifying all the secret occurrences in a file

Open reddybhaskarvengala opened this issue 3 years ago • 6 comments

If the secret written into a file at multiple locations, only the first one being identified by detect-secrets. Remaining instances are not getting reported by detect-secrets.

Example code in demo.txt

  1. secret="abcd"
  2. random code
  3. secret="abcd"

Now run the detect-secrets scan on the above file and observe that the issue will be reported only at the line 1 and it is not reported the line number 3.

reddybhaskarvengala avatar Nov 19 '21 07:11 reddybhaskarvengala

Hi @lorenzodb1 any update on this?

reddybhaskarvengala avatar Jul 06 '23 07:07 reddybhaskarvengala

Hey, this is mentioned in the docs, to avoid this you can do the following: go to detect-secrets/detect_secrets/core/potential_secret.py on line number 53, you'll find a list. In that list add another parameter "line_number". So it should look something like this: self.fields_to_compare = ['filename', 'secret_hash', 'type', 'line_number']

geekNero avatar Jul 14 '23 11:07 geekNero

I'm running into this issue as well.

Would it be worth adding a command line flag/programmatic setting of this behavior?

a-weiss-programmer avatar Oct 23 '23 16:10 a-weiss-programmer

I'll give it a go but the devs have been inactive for a while, I doubt they'll accept it. Still I'll drop the link to my forked repository.

geekNero avatar Oct 23 '23 16:10 geekNero

Hello everyone, apologies for the delayed reply. I've gathered some context around this issue and it turns out that this is actually a feature ™. Jokes aside, the idea behind this is that if detect-secrets flags a secret in a file, a developer would look for other instances of the same secret in it. Now, I personally do like the idea of flagging all instances, but the change is not trivial. #527 would help a lot, and I'm pushing for it to be merged as soon as possible. In the meantime, forgive us and stay tuned for more updates :)

lorenzodb1 avatar Nov 17 '23 00:11 lorenzodb1

Hi @lorenzodb1 thank you for the update.

reddybhaskarvengala avatar Nov 22 '23 06:11 reddybhaskarvengala