Yelp / detect-secrets

An enterprise friendly way of detecting and preventing secrets in code.
Apache License 2.0
3.62k stars 450 forks source link

Changed or added secrets in existing files not detected #665

Closed csurfleet closed 1 year ago

csurfleet commented 1 year ago

I commit the baseline file then modify my compose file to

mongodb:
    image: mongo:latest
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: changedpassword
      SOME_OTHER_PASSWORD: newpassword

I then run detect-secrets scan --baseline .baseline > .newsecrets but the resulting file is empty. I can also run detect-secrets-hook --baseline .baseline and see no results there either.

jpdakran commented 1 year ago

Hi @csurfleet. Thank you for reporting this. I can explain the behaviour you are seeing.

Running detect-secrets scan > .baseline will add the MONGO_INITDB_ROOT_PASSWORD: password to the baseline file.

When you update the file to change the existing password and add a new password this will alert.

There is a difference between detect-secrets scan and detect-secrets-hook - the prior adds secrets to your baseline and the later alerts on new secrets.

When you run detect-secrets scan --baseline .baseline > .newsecrets - This does not work since adding the --baseline command initiates an update to that file with the results - there is no stdout which is why there is nothing in .newsecrets.

Running detect-secrets scan --baseline .baseline would correctly update the baseline file with the changed secret and the new secret.

If you want to alert (on the changed and new secret) - you can see the functionality below:

If you have any other questions let me know.

jpdakran commented 1 year ago

As this is intended behavior. I will go ahead and close out this issue. If you have any other questions or this answer was not sufficient. Please feel free to open another issue.