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

include prohibited regular expressions from a .gitprohibited file #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

willphdavies
Copy link

Update git-secrets to include prohibited regular expressions from a .gitprohibited file

Issue #, if available:

Add the possibility of using a .gitprohibited file in the repository root to include prohibited patterns - much the same as .gitallowed is used to mark false positives

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@chrisba11
Copy link

Would love to see this merged in!

Copy link
Contributor

@sparr sparr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are also needed for this change.

  1. positive test, prohibited pattern is successfully detected as a secrets match
  2. negative test, commented line doesn't match
  3. positive test, line starting with (#) (or another suggested alternative to ^#) matches
    Possibly others, try to exercise the various use cases here.

@@ -403,6 +403,9 @@ like Ubuntu (BSD vs GNU).
You can add prohibited regular expression patterns to your git config using
``git secrets --add <pattern>``.

You can also add prohibited regular expressions patterns to a
``.gitprohibited`` file located in the repository's root directory. Lines starting
with ``#`` are skipped (comment line) and empty lines are also skipped.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sold on the name, but can't think of a better one. I'm opening this thread to explicitly ask the next reviewer to weigh in on the file name.

@@ -47,6 +47,10 @@ prepare_commit_msg_hook* prepare-commit-msg hook (internal only)"

load_patterns() {
git config --get-all secrets.patterns
local gitprohibited="$(git rev-parse --show-toplevel)/.gitprohibited"
if [ -e "$gitprohibited" ]; then
cat $gitprohibited | awk 'NF && $1!~/^#/'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cat $gitprohibited | awk 'NF && $1!~/^#/'
awk 'NF && $1!~/^#/' "$gitprohibited"

cat is not necessary here, and the quotes are needed in case the path to the file has spaces

@@ -403,6 +403,9 @@ like Ubuntu (BSD vs GNU).
You can add prohibited regular expression patterns to your git config using
``git secrets --add <pattern>``.

You can also add prohibited regular expressions patterns to a
``.gitprohibited`` file located in the repository's root directory. Lines starting
with ``#`` are skipped (comment line) and empty lines are also skipped.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should the user specify patterns that start with #? I think (#) would work, but that should probably be explicitly described here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants