blib/script/find-secret-leakage-in-git-diff.pl untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 2 Podpod n/a totaltotal 0.0% 0 / 61 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2 # PODNAME: find-secret-leakage-in-git-diff.pl
3 # ABSTRACT: find secrets leaking in a Git repository
4 ## no critic (RequireCarping)
5  
6 use v5.16.0;
7 use warnings;
8  
9 my %tokens = (
10 # Article's TABLE III
11 'Amazon AWS Access Key ID' => qr/AKIA[0-9A-Z]{16}/,
12 'Amazon MWS Auth Token' => qr/amzn\.mws\.[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}/,
13 'Facebook Access Token' => qr/EAACEdEose0cBA[0-9a-zA-Z]+/,
14 'Google API Key' => qr/AIza[0-9a-zA-Z_-]{35}/,
15 'Google OAuth ID' => qr/\d+-[0-9a-zA-Z_]{32}\.apps\.googleusercontent\.com/,
16 'MailChimp API Key' => qr/[0-9a-f]{32}-us\d{1,2}/,
17 'MailGun API Key' => qr/key-[0-9a-zA-Z]{32}/,
18 'PayPal Braintree Access Token' => qr/access_token\$production\$[0-9a-z]{16}\$[0-9a-f]{32}/,
19 'Picatic API Key' => qr/sk_live_[0-9a-z]{32}/,
20 'Square Access Token' => qr/sq0atp-[0-9a-zA-Z_-]{22}/,
21 'Square OAuth Secret' => qr/sq0csp-[0-9a-zA-Z_-]{43}/,
22 'Stripe API Key' => qr/[rs]k_live_[0-9a-zA-Z]{24}/,
23 'Twilio API Key' => qr/SK[0-9a-fA-F]{32}/,
24 'Twitter Access Token' => qr/[1-9]\d+-[0-9a-zA-Z]{40}/,
25  
26 # Private keys (RSA, SSH, PKCS8, PGP, EC, etc.)
27 'Private Key' => qr/-----BEGIN [A-Z ]*?PRIVATE KEY(?: BLOCK)?-----/,
28  
29 # Passwords
30 'URL with Password' => qr'(?i)[a-z][a-z+.-]*://[^:@/]+:([^@/]+)@',
31 );
32  
33 my $errors = 0;
34  
35 my ($filename, $lineno, $skip) = ('', 0, 0);
36  
37 while (<>) {
38 if (/^\+\+\+ (.+)/) {
39 $filename = $1;
40 } elsif (/^\@\@ -[0-9,]+ \+(\d+)/) {
41 $lineno = $1;
42 } elsif (/^\ /) {
43 $lineno += 1;
44 } elsif (/^\+/) {
45 if (/## not a secret leak ?(begin|end)?/) {
46 if ($skip) {
47 $skip = 0 if defined $1 && $1 eq 'end';
48 } else {
49 $skip = 1 if defined $1 && $1 eq 'begin';
50 }
51 $lineno += 1;
52 next;
53 }
54 unless ($skip) {
55 while (my ($token, $regex) = each %tokens) {
56 if (/$regex/) {
57 $errors += 1;
58 warn "$filename:$lineno: Secret Leakage: $token '$&'";
59 last;
60 }
61 }
62 }
63 $lineno += 1;
64 }
65 }
66  
67 exit $errors;
68  
69 __END__