awslabs / git-secrets

Prevents you from committing secrets and credentials into git repositories
Apache License 2.0
12.44k stars 1.18k forks source link

Email address pattern #41

Open bjfletcher opened 7 years ago

bjfletcher commented 7 years ago

Hi there,

I'm trying to get it to match email addresses (RFC 5322), which I don't want to commit.

(([^<>()\\[\\]\\\\.,;:\\s@"]+(\\.[^<>()\[\]\\\\.,;:\\s@"]+)*)|(".+"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))

The above works great when tested in JavaScript. But git secrets --scan fails with the following output:

fatal: command line, '(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()[]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))': Invalid range end
mtdowling commented 7 years ago

What's the output of grep --version? How did you add the pattern to git-secrets? What does the pattern look like in your .git/config?

ericzon commented 4 years ago

in my case I got the same result (Invalid range end):

git secrets --list

secrets.providers cat /path/to/credential/patterns.txt

patterns.txt content:

MY_KEY( )*=( )*[a-zA-Z0-9-_.]{90,}

I added as explained in the example:

git secrets --add-provider -- cat /path/to/credential/patterns.txt

What does the pattern look like in your .git/config?

[secrets]
    providers = cat /Users/elara/Documents/gitsec/credential_patterns.txt

OS: macos mojave grep (BSD grep) 2.5.1-FreeBSD

sparr commented 1 year ago

[a-zA-Z\\-0-9]

If you're looking for a-z and A-Z and \ and -and 0-9 then you need to move the - to the end, otherwise grep is trying to match \-0 which is not a valid character range.