Compare commits

...
82 Commits
Author SHA1 Message Date
Roger Meier 7bad9f7654 chore(gcp): add firebase example keys to the gcp-api-key allowlists (#1635) 2025-01-15 06:47:08 -06:00
Richard Gomez 977236cb5f fix: unaligned 64-bit atomic operation panic (#1696) 2025-01-15 06:45:37 -06:00
Zach a211b1601f force push to master everyday 2025-01-14 19:14:21 -06:00
Richard Gomez 0e5f644b67 feat(config): disable extended rule (#1535) 2025-01-14 18:52:57 -06:00
Piotr Idzik f320a60e6f style: prevent globbing and word splitting (#1543) 2025-01-14 16:42:07 -06:00
Richard Gomez c4526b2c55 refactor(generic-api-key): remove hard-coded 'magic' (#1600) 2025-01-13 19:57:25 -06:00
Richard Gomez 748076d976 chore(generate): add failing test case (#1690) 2025-01-13 10:21:29 -06:00
Richard Gomez db8e5e672e feat(generate): use multiple allowlists (#1691) 2025-01-13 08:49:12 -06:00
Richard Gomez 973c794cf0 chore(rules): include fps in reference (#1471) 2025-01-13 08:40:20 -06:00
rmdwe f0d4499064 Add comma as operator for GenerateSemiGenericRegex (#1679)
* feat: add comma as operator for GenerateSemiGenericRegex

* test: fix tests.
2025-01-13 08:21:45 -06:00
Richard Gomez ab38a46986 refactor: central logger (#1692) 2025-01-13 08:09:22 -06:00
Zachary Rice b022d1c856 friendship ended with tines 2025-01-02 10:24:13 -06:00
almaz045andAlmaz Vakhitov b69b5157a0 Entropy trace (#1659)
* I do an entropy check earlier than the others and add the info to the trace

Maybe I'm wrong, but it seems to me that if the regex allowlist is large, it's easier to first check for entropy, since we won't have to go through all these regexes. Plus, we need to check entropy anyway.
Additionally, when using -l trace, there was no information that the find was missed precisely because of entropy. Now it will be shown

* adding info into trace about entropy

* Fixed name of variables

---------

Co-authored-by: Almaz Vakhitov <a.vakhitov@vk.team>
2024-12-30 10:15:51 -06:00
Richard Gomez 7357adca5e build: add 'toolchain' to go.mod (#1682) 2024-12-30 10:08:24 -06:00
Richard Gomez 4c3da6ebb7 refactor(detect): create readUntilSafeBoundary + add tests (#1676) 2024-12-28 15:14:49 -06:00
Zachary Rice dbe3746455 twitter really does suck ass now 2024-12-28 10:22:25 -06:00
Ben-grmbl 7edfc6b5d5 chore(tests): test cases for generate.go (#1623)
GenerateSemiGenericRegex,
GenerateUniqueTokenRegex

to clarify and document current behavior
2024-12-20 20:55:10 -06:00
Richard Gomez efe40cae39 fix: only use non-empty secret groups (#1632) 2024-12-20 20:53:44 -06:00
Richard Gomez 7cb5f6f64c build: upgrade sprig v2->v3 (#1674) 2024-12-20 19:44:18 -06:00
Kenichi Kamiya 2930537190 fix: generate report file even if no findings (#1673) 2024-12-20 10:17:23 -06:00
ahrav a91c6717a0 replace std library regex engine with go-re2 (#1669) 2024-12-20 09:53:01 -06:00
David Mateo 906085fba6 Update golang version to 1.23 (#1672)
Because go mod 1.23 has been updated, the golang image needs it too
2024-12-20 08:38:11 -06:00
Zach d0ba52e2be bump go in dockerfile 2024-12-20 05:54:52 -06:00
Zachary Rice 8a8306288e log bytes (#1670) 2024-12-20 05:46:25 -06:00
Zach a9e6d8c9a7 go mod 1.23 2024-12-19 09:27:43 -06:00
Craig SmithandCraig Smith 2f73a3e3cf Ensure keywords are downcased (#1633)
* Ensure keywords are downcased

* Update tests

* Remove unnecessary code

* Add msg to test expectation

* Update the keywords as we iterate through them

* Remove unnecessary to lower

---------

Co-authored-by: Craig Smith <5344211-craigmsmith@users.noreply.gitlab.com>
2024-12-19 09:22:03 -06:00
Bert Coppens f6966057f5 feat: add settlemint api keys detection (#1663)
* feat: add settlemint api keys detection

* fix regex creation

* use GenerateUniqueTokenRegex

* trigger ci

* ensure tokens have min length of 12

* ensure to set minLength on settlemint token pattern

* set base entropy for settlemint detectors

* update settlemint token regexes to be more precise
2024-12-13 09:18:30 -06:00
Richard Gomez 0bf13fc25a feat(dir): better chunking (#1665) 2024-12-12 10:27:27 -06:00
Richard Gomez 83e99bacf1 feat(report): allow user-defined templates (#1650) 2024-12-10 18:56:11 -06:00
e393d299bc Add support for GitLab routable tokens (#1656)
* Add support for GitLab routable tokens #1655

This commit adds support for GitLabs routable tokens.

For the specification see:
https://handbook.gitlab.com/handbook/engineering/architecture/design-documents/cells/routable_tokens/#proposal

Issue: https://github.com/gitleaks/gitleaks/issues/1655

* Add support for GitLab routable tokens #1655

This commit adds increases the entropy.

For the specification see:
https://handbook.gitlab.com/handbook/engineering/architecture/design-documents/cells/routable_tokens/#proposal

Issue: https://github.com/gitleaks/gitleaks/issues/1655

* add word boundary to regex

Co-authored-by: Ben-grmbl <173737458+Ben-grmbl@users.noreply.github.com>

* chore: re-generate gitleaks.toml

Co-authored-by: Ben-grmbl <173737458+Ben-grmbl@users.noreply.github.com>

---------

Co-authored-by: Nicholas Wittstruck <1283061+nwittstruck@users.noreply.github.com>
Co-authored-by: Ben-grmbl <173737458+Ben-grmbl@users.noreply.github.com>
2024-12-06 07:41:41 -06:00
naveen 263ce82365 Add freemius secret key detection (#1611) 2024-12-05 10:37:53 -06:00
Richard Gomez 3c0e068b69 fix(kubernetes): only match 'kind: secret' (#1649) 2024-12-05 10:22:34 -06:00
Bryce Thuilot f3adda07ca feat: use STDOUT when report file not specified (#1642)
* feat: use STDOUT when report file not specified

Signed-off-by: Bryce Thuilot <bryce@thuilot.io>

* fix: update tests

Signed-off-by: Bryce Thuilot <bryce@thuilot.io>

* fix: use only '-' for stdout report

Signed-off-by: Bryce Thuilot <bryce@thuilot.io>

---------

Signed-off-by: Bryce Thuilot <bryce@thuilot.io>
2024-12-05 09:44:07 -06:00
Richard Gomez ed205a5f63 fix(dir): skip opening file&dir if allowlist matches (#1653) 2024-12-05 08:35:42 -06:00
Richard Gomez 6018012b7e fix: increase chunk size 10kb -> 100kb (#1652) 2024-12-01 19:42:40 -06:00
Ben-grmbl 7f77987d91 feat: detect sentry.io tokens in the new format (#1640)
sntrys_..., sntryu_...
2024-11-19 09:46:19 -06:00
Adam Moss 48a2e0e318 refactor: pre-commit hooks (#1627)
Signed-off-by: Adam Moss <2951486+adam-moss@users.noreply.github.com>
2024-11-05 12:05:21 -06:00
Ben-grmbl 4e303d0284 fix(easypost): only detect tokens of correct length (#1628) 2024-11-05 11:50:41 -06:00
Richard Gomez c1add1d268 feat(dir): continue on permission error (#1621) 2024-11-05 07:58:36 -06:00
amanda-friesen 202106a190 Add human readable description for curl rules (#1625)
Provides more context to the user than the base rule name.
2024-11-05 07:40:29 -06:00
Taiki Ono 8e94f98e92 Add option to include Line field in report (#1616)
Signed-off-by: Taiki Ono <taiki@finatext.com>
2024-10-31 15:51:53 -05:00
Zach dbb42a727d hm 2024-10-31 08:35:55 -05:00
Zachary Rice 259946000b Update README.md 2024-10-31 08:31:50 -05:00
Zachary Rice 8ffb980ee5 nop for stupid build 2024-10-31 08:30:57 -05:00
Oscar BlancoandRichard Gomez 4181ad647a Add new jira api token pattern (#1601)
* add new jira api token pattern

* Apply suggestions from code review

Co-authored-by: Richard Gomez <32133502+rgmz@users.noreply.github.com>

* apply comments from PR

* Apply suggestions from code review

Co-authored-by: Richard Gomez <32133502+rgmz@users.noreply.github.com>

* apply comments from PR

---------

Co-authored-by: Richard Gomez <32133502+rgmz@users.noreply.github.com>
2024-10-31 08:19:05 -05:00
Richard Gomez 48ea14bd47 feat: update global & generic allowlist (#1618) 2024-10-30 19:23:23 -05:00
81f0002845 fix(vault-service-token): ensure that TPS contains digits (#1614)
* fix(vault-service-token): ensure that TPS contains digits

Chances of randomly generating a 24 letter string without digits:
P = ( (26+26) / (26+26+10) ) ^ 24 = 1.46 %

* fixt

---------

Co-authored-by: Zachary Rice <zricer@protonmail.com>
Co-authored-by: Zachary Rice <zachary.rice@trufflesec.com>
2024-10-30 15:49:06 -05:00
Richard Gomez c11adc91ad Generate comprehensive secret samples (#1484)
* feat(config): comprehensive samples

* refactor(config): use new generate func

* chore(config): comment unsupported cases

* feat(config): enable '?=' case

* feat(config): enable '+=' case

* feat(config): enable escaped json case

* feat(config): enable '<' (xml) case

* feat(config): enable multiline yaml case

* chore(config): add comment case

* feat(config): add php cases

* feat(config): add java case

* chore(config): address review comments

* fix(config): prevent matching '=='

* feat(config): add URL cases

* chore(config): revert regex changes
To be tackled in separate PRs.
2024-10-30 09:34:21 -05:00
Ben-grmbl d1d9054ef0 fix(aws): detect token in url (#1615) 2024-10-30 08:21:14 -05:00
Ben-grmbl 5fe58bf0b0 fix(rules): entropy, uppercase in samples (#1593)
`go generate` was slightly flaky,
since the example true positive secrets for these rules
did not include uppercase letters
and/or the min entropy was just barely too high
2024-10-29 16:33:09 -05:00
Richard Gomez 5c2e8132f2 feat: tweak rules (#1608) 2024-10-29 01:47:12 -05:00
Richard Gomez 43fae355e6 feat(rules): create Octopus Deploy api key (#1602) 2024-10-28 08:25:25 -05:00
Ben-grmbl a158e4fc15 fix(aws-access-token): only match if correct length (#1584)
Previously, the rule matched for any long string
containing e.g. ASIA, ACCA somewhere,
as long as the next 16 chars were also uppercase letters.

This change checks for word boundaries before and after the secret.

Also the prefix (AKIA|ASIA|...) was moved from the non-capturing group
into the secret matching group,
since it is part of the token

fix(aws-access-token): non-capture for prefix

Review findings https://github.com/gitleaks/gitleaks/pull/1584/files#r1807793907
2024-10-28 08:19:48 -05:00
Richard Gomez b6e0eeeb0a fix(config): ignore jquery/swagger w/o version (#1607) 2024-10-28 08:18:42 -05:00
Roger Meier 722e7d8e73 feat: add new GitLab tokens (#1560)
Closes #1401
2024-10-28 08:15:36 -05:00
Richard Gomez 961f2e674f feat(generic-api-key): tune false positives (#1606) 2024-10-27 19:24:06 -05:00
Zachary Rice e734fcf01d Create .gitleaks.toml (#1605) 2024-10-27 08:01:40 -05:00
Richard Gomez 7206d6bc56 feat(curl): tweak tps and fps (#1603) 2024-10-27 07:43:55 -05:00
Richard Gomez 2db25f1367 feat(config): ignore swagger-ui assets (#1604)
also, ignore public known checkmarx secret
2024-10-27 07:43:14 -05:00
Ben-grmbl e97695b852 feat(generic-api-key): exclude keywords (#1587)
* fix(config.tmpl) missing \n for rules with regexes AND stopwords

patch provided by rgmx

fix(config.tmpl) omit `condition=OR`

* feat(generic-api-key): exclude keywords

prevent matching the rule generic-api-key on e.g.
- public_key
- api_version
- client_id
- client_name
- keyword
- monkey

feat(generic-api-key): review findings

- combine capture groups
- remove mapKey from allowList

fix(generic): make monkey, donkey, case-sensitive

avoids matching on e.g. pokemonKey=

* feat(generic) remove client, add credential

exclude more composite words with key
2024-10-25 15:26:00 -05:00
Richard Gomez 0afb525e59 feat(okta): bump entropy to 4 (#1599) 2024-10-25 08:00:59 -05:00
Richard Gomez 2068870c8d feat: update global allowlist (#1597) 2024-10-24 08:17:27 -05:00
Richard Gomez 8cf93b9ad5 refactor(allowlist): deduplicate commits & keywords (#1596) 2024-10-24 07:28:55 -05:00
Richard Gomez 50c2818167 feat(config): ignore jquery static assets (#1595) 2024-10-23 07:30:48 -05:00
Richard Gomez 455ae0aab7 More rule fixes (#1586)
* feat: tweak more rules

* fix(curl): update pattern & ignore more stuff

* chore: update .gitleaksignore
2024-10-22 08:23:47 -05:00
Richard Gomez 5407c44e0c chore: log skipped symlinks (#1591) 2024-10-22 08:23:10 -05:00
Richard Gomez d03d6c401b feat: match left side of identifier (#1585) 2024-10-20 09:38:18 -05:00
Zach 851c11ab1a what secrets? 2024-10-19 19:58:07 -05:00
Richard Gomez 8cfa6b2e43 fix(rules): add entropy (#1580) 2024-10-19 19:49:36 -05:00
Richard Gomez 9152eaa57a feat(aws): add entropy & allowlist (#1582) 2024-10-19 19:47:45 -05:00
Richard Gomez 93acc6e82a feat(rules): add 1password token (#1583) 2024-10-19 19:47:07 -05:00
Richard Gomez 83a57244cd feat(config): add curl header rule (#1576) 2024-10-18 20:06:31 -05:00
Richard Gomez cf5334fd61 feat: add curl basic auth rule (#1575) 2024-10-17 19:15:30 -05:00
ReRetriever d07b394b08 Update spelling in README.md (#1574) 2024-10-17 10:53:30 -05:00
Richard Gomez 5c03fa4a3e refactor(allowlist): use iota for condition (#1569) 2024-10-16 14:59:37 -05:00
Richard Gomez 12034a71c5 refactor(config): temporarily switch to [rules.allowlist] (#1573) 2024-10-16 14:49:34 -05:00
Richard Gomez aabe381539 Define multiple allowlists per rule (#1496)
* feat: multiple rule allowlists

* feat(config): add allowlist 'condition'
2024-10-14 19:17:37 -05:00
Richard Gomez 8ea608595c build: upgrade gitleaks/go-gitdiff to v0.9.1 (#1559) 2024-10-13 06:46:44 -05:00
Rebecca Turner be9d0f8930 Fix rule extension (#1556)
* Reimplement the ability to override built-in rules

PR #1524 broke the ability to specify a `[[rules]]` with the same ID as
a built-in rule in order to extend the default configuration.

This PR restores this ability, but merges the provided configuration
with the default rule instead of overwriting the default rule wholesale.

* Add tests

* Append keywords and tags
2024-10-10 16:50:29 -05:00
Richard Gomez 9988e5224c Update base config allowlist (#1555)
* feat(config): add String fmt placeholders

* feat(config): ignore font files

* feat(config): ignore repeated characters
2024-10-10 02:05:16 -05:00
Richard Gomez 8fb39ba8dc feat(azure): detect Azure AD client secrets (#1199) 2024-10-09 06:44:19 -05:00
Richard Gomez 14c924dd02 chore: match gitleaks.toml anywhere (#1553) 2024-10-08 09:39:44 -05:00
201 changed files with 5161 additions and 2032 deletions

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
# This is NOT the default gitleaks config. The default gitleaks config is located
# here: https://github.com/gitleaks/gitleaks/blob/master/config/gitleaks.toml
# This gitleaks config extends the default config and ignores secrets located in the `cmd/generate/config/rules`
title = "Gitleaks development"
[extend]
useDefault = true
[allowlist]
paths = [
'''(^|/)cmd/generate/config/rules''',
]
+171
View File
@@ -767,3 +767,174 @@ adf617b3b4628e1160fa3d135b4c3dfd45c05e15:testdata/repos/small/api/ignoreGlobal.g
adf617b3b4628e1160fa3d135b4c3dfd45c05e15:testdata/repos/small/api/ignoreCommit.go:aws-access-token:20 adf617b3b4628e1160fa3d135b4c3dfd45c05e15:testdata/repos/small/api/ignoreCommit.go:aws-access-token:20
f361c5ef71853923277e3f284890083bc7825205:detect/reader_test.go:aws-access-token:12 f361c5ef71853923277e3f284890083bc7825205:detect/reader_test.go:aws-access-token:12
8cfa6b2e43544895f52d2e37535ccfe29a6cdfd3:cmd/generate/config/rules/infracost.go:infracost-api-token:24
8cfa6b2e43544895f52d2e37535ccfe29a6cdfd3:cmd/generate/config/rules/infracost.go:generic-api-key:29
8cfa6b2e43544895f52d2e37535ccfe29a6cdfd3:cmd/generate/config/rules/discord.go:discord-client-secret:64
8cfa6b2e43544895f52d2e37535ccfe29a6cdfd3:cmd/generate/config/rules/grafana.go:grafana-cloud-api-token:42
8cfa6b2e43544895f52d2e37535ccfe29a6cdfd3:cmd/generate/config/rules/grafana.go:grafana-service-account-token:80
9152eaa57a91d7249bd0b3c3a86b9e837072a828:detect/reader_test.go:aws-access-token:12
9152eaa57a91d7249bd0b3c3a86b9e837072a828:cmd/generate/config/rules/aws.go:aws-access-token:42
93acc6e82adb46ef442fcb44bd9fd83489690ca3:cmd/generate/config/rules/1password.go:1password-service-account-token:25
93acc6e82adb46ef442fcb44bd9fd83489690ca3:cmd/generate/config/rules/1password.go:1password-service-account-token:27
93acc6e82adb46ef442fcb44bd9fd83489690ca3:cmd/generate/config/rules/1password.go:1password-service-account-token:28
93acc6e82adb46ef442fcb44bd9fd83489690ca3:cmd/generate/config/rules/1password.go:generic-api-key:37
83a57244cdd0bfe1634326ab04a29b9b139bf158:cmd/generate/config/rules/curl.go:openai-api-key:125
83a57244cdd0bfe1634326ab04a29b9b139bf158:cmd/generate/config/rules/curl.go:curl-auth-header:100
83a57244cdd0bfe1634326ab04a29b9b139bf158:cmd/generate/config/rules/curl.go:curl-auth-header:102
83a57244cdd0bfe1634326ab04a29b9b139bf158:cmd/generate/config/rules/curl.go:curl-auth-header:108
83a57244cdd0bfe1634326ab04a29b9b139bf158:cmd/generate/config/rules/curl.go:curl-auth-header:112
83a57244cdd0bfe1634326ab04a29b9b139bf158:cmd/generate/config/rules/curl.go:curl-auth-header:121
83a57244cdd0bfe1634326ab04a29b9b139bf158:cmd/generate/config/rules/curl.go:curl-auth-header:122
83a57244cdd0bfe1634326ab04a29b9b139bf158:cmd/generate/config/rules/curl.go:curl-auth-header:123
83a57244cdd0bfe1634326ab04a29b9b139bf158:cmd/generate/config/rules/curl.go:curl-auth-header:126
83a57244cdd0bfe1634326ab04a29b9b139bf158:cmd/generate/config/rules/curl.go:curl-auth-header:131
83a57244cdd0bfe1634326ab04a29b9b139bf158:cmd/generate/config/rules/curl.go:curl-auth-header:134
83a57244cdd0bfe1634326ab04a29b9b139bf158:cmd/generate/config/rules/curl.go:curl-auth-header:137
83a57244cdd0bfe1634326ab04a29b9b139bf158:cmd/generate/config/rules/curl.go:curl-auth-header:137
83a57244cdd0bfe1634326ab04a29b9b139bf158:cmd/generate/config/rules/curl.go:generic-api-key:139
83a57244cdd0bfe1634326ab04a29b9b139bf158:cmd/generate/config/rules/curl.go:jwt:134
83a57244cdd0bfe1634326ab04a29b9b139bf158:cmd/generate/config/rules/curl.go:jwt:170
cf5334fd61d16fb4af1362856ebfb98397c5d4b3:cmd/generate/config/rules/curl.go:curl-auth-user:32
cf5334fd61d16fb4af1362856ebfb98397c5d4b3:cmd/generate/config/rules/curl.go:curl-auth-user:33
cf5334fd61d16fb4af1362856ebfb98397c5d4b3:cmd/generate/config/rules/curl.go:curl-auth-user:40
cf5334fd61d16fb4af1362856ebfb98397c5d4b3:cmd/generate/config/rules/curl.go:curl-auth-user:42
cf5334fd61d16fb4af1362856ebfb98397c5d4b3:cmd/generate/config/rules/curl.go:curl-auth-user:43
cf5334fd61d16fb4af1362856ebfb98397c5d4b3:cmd/generate/config/rules/curl.go:curl-auth-user:44
cf5334fd61d16fb4af1362856ebfb98397c5d4b3:cmd/generate/config/rules/curl.go:curl-auth-user:45
aabe3815394d24d5b8198ba6068a99e0ba7601b1:config/config_test.go:aws-access-token:72
b9f7fdaacb9e3799a9b3e4f7f6181963b8931b73:config/config_test.go:aws-access-token:67
3ef444d24677c863bb724fa406dd12464b7f2362:config/config_test.go:aws-access-token:39
8fb39ba8dc9d872d57cc3151b3750e8234b9b980:cmd/generate/config/rules/azure.go:azure-ad-client-secret:33
2278a2a97e422c8075207d17195b29e7f4ff15e1:detect/decoder_test.go:generic-api-key:22
2278a2a97e422c8075207d17195b29e7f4ff15e1:detect/decoder_test.go:generic-api-key:32
2278a2a97e422c8075207d17195b29e7f4ff15e1:detect/decoder_test.go:generic-api-key:37
2278a2a97e422c8075207d17195b29e7f4ff15e1:detect/decoder_test.go:generic-api-key:54
2278a2a97e422c8075207d17195b29e7f4ff15e1:detect/decoder_test.go:generic-api-key:59
2278a2a97e422c8075207d17195b29e7f4ff15e1:detect/decoder_test.go:generic-api-key:64
2278a2a97e422c8075207d17195b29e7f4ff15e1:detect/detect_test.go:private-key:23
2278a2a97e422c8075207d17195b29e7f4ff15e1:detect/detect_test.go:generic-api-key:39
2278a2a97e422c8075207d17195b29e7f4ff15e1:detect/detect_test.go:jwt:32
2278a2a97e422c8075207d17195b29e7f4ff15e1:detect/detect_test.go:private-key:365
2278a2a97e422c8075207d17195b29e7f4ff15e1:detect/detect_test.go:private-key:366
2278a2a97e422c8075207d17195b29e7f4ff15e1:detect/detect_test.go:private-key:368
2278a2a97e422c8075207d17195b29e7f4ff15e1:detect/detect_test.go:private-key:393
2278a2a97e422c8075207d17195b29e7f4ff15e1:detect/detect_test.go:private-key:394
2278a2a97e422c8075207d17195b29e7f4ff15e1:detect/detect_test.go:aws-access-token:407
2278a2a97e422c8075207d17195b29e7f4ff15e1:detect/detect_test.go:aws-access-token:408
2278a2a97e422c8075207d17195b29e7f4ff15e1:detect/detect_test.go:generic-api-key:452
f8dcd838da26f591c70acbbc3dea8d8b4d1649c7:detect/detect_test.go:generic-api-key:616
f8dcd838da26f591c70acbbc3dea8d8b4d1649c7:detect/detect_test.go:generic-api-key:618
f8dcd838da26f591c70acbbc3dea8d8b4d1649c7:testdata/repos/nogit/.env.prod:generic-api-key:4
032c47e7e1ebfb745d3b66ef448697d4cbf6a406:detect/detect_test.go:generic-api-key:38
032c47e7e1ebfb745d3b66ef448697d4cbf6a406:detect/detect_test.go:generic-api-key:451
6c5e01c144b3d5e48422ab66a353f4cbdc14b24a:detect/detect_test.go:private-key:22
6c5e01c144b3d5e48422ab66a353f4cbdc14b24a:detect/detect_test.go:jwt:31
6c5e01c144b3d5e48422ab66a353f4cbdc14b24a:detect/decoder_test.go:generic-api-key:22
6c5e01c144b3d5e48422ab66a353f4cbdc14b24a:detect/decoder_test.go:generic-api-key:32
6c5e01c144b3d5e48422ab66a353f4cbdc14b24a:detect/decoder_test.go:generic-api-key:37
6c5e01c144b3d5e48422ab66a353f4cbdc14b24a:detect/decoder_test.go:generic-api-key:54
6c5e01c144b3d5e48422ab66a353f4cbdc14b24a:detect/decoder_test.go:generic-api-key:59
6c5e01c144b3d5e48422ab66a353f4cbdc14b24a:detect/decoder_test.go:generic-api-key:64
6c5e01c144b3d5e48422ab66a353f4cbdc14b24a:detect/detect_test.go:private-key:359
6c5e01c144b3d5e48422ab66a353f4cbdc14b24a:detect/detect_test.go:private-key:360
6c5e01c144b3d5e48422ab66a353f4cbdc14b24a:detect/detect_test.go:private-key:362
6c5e01c144b3d5e48422ab66a353f4cbdc14b24a:detect/detect_test.go:private-key:387
6c5e01c144b3d5e48422ab66a353f4cbdc14b24a:detect/detect_test.go:private-key:388
6c5e01c144b3d5e48422ab66a353f4cbdc14b24a:detect/detect_test.go:aws-access-token:401
6c5e01c144b3d5e48422ab66a353f4cbdc14b24a:detect/detect_test.go:aws-access-token:402
78f7d3f5dfba03f816418f987ff3a78643c1eda7:cmd/generate/config/rules/flyio.go:flyio-access-token:26
78f7d3f5dfba03f816418f987ff3a78643c1eda7:cmd/generate/config/rules/flyio.go:flyio-access-token:30
78f7d3f5dfba03f816418f987ff3a78643c1eda7:cmd/generate/config/rules/flyio.go:flyio-access-token:34
78f7d3f5dfba03f816418f987ff3a78643c1eda7:cmd/generate/config/rules/flyio.go:flyio-access-token:37
78f7d3f5dfba03f816418f987ff3a78643c1eda7:cmd/generate/config/rules/flyio.go:flyio-access-token:38
3698060a2bcf926b8ae459270d9bcb7b69339104:cmd/generate/config/rules/kubernetes.go:generic-api-key:56
3698060a2bcf926b8ae459270d9bcb7b69339104:cmd/generate/config/rules/kubernetes.go:generic-api-key:68
3698060a2bcf926b8ae459270d9bcb7b69339104:cmd/generate/config/rules/kubernetes.go:generic-api-key:79
3698060a2bcf926b8ae459270d9bcb7b69339104:cmd/generate/config/rules/kubernetes.go:generic-api-key:147
3698060a2bcf926b8ae459270d9bcb7b69339104:cmd/generate/config/rules/kubernetes.go:generic-api-key:153
3698060a2bcf926b8ae459270d9bcb7b69339104:cmd/generate/config/rules/kubernetes.go:generic-api-key:162
5740eddd75b2a1149374438afe80c7cf2535b35f:README.md:aws-access-token:221
5740eddd75b2a1149374438afe80c7cf2535b35f:README.md:aws-access-token:223
5740eddd75b2a1149374438afe80c7cf2535b35f:README.md:aws-access-token:259
5740eddd75b2a1149374438afe80c7cf2535b35f:cmd/generate/config/rules/generic.go:clojars-api-token:42
372d99cfdb92a1e177badbfc1cd65bd692df9025:cmd/generate/config/rules/hashicorp.go:hashicorp-tf-api-token:24
372d99cfdb92a1e177badbfc1cd65bd692df9025:cmd/generate/config/rules/vault.go:vault-service-token:22
372d99cfdb92a1e177badbfc1cd65bd692df9025:cmd/generate/config/rules/vault.go:vault-service-token:25
3be7faa1ffc80f1aa071192a09141d5e829e1af3:cmd/generate/config/rules/vault.go:vault-service-token:22
3be7faa1ffc80f1aa071192a09141d5e829e1af3:cmd/generate/config/rules/hashicorp.go:hashicorp-tf-api-token:24
3be7faa1ffc80f1aa071192a09141d5e829e1af3:cmd/generate/config/rules/vault.go:vault-service-token:25
840c3cb24dcf14bf3332793f0702e75085ff5de2:detect/verify_test.go:generic-api-key:39
840c3cb24dcf14bf3332793f0702e75085ff5de2:detect/verify_test.go:generic-api-key:47
840c3cb24dcf14bf3332793f0702e75085ff5de2:detect/verify_test.go:generic-api-key:88
c1345e1b2b63260d860637530ba4d17571d547d6:cmd/generate/config/rules/openshift.go:openshift-user-token:27
c1345e1b2b63260d860637530ba4d17571d547d6:cmd/generate/config/rules/openshift.go:openshift-user-token:28
821b2323940b1792d9001d0812a2a4f7480a69c0:cmd/generate/config/rules/cloudflare.go:cloudflare-origin-ca-key:20
821b2323940b1792d9001d0812a2a4f7480a69c0:cmd/generate/config/rules/cloudflare.go:cloudflare-origin-ca-key:21
e265bfbbc3b208a23f0e46dd4a96795817068b77:detect/validate_test.go:generic-api-key:93
9d06c40017ba6710032e9bc08ebbc056175629cf:detect/validate_test.go:github-pat:33
9d06c40017ba6710032e9bc08ebbc056175629cf:detect/validate_test.go:github-pat:36
9d06c40017ba6710032e9bc08ebbc056175629cf:detect/validate_test.go:generic-api-key:43
9d06c40017ba6710032e9bc08ebbc056175629cf:detect/validate_test.go:generic-api-key:49
9d06c40017ba6710032e9bc08ebbc056175629cf:detect/validate_test.go:generic-api-key:57
e9135cf0b598738b5fc63ca004db8ab30845393d:cmd/generate/config/rules/jwt.go:jwt:48
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-organization-api-token:85
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-organization-api-token:86
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-organization-api-token:87
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-organization-api-token:88
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-organization-api-token:89
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-organization-api-token:90
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-organization-api-token:91
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-organization-api-token:93
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-organization-api-token:95
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-organization-api-token:96
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-organization-api-token:97
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-access-token:30
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-access-token:31
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-access-token:32
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-access-token:33
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-access-token:34
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-access-token:35
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-access-token:36
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-access-token:37
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-access-token:38
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-access-token:39
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-access-token:40
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-access-token:41
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-access-token:42
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-access-token:43
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-access-token:45
9fb36b242d75aac1a2bf885724dfd9886db08ea7:cmd/generate/config/rules/huggingface.go:huggingface-access-token:46
463d24618fa42fc7629dc30c9744ebe36c5df1ab:cmd/generate/config/rules/slack.go:slack-user-token:66
463d24618fa42fc7629dc30c9744ebe36c5df1ab:cmd/generate/config/rules/slack.go:slack-config-access-token:115
463d24618fa42fc7629dc30c9744ebe36c5df1ab:cmd/generate/config/rules/slack.go:slack-legacy-workspace-token:210
025908808f2ad1ce244f9806b8dd593bd9afbab0:detect/detect_test.go:discord-api-token:326
e002920355ac91770a329cfa69d6359bd665ba66:cmd/generate/config/rules/privatekey.go:private-key:26
e890a8e8098ee8021d25a429315a6c153126db22:cmd/generate/config/rules/jwt.go:jwt:17
9326f35380636bcbe61e94b0584d1618c4b5c2c2:detect/detect_test.go:pypi-upload-token:27
9326f35380636bcbe61e94b0584d1618c4b5c2c2:detect/detect_test.go:pypi-upload-token:32
9326f35380636bcbe61e94b0584d1618c4b5c2c2:detect/detect_test.go:pypi-upload-token:33
3a3e13c3b5f85b0116cf2a0cd92529baf22d0ac9:testdata/repos/with_square_and_google/env:gcp-api-key:3
45c898c5ea56ee503a048c1bac1404cf63855edc:test_data/test_repos/test_dir_2/env:gcp-api-key:3
45c898c5ea56ee503a048c1bac1404cf63855edc:test_data/test_dir_one_google_leak_and_square_leak.json:gcp-api-key:20
45c898c5ea56ee503a048c1bac1404cf63855edc:test_data/test_dir_one_google_leak_and_square_leak.json:gcp-api-key:22
f6460a7365479a48581e0641b40147914542bb24:test_data/test_local_owner_aws_leak_depth_2.json:aws-access-token:16
f6460a7365479a48581e0641b40147914542bb24:test_data/test_local_owner_aws_leak_depth_2.json:aws-access-token:17
f6460a7365479a48581e0641b40147914542bb24:test_data/test_local_owner_aws_leak_depth_2.json:aws-access-token:42
f6460a7365479a48581e0641b40147914542bb24:test_data/test_local_owner_aws_leak_depth_2.json:aws-access-token:43
f6460a7365479a48581e0641b40147914542bb24:test_data/test_local_owner_aws_leak_depth_2.json:aws-access-token:68
f6460a7365479a48581e0641b40147914542bb24:test_data/test_local_owner_aws_leak_depth_2.json:aws-access-token:69
f6460a7365479a48581e0641b40147914542bb24:test_data/test_local_owner_aws_leak_depth_2.json:aws-access-token:94
f6460a7365479a48581e0641b40147914542bb24:test_data/test_local_owner_aws_leak_depth_2.json:aws-access-token:95
7bd55e33b504f76fc2aec27f4f479a5fb2606480:src/constants.go:private-key:42
e79ffc6ae8f66931d687407e07bc0632fb262091:src/constants.go:private-key:29
2b995fda446e03b7660c327fec41265f03199c71:config.go:private-key:34
ccef3680d5552443c999345567ea60909c863c0a:checks_test.go:aws-access-token:52
1cecd5e0908ab581f217ebb2cb58829204530c79:README.md:aws-access-token:25
1cecd5e0908ab581f217ebb2cb58829204530c79:README.md:aws-access-token:27
e56870aecf8ac2733affc82e1ac25e3be9092db3:cmd/generate/config/rules/curl.go:generic-api-key:116
239e6323639b18ba8a1081f17788a658da075dd7:cmd/generate/config/rules/sumologic.go:sumologic-access-token:72
239e6323639b18ba8a1081f17788a658da075dd7:cmd/generate/config/rules/sumologic.go:sumologic-access-id:40
239e6323639b18ba8a1081f17788a658da075dd7:cmd/generate/config/rules/readme.go:readme-api-token:26
239e6323639b18ba8a1081f17788a658da075dd7:cmd/generate/config/rules/prefect.go:prefect-api-token:26
239e6323639b18ba8a1081f17788a658da075dd7:cmd/generate/config/rules/databricks.go:databricks-api-token:25
239e6323639b18ba8a1081f17788a658da075dd7:cmd/generate/config/rules/databricks.go:generic-api-key:22
+3 -3
View File
@@ -1,16 +1,16 @@
- id: gitleaks - id: gitleaks
name: Detect hardcoded secrets name: Detect hardcoded secrets
description: Detect hardcoded secrets using Gitleaks description: Detect hardcoded secrets using Gitleaks
entry: gitleaks protect --verbose --redact --staged entry: gitleaks git --pre-commit --redact --staged --verbose
language: golang language: golang
pass_filenames: false pass_filenames: false
- id: gitleaks-docker - id: gitleaks-docker
name: Detect hardcoded secrets name: Detect hardcoded secrets
description: Detect hardcoded secrets using Gitleaks description: Detect hardcoded secrets using Gitleaks
entry: zricethezav/gitleaks protect --verbose --redact --staged entry: zricethezav/gitleaks git --pre-commit --redact --staged --verbose
language: docker_image language: docker_image
- id: gitleaks-system - id: gitleaks-system
name: Detect hardcoded secrets name: Detect hardcoded secrets
description: Detect hardcoded secrets using Gitleaks description: Detect hardcoded secrets using Gitleaks
entry: gitleaks protect --verbose --redact --staged entry: gitleaks git --pre-commit --redact --staged --verbose
language: system language: system
+4 -1
View File
@@ -49,7 +49,10 @@ If you want to add a new rule to the [default Gitleaks configuration](https://gi
tps := []string{ tps := []string{
generateSampleSecret("beamer", "b_"+secrets.NewSecret(alphaNumericExtended("44"))), generateSampleSecret("beamer", "b_"+secrets.NewSecret(alphaNumericExtended("44"))),
} }
return validate(r, tps, nil) fps := []string{
`R21A-A-V010SP13RC181024R16900-CN-B_250K-Release-OTA-97B6C6C59241976086FABDC41472150C.bfu`,
}
return validate(r, tps, fps)
} }
``` ```
+2 -2
View File
@@ -1,8 +1,8 @@
FROM golang:1.22 AS build FROM golang:1.23 AS build
WORKDIR /go/src/github.com/zricethezav/gitleaks WORKDIR /go/src/github.com/zricethezav/gitleaks
COPY . . COPY . .
RUN VERSION=$(git describe --tags --abbrev=0) && \ RUN VERSION=$(git describe --tags --abbrev=0) && \
CGO_ENABLED=0 go build -o bin/gitleaks -ldflags "-X="github.com/zricethezav/gitleaks/v8/cmd.Version=${VERSION} CGO_ENABLED=0 go build -o bin/gitleaks -ldflags "-X=github.com/zricethezav/gitleaks/v8/cmd.Version=${VERSION}"
FROM alpine:3.19 FROM alpine:3.19
RUN apk add --no-cache bash git openssh-client RUN apk add --no-cache bash git openssh-client
+87 -46
View File
@@ -19,15 +19,12 @@
<a href="https://github.com/gitleaks/gitleaks-action"> <a href="https://github.com/gitleaks/gitleaks-action">
<img alt="gitleaks badge" src="https://img.shields.io/badge/protected%20by-gitleaks-blue"> <img alt="gitleaks badge" src="https://img.shields.io/badge/protected%20by-gitleaks-blue">
</a> </a>
<a href="https://twitter.com/intent/follow?screen_name=zricethezav">
<img src="https://img.shields.io/twitter/follow/zricethezav?label=Follow%20zricethezav&style=social&color=blue" alt="Follow @zricethezav" />
</a>
</p> </p>
</p> </p>
### Join our Discord! [![Discord](https://img.shields.io/discord/1102689410522284044.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/8Hzbrnkr7E) ### Join our Discord! [![Discord](https://img.shields.io/discord/1102689410522284044.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/8Hzbrnkr7E)
Gitleaks is a SAST tool for **detecting** and **preventing** hardcoded secrets like passwords, API keys, and tokens in git repos. Gitleaks is an **easy-to-use, all-in-one solution** for detecting secrets, past or present, in your code. Gitleaks is a tool for **detecting** secrets like passwords, API keys, and tokens in git repos, files, and whatever else you wanna throw at it via `stdin`.
``` ```
➜ ~/code(master) gitleaks git -v ➜ ~/code(master) gitleaks git -v
@@ -164,6 +161,7 @@ Flags:
--redact uint[=100] redact secrets from logs and stdout. To redact only parts of the secret just apply a percent value from 0..100. For example --redact=20 (default 100%) --redact uint[=100] redact secrets from logs and stdout. To redact only parts of the secret just apply a percent value from 0..100. For example --redact=20 (default 100%)
-f, --report-format string output format (json, csv, junit, sarif) (default "json") -f, --report-format string output format (json, csv, junit, sarif) (default "json")
-r, --report-path string report file -r, --report-path string report file
--report-template string template file used to generate the report (implies --report-format=template)
-v, --verbose show verbose output from scan -v, --verbose show verbose output from scan
--version version for gitleaks --version version for gitleaks
@@ -237,6 +235,8 @@ useDefault = true
# or you can supply a path to a configuration. Path is relative to where gitleaks # or you can supply a path to a configuration. Path is relative to where gitleaks
# was invoked, not the location of the base config. # was invoked, not the location of the base config.
path = "common_config.toml" path = "common_config.toml"
# If there are any rules you don't want to inherit, they can be specified here.
disabledRules = [ "generic-api-key"]
# An array of tables that contain information that define instructions # An array of tables that contain information that define instructions
# on how to detect secrets # on how to detect secrets
@@ -252,13 +252,6 @@ description = "awesome rule 1"
# does not support lookaheads. # does not support lookaheads.
regex = '''one-go-style-regex-for-this-rule''' regex = '''one-go-style-regex-for-this-rule'''
# Golang regular expression used to match paths. This can be used as a standalone rule or it can be used
# in conjunction with a valid `regex` entry.
path = '''a-file-path-regex'''
# Array of strings used for metadata and reporting purposes.
tags = ["tag","another tag"]
# Int used to extract secret from regex match and used as the group that will have # Int used to extract secret from regex match and used as the group that will have
# its entropy checked if `entropy` is set. # its entropy checked if `entropy` is set.
secretGroup = 3 secretGroup = 3
@@ -266,10 +259,14 @@ secretGroup = 3
# Float representing the minimum shannon entropy a regex group must have to be considered a secret. # Float representing the minimum shannon entropy a regex group must have to be considered a secret.
entropy = 3.5 entropy = 3.5
# Golang regular expression used to match paths. This can be used as a standalone rule or it can be used
# in conjunction with a valid `regex` entry.
path = '''a-file-path-regex'''
# Keywords are used for pre-regex check filtering. Rules that contain # Keywords are used for pre-regex check filtering. Rules that contain
# keywords will perform a quick string compare check to make sure the # keywords will perform a quick string compare check to make sure the
# keyword(s) are in the content being scanned. Ideally these values should # keyword(s) are in the content being scanned. Ideally these values should
# either be part of the idenitifer or unique strings specific to the rule's regex # either be part of the identiifer or unique strings specific to the rule's regex
# (introduced in v8.6.0) # (introduced in v8.6.0)
keywords = [ keywords = [
"auth", "auth",
@@ -277,29 +274,40 @@ keywords = [
"token", "token",
] ]
# You can include an allowlist table for a single rule to reduce false positives or ignore commits # Array of strings used for metadata and reporting purposes.
# with known/rotated secrets tags = ["tag","another tag"]
[rules.allowlist]
description = "ignore commit A" # ⚠️ In v8.21.0 `[rules.allowlist]` was replaced with `[[rules.allowlists]]`.
commits = [ "commit-A", "commit-B"] # This change was backwards-compatible: instances of `[rules.allowlist]` still work.
paths = [ #
'''go\.mod''', # You can define multiple allowlists for a rule to reduce false positives.
'''go\.sum''' # A finding will be ignored if _ANY_ `[[rules.allowlists]]` matches.
] [[rules.allowlists]]
# note: (rule) regexTarget defaults to check the _Secret_ in the finding. description = "ignore commit A"
# if regexTarget is not specified then _Secret_ will be used. # When multiple criteria are defined the default condition is "OR".
# Acceptable values for regexTarget are "match" and "line" # e.g., this can match on |commits| OR |paths| OR |stopwords|.
regexTarget = "match" condition = "OR"
regexes = [ commits = [ "commit-A", "commit-B"]
'''process''', paths = [
'''getenv''', '''go\.mod''',
] '''go\.sum'''
# note: stopwords targets the extracted secret, not the entire regex match ]
# like 'regexes' does. (stopwords introduced in 8.8.0) # note: stopwords targets the extracted secret, not the entire regex match
stopwords = [ # like 'regexes' does. (stopwords introduced in 8.8.0)
'''client''', stopwords = [
'''endpoint''', '''client''',
] '''endpoint''',
]
[[rules.allowlists]]
# The "AND" condition can be used to make sure all criteria match.
# e.g., this matches if |regexes| AND |paths| are satisfied.
condition = "AND"
# note: |regexes| defaults to check the _Secret_ in the finding.
# Acceptable values for |regexTarget| are "secret" (default), "match", and "line".
regexTarget = "match"
regexes = [ '''(?i)parseur[il]''' ]
paths = [ '''package-lock\.json''' ]
# You can extend a particular rule from the default config. e.g., gitlab-pat # You can extend a particular rule from the default config. e.g., gitlab-pat
# if you have defined a custom token prefix on your GitLab instance # if you have defined a custom token prefix on your GitLab instance
@@ -307,11 +315,9 @@ stopwords = [
id = "gitlab-pat" id = "gitlab-pat"
# all the other attributes from the default rule are inherited # all the other attributes from the default rule are inherited
[rules.allowlist] [[rules.allowlists]]
regexTarget = "line" regexTarget = "line"
regexes = [ regexes = [ '''MY-glpat-''' ]
'''MY-glpat-''',
]
# This is a global allowlist which has a higher order of precedence than rule-specific allowlists. # This is a global allowlist which has a higher order of precedence than rule-specific allowlists.
# If a commit listed in the `commits` field below is encountered then that commit will be skipped and no # If a commit listed in the `commits` field below is encountered then that commit will be skipped and no
@@ -328,7 +334,6 @@ paths = [
# if regexTarget is not specified then _Secret_ will be used. # if regexTarget is not specified then _Secret_ will be used.
# Acceptable values for regexTarget are "match" and "line" # Acceptable values for regexTarget are "match" and "line"
regexTarget = "match" regexTarget = "match"
regexes = [ regexes = [
'''219-09-9999''', '''219-09-9999''',
'''078-05-1120''', '''078-05-1120''',
@@ -388,6 +393,47 @@ Currently supported encodings:
- `base64` (both standard and base64url) - `base64` (both standard and base64url)
#### Reporting
Gitleaks has built-in support for several report formats: [`json`](https://github.com/gitleaks/gitleaks/blob/master/testdata/expected/report/json_simple.json), [`csv`](https://github.com/gitleaks/gitleaks/blob/master/testdata/expected/report/csv_simple.csv?plain=1), [`junit`](https://github.com/gitleaks/gitleaks/blob/master/testdata/expected/report/junit_simple.xml), and [`sarif`](https://github.com/gitleaks/gitleaks/blob/master/testdata/expected/report/sarif_simple.sarif).
If none of these formats fit your need, you can create your own report format with a [Go `text/template` .tmpl file](https://www.digitalocean.com/community/tutorials/how-to-use-templates-in-go#step-4-writing-a-template) and the `--report-template` flag. The template can use [extended functionality from the `Masterminds/sprig` template library](https://masterminds.github.io/sprig/).
For example, the following template provides a custom JSON output:
```gotemplate
# jsonextra.tmpl
[{{ $lastFinding := (sub (len . ) 1) }}
{{- range $i, $finding := . }}{{with $finding}}
{
"Description": {{ quote .Description }},
"StartLine": {{ .StartLine }},
"EndLine": {{ .EndLine }},
"StartColumn": {{ .StartColumn }},
"EndColumn": {{ .EndColumn }},
"Line": {{ quote .Line }},
"Match": {{ quote .Match }},
"Secret": {{ quote .Secret }},
"File": "{{ .File }}",
"SymlinkFile": {{ quote .SymlinkFile }},
"Commit": {{ quote .Commit }},
"Entropy": {{ .Entropy }},
"Author": {{ quote .Author }},
"Email": {{ quote .Email }},
"Date": {{ quote .Date }},
"Message": {{ quote .Message }},
"Tags": [{{ $lastTag := (sub (len .Tags ) 1) }}{{ range $j, $tag := .Tags }}{{ quote . }}{{ if ne $j $lastTag }},{{ end }}{{ end }}],
"RuleID": {{ quote .RuleID }},
"Fingerprint": {{ quote .Fingerprint }}
}{{ if ne $i $lastFinding }},{{ end }}
{{- end}}{{ end }}
]
```
Usage:
```sh
$ gitleaks dir ~/leaky-repo/ --report-path "report.json" --report-format template --report-template testdata/report/jsonextra.tmpl
```
## Sponsorships ## Sponsorships
<p align="left"> <p align="left">
@@ -396,11 +442,6 @@ Currently supported encodings:
<img alt="CodeRabbit.ai Sponsorship" src="https://github.com/gitleaks/gitleaks/assets/15034943/76c30a85-887b-47ca-9956-17a8e55c6c41" width=200> <img alt="CodeRabbit.ai Sponsorship" src="https://github.com/gitleaks/gitleaks/assets/15034943/76c30a85-887b-47ca-9956-17a8e55c6c41" width=200>
</a> </a>
</p> </p>
<p align="left">
<a href="https://www.tines.com/?utm_source=oss&utm_medium=sponsorship&utm_campaign=gitleaks">
<img alt="Tines Sponsorship" src="https://user-images.githubusercontent.com/15034943/146411864-4878f936-b4f7-49a0-b625-f9f40c704bfa.png" width=200>
</a>
</p>
## Exit Codes ## Exit Codes
+22 -18
View File
@@ -22,9 +22,9 @@ import (
"os" "os"
"time" "time"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/zricethezav/gitleaks/v8/logging"
"github.com/zricethezav/gitleaks/v8/report" "github.com/zricethezav/gitleaks/v8/report"
"github.com/zricethezav/gitleaks/v8/sources" "github.com/zricethezav/gitleaks/v8/sources"
) )
@@ -48,7 +48,7 @@ var detectCmd = &cobra.Command{
func runDetect(cmd *cobra.Command, args []string) { func runDetect(cmd *cobra.Command, args []string) {
source, err := cmd.Flags().GetString("source") source, err := cmd.Flags().GetString("source")
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("could not get source") logging.Fatal().Err(err).Msg("could not get source")
} }
initConfig(source) initConfig(source)
@@ -62,10 +62,14 @@ func runDetect(cmd *cobra.Command, args []string) {
detector := Detector(cmd, cfg, source) detector := Detector(cmd, cfg, source)
// set follow symlinks flag
if detector.FollowSymlinks, err = cmd.Flags().GetBool("follow-symlinks"); err != nil {
logging.Fatal().Err(err).Msg("")
}
// set exit code // set exit code
exitCode, err := cmd.Flags().GetInt("exit-code") exitCode, err := cmd.Flags().GetInt("exit-code")
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("could not get exit code") logging.Fatal().Err(err).Msg("could not get exit code")
} }
// determine what type of scan: // determine what type of scan:
@@ -73,32 +77,37 @@ func runDetect(cmd *cobra.Command, args []string) {
// - no-git: scan files by treating the repo as a plain directory // - no-git: scan files by treating the repo as a plain directory
noGit, err := cmd.Flags().GetBool("no-git") noGit, err := cmd.Flags().GetBool("no-git")
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("could not call GetBool() for no-git") logging.Fatal().Err(err).Msg("could not call GetBool() for no-git")
} }
fromPipe, err := cmd.Flags().GetBool("pipe") fromPipe, err := cmd.Flags().GetBool("pipe")
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("could not call GetBool() for pipe") logging.Fatal().Err(err).Msg("could not call GetBool() for pipe")
} }
// start the detector scan // start the detector scan
if noGit { if noGit {
var paths <-chan sources.ScanTarget var paths <-chan sources.ScanTarget
paths, err = sources.DirectoryTargets(source, detector.Sema, detector.FollowSymlinks) paths, err = sources.DirectoryTargets(
source,
detector.Sema,
detector.FollowSymlinks,
detector.Config.Allowlist.PathAllowed,
)
if err != nil { if err != nil {
log.Fatal().Err(err) logging.Fatal().Err(err)
} }
findings, err = detector.DetectFiles(paths) findings, err = detector.DetectFiles(paths)
if err != nil { if err != nil {
// don't exit on error, just log it // don't exit on error, just log it
log.Error().Err(err).Msg("failed scan directory") logging.Error().Err(err).Msg("failed scan directory")
} }
} else if fromPipe { } else if fromPipe {
findings, err = detector.DetectReader(os.Stdin, 10) findings, err = detector.DetectReader(os.Stdin, 10)
if err != nil { if err != nil {
// log fatal to exit, no need to continue since a report // log fatal to exit, no need to continue since a report
// will not be generated when scanning from a pipe...for now // will not be generated when scanning from a pipe...for now
log.Fatal().Err(err).Msg("failed scan input from stdin") logging.Fatal().Err(err).Msg("failed scan input from stdin")
} }
} else { } else {
var ( var (
@@ -107,23 +116,18 @@ func runDetect(cmd *cobra.Command, args []string) {
) )
logOpts, err = cmd.Flags().GetString("log-opts") logOpts, err = cmd.Flags().GetString("log-opts")
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("could not call GetString() for log-opts") logging.Fatal().Err(err).Msg("could not call GetString() for log-opts")
} }
gitCmd, err = sources.NewGitLogCmd(source, logOpts) gitCmd, err = sources.NewGitLogCmd(source, logOpts)
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("could not create Git cmd") logging.Fatal().Err(err).Msg("could not create Git cmd")
} }
findings, err = detector.DetectGit(gitCmd) findings, err = detector.DetectGit(gitCmd)
if err != nil { if err != nil {
// don't exit on error, just log it // don't exit on error, just log it
log.Error().Err(err).Msg("failed to scan Git repository") logging.Error().Err(err).Msg("failed to scan Git repository")
} }
} }
// set follow symlinks flag findingSummaryAndExit(detector, findings, exitCode, start, err)
if detector.FollowSymlinks, err = cmd.Flags().GetBool("follow-symlinks"); err != nil {
log.Fatal().Err(err).Msg("")
}
findingSummaryAndExit(findings, cmd, cfg, exitCode, start, err)
} }
+15 -6
View File
@@ -3,9 +3,9 @@ package cmd
import ( import (
"time" "time"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/zricethezav/gitleaks/v8/logging"
"github.com/zricethezav/gitleaks/v8/report" "github.com/zricethezav/gitleaks/v8/report"
"github.com/zricethezav/gitleaks/v8/sources" "github.com/zricethezav/gitleaks/v8/sources"
) )
@@ -45,23 +45,32 @@ func runDirectory(cmd *cobra.Command, args []string) {
detector := Detector(cmd, cfg, source) detector := Detector(cmd, cfg, source)
// set follow symlinks flag
if detector.FollowSymlinks, err = cmd.Flags().GetBool("follow-symlinks"); err != nil {
logging.Fatal().Err(err).Msg("")
}
// set exit code // set exit code
exitCode, err := cmd.Flags().GetInt("exit-code") exitCode, err := cmd.Flags().GetInt("exit-code")
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("could not get exit code") logging.Fatal().Err(err).Msg("could not get exit code")
} }
var paths <-chan sources.ScanTarget var paths <-chan sources.ScanTarget
paths, err = sources.DirectoryTargets(source, detector.Sema, detector.FollowSymlinks) paths, err = sources.DirectoryTargets(
source,
detector.Sema,
detector.FollowSymlinks,
detector.Config.Allowlist.PathAllowed,
)
if err != nil { if err != nil {
log.Fatal().Err(err) logging.Fatal().Err(err)
} }
findings, err = detector.DetectFiles(paths) findings, err = detector.DetectFiles(paths)
if err != nil { if err != nil {
// don't exit on error, just log it // don't exit on error, just log it
log.Error().Err(err).Msg("failed scan directory") logging.Error().Err(err).Msg("failed scan directory")
} }
findingSummaryAndExit(findings, cmd, cfg, exitCode, start, err) findingSummaryAndExit(detector, findings, exitCode, start, err)
} }
+50 -29
View File
@@ -1,8 +1,11 @@
package base package base
import ( import (
"fmt"
"strings"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
"regexp"
) )
func CreateGlobalConfig() config.Config { func CreateGlobalConfig() config.Config {
@@ -13,6 +16,27 @@ func CreateGlobalConfig() config.Config {
Regexes: []*regexp.Regexp{ Regexes: []*regexp.Regexp{
// ----------- General placeholders ----------- // ----------- General placeholders -----------
regexp.MustCompile(`(?i)^true|false|null$`), regexp.MustCompile(`(?i)^true|false|null$`),
// Awkward workaround to detect repeated characters.
func() *regexp.Regexp {
var (
letters = "abcdefghijklmnopqrstuvwxyz*."
patterns []string
)
for _, char := range letters {
if char == '*' || char == '.' {
patterns = append(patterns, fmt.Sprintf("\\%c+", char))
} else {
patterns = append(patterns, fmt.Sprintf("%c+", char))
}
}
return regexp.MustCompile("^(?i:" + strings.Join(patterns, "|") + ")$")
}(),
// ----------- Environment Variables -----------
regexp.MustCompile(`^\$(\d+|{\d+})$`),
regexp.MustCompile(`^\$([A-Z_]+|[a-z_]+)$`),
regexp.MustCompile(`^\${([A-Z_]+|[a-z_]+)}$`),
// ----------- Interpolated Variables ----------- // ----------- Interpolated Variables -----------
// Ansible (https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html) // Ansible (https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html)
regexp.MustCompile(`^\{\{[ \t]*[\w ().|]+[ \t]*}}$`), regexp.MustCompile(`^\{\{[ \t]*[\w ().|]+[ \t]*}}$`),
@@ -22,25 +46,26 @@ func CreateGlobalConfig() config.Config {
regexp.MustCompile(`^\$\{\{[ \t]*((env|github|secrets|vars)(\.[A-Za-z]\w+)+[\w "'&./=|]*)[ \t]*}}$`), regexp.MustCompile(`^\$\{\{[ \t]*((env|github|secrets|vars)(\.[A-Za-z]\w+)+[\w "'&./=|]*)[ \t]*}}$`),
// NuGet (https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file#using-environment-variables) // NuGet (https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file#using-environment-variables)
regexp.MustCompile(`^%([A-Z_]+|[a-z_]+)%$`), regexp.MustCompile(`^%([A-Z_]+|[a-z_]+)%$`),
// String formatting.
regexp.MustCompile(`^%[+\-# 0]?[bcdeEfFgGoOpqstTUvxX]$`), // Golang (https://pkg.go.dev/fmt)
regexp.MustCompile(`^\{\d{0,2}}$`), // Python (https://docs.python.org/3/tutorial/inputoutput.html)
// Urban Code Deploy (https://www.ibm.com/support/pages/replace-token-step-replaces-replacement-values-windows-variables) // Urban Code Deploy (https://www.ibm.com/support/pages/replace-token-step-replaces-replacement-values-windows-variables)
regexp.MustCompile(`^@([A-Z_]+|[a-z_]+)@$`), regexp.MustCompile(`^@([A-Z_]+|[a-z_]+)@$`),
// ----------- Environment Variables ----------- // ----------- Miscellaneous -----------
regexp.MustCompile(`^\$(\d+|{\d+})$`),
regexp.MustCompile(`^\$([A-Z_]+|[a-z_]+)$`),
regexp.MustCompile(`^\${([A-Z_]+|[a-z_]+)}$`),
}, },
Paths: []*regexp.Regexp{ Paths: []*regexp.Regexp{
regexp.MustCompile(`^gitleaks\.toml$`), regexp.MustCompile(`gitleaks\.toml`),
// ----------- Documents and media ----------- // ----------- Documents and media -----------
regexp.MustCompile(`(?i)\.(bmp|gif|jpe?g|svg|tiff?)$`), regexp.MustCompile(`(?i)\.(bmp|gif|jpe?g|svg|tiff?)$`), // Images
regexp.MustCompile(`\.(eot|[ot]tf|woff2?)$`), // Fonts
regexp.MustCompile(`(.*?)(doc|docx|zip|xls|pdf|bin|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe|gltf)$`), regexp.MustCompile(`(.*?)(doc|docx|zip|xls|pdf|bin|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe|gltf)$`),
// ----------- Golang files ----------- // ----------- Golang files -----------
regexp.MustCompile(`go\.(mod|sum|work(\.sum)?)$`), regexp.MustCompile(`go\.(mod|sum|work(\.sum)?)$`),
regexp.MustCompile(`(^|/)vendor/modules\.txt$`), regexp.MustCompile(`(^|/)vendor/modules\.txt$`),
regexp.MustCompile(`(^|/)vendor/(github\.com|golang\.org/x|google\.golang\.org|gopkg\.in|istio\.io|k8s\.io|sigs\.k8s\.io)/.*$`), regexp.MustCompile(`(^|/)vendor/(github\.com|golang\.org/x|google\.golang\.org|gopkg\.in|istio\.io|k8s\.io|sigs\.k8s\.io)(/.*)?$`),
// ----------- Java files ----------- // ----------- Java files -----------
// Gradle // Gradle
@@ -49,41 +74,37 @@ func CreateGlobalConfig() config.Config {
regexp.MustCompile(`(^|/)mvnw(\.cmd)?$`), regexp.MustCompile(`(^|/)mvnw(\.cmd)?$`),
regexp.MustCompile(`(^|/)\.mvn/wrapper/MavenWrapperDownloader\.java$`), regexp.MustCompile(`(^|/)\.mvn/wrapper/MavenWrapperDownloader\.java$`),
// ----------- Node.js files ----------- // ----------- JavaScript files -----------
// Dependencies and lock files. // Dependencies and lock files.
regexp.MustCompile(`(^|/)node_modules/.*?$`), regexp.MustCompile(`(^|/)node_modules(/.*)?$`),
regexp.MustCompile(`(^|/)package-lock\.json$`), regexp.MustCompile(`(^|/)(npm-shrinkwrap\.json|package-lock\.json|pnpm-lock\.yaml|yarn\.lock)$`),
regexp.MustCompile(`(^|/)yarn\.lock$`), regexp.MustCompile(`(^|/)bower_components(/.*)?$`),
regexp.MustCompile(`(^|/)pnpm-lock\.yaml$`), // TODO: Add more common static assets, such as swagger-ui.
regexp.MustCompile(`(^|/)npm-shrinkwrap\.json$`), regexp.MustCompile(`(^|/)(angular|jquery(-?ui)?|plotly|swagger-?ui)[a-zA-Z0-9.-]*(\.min)?\.js(\.map)?$`),
regexp.MustCompile(`(^|/)bower_components/.*?$`),
// ----------- Python files ----------- // ----------- Python files -----------
// Dependencies and lock files. // Dependencies and lock files.
regexp.MustCompile(`(^|/)Pipfile\.lock$`), regexp.MustCompile(`(^|/)(Pipfile|poetry)\.lock$`),
regexp.MustCompile(`(^|/)poetry\.lock$`),
// Virtual environments // Virtual environments
// env/lib/python3.7/site-packages/urllib3/util/url.py regexp.MustCompile(`(?i)/?(v?env|virtualenv)/lib(64)?(/.*)?$`),
regexp.MustCompile(`(?i)/?(v?env|virtualenv)/lib/.+$`), regexp.MustCompile(`(?i)(^|/)(lib(64)?/python[23](\.\d{1,2})+|python/[23](\.\d{1,2})+/lib(64)?)(/.*)?$`),
// /python/3.7.4/Lib/site-packages/dask/bytes/tests/test_bytes_utils.py
// python/3.7.4/Lib/site-packages/fsspec/utils.py
// python/2.7.16.32/Lib/bsddb/test/test_dbenv.py
regexp.MustCompile(`(?i)/?python/[23](\.\d{1,2})+/lib/.+$`),
// python/lib/python3.8/site-packages/boto3/data/ec2/2016-04-01/resources-1.json
// python/lib/python3.8/site-packages/botocore/data/alexaforbusiness/2017-11-09/service-2.json
regexp.MustCompile(`(?i)/?python/lib/python[23](\.\d{1,2})+/.+$`),
// dist-info directory (https://py-pkgs.org/04-package-structure.html#building-sdists-and-wheels) // dist-info directory (https://py-pkgs.org/04-package-structure.html#building-sdists-and-wheels)
regexp.MustCompile(`(?i)(^|/)[a-z0-9_.]+-[0-9.]+\.dist-info/.+$`), regexp.MustCompile(`(?i)(^|/)[a-z0-9_.]+-[0-9.]+\.dist-info(/.+)?$`),
// ----------- Ruby files ----------- // ----------- Ruby files -----------
regexp.MustCompile(`(^|/)vendor/(bundle|ruby)/.*?$`), regexp.MustCompile(`(^|/)vendor/(bundle|ruby)(/.*?)?$`),
regexp.MustCompile(`\.gem$`), // tar archive regexp.MustCompile(`\.gem$`), // tar archive
// Misc // Misc
regexp.MustCompile(`verification-metadata.xml`), regexp.MustCompile(`verification-metadata\.xml`),
regexp.MustCompile(`Database.refactorlog`), regexp.MustCompile(`Database.refactorlog`),
//regexp.MustCompile(`vendor`), //regexp.MustCompile(`vendor`),
}, },
StopWords: []string{
// ----------- Secrets -----------
// Checkmarx client secret. (https://github.com/checkmarx-ts/checkmarx-python-sdk/blob/86560f6e2a3e46d16322101294da10d5d190312d/README.md?plain=1#L56)
"014df517-39d1-4453-b7b3-9930c563627c",
},
}, },
} }
} }
+80 -4
View File
@@ -14,6 +14,16 @@ func TestConfigAllowlistRegexes(t *testing.T) {
`true`, `True`, `false`, `False`, `null`, `NULL`, `true`, `True`, `false`, `False`, `null`, `NULL`,
}, },
}, },
"general placeholders - repeated characters": {
invalid: []string{
`aaaaaaaaaaaaaaaaa`, `BBBBBBBBBBbBBBBBBBbBB`, `********************`,
},
valid: []string{`aaaaaaaaaaaaaaaaaaabaa`, `pas*************d`},
},
"environment variables": {
invalid: []string{`$2`, `$GIT_PASSWORD`, `${GIT_PASSWORD}`, `$password`},
valid: []string{`$yP@R.@=ibxI`, `$2a6WCust9aE`, `${not_complete1`},
},
"interpolated variables - ansible": { "interpolated variables - ansible": {
invalid: []string{ invalid: []string{
`{{ x }}`, `{{ password }}`, `{{password}}`, `{{ data.proxy_password }}`, `{{ x }}`, `{{ password }}`, `{{password}}`, `{{ data.proxy_password }}`,
@@ -39,14 +49,20 @@ func TestConfigAllowlistRegexes(t *testing.T) {
`%MY_PASSWORD%`, `%password%`, `%MY_PASSWORD%`, `%password%`,
}, },
}, },
"interpolated variables - string fmt - golang": {
invalid: []string{
`%b`, `%c`, `%d`, `% d`, `%e`, `%E`, `%f`, `%F`, `%g`, `%G`, `%o`, `%O`, `%p`, `%q`, `%-s`, `%s`, `%t`, `%T`, `%U`, `%#U`, `%+v`, `%#v`, `%v`, `%x`, `%X`,
},
},
"interpolated variables - string fmt - python": {
invalid: []string{
`{}`, `{0}`, `{10}`,
},
},
"interpolated variables - ucd": { "interpolated variables - ucd": {
invalid: []string{`@password@`, `@LDAP_PASS@`}, invalid: []string{`@password@`, `@LDAP_PASS@`},
valid: []string{`@username@mastodon.example`}, valid: []string{`@username@mastodon.example`},
}, },
"environment variables": {
invalid: []string{`$2`, `$GIT_PASSWORD`, `${GIT_PASSWORD}`, `$password`},
valid: []string{`$yP@R.@=ibxI`, `$2a6WCust9aE`, `${not_complete1`},
},
} }
cfg := CreateGlobalConfig() cfg := CreateGlobalConfig()
@@ -67,3 +83,63 @@ func TestConfigAllowlistRegexes(t *testing.T) {
}) })
} }
} }
func TestConfigAllowlistPaths(t *testing.T) {
tests := map[string]struct {
invalid []string
valid []string
}{
"javascript - common static assets": {
invalid: []string{
`src/main/static/lib/angular.1.2.16.min.js`,
`src/main/resources/static/jquery-ui-1.12.1/jquery-ui-min.js`,
`src/main/resources/static/js/jquery-ui-1.10.4.min.js`,
`src-static/js/plotly.min.js`,
`swagger/swaggerui/swagger-ui-bundle.js.map`,
`swagger/swaggerui/swagger-ui-es-bundle.js.map`,
`src/main/static/swagger-ui.min.js`,
`swagger/swaggerui/swagger-ui.js`,
},
},
"python": {
invalid: []string{
// lock files
`Pipfile.lock`, `poetry.lock`,
// virtual environments
"env/lib/python3.7/site-packages/urllib3/util/url.py",
"venv/Lib/site-packages/regex-2018.08.29.dist-info/DESCRIPTION.rst",
"venv/lib64/python3.5/site-packages/pynvml.py",
"python/python3/virtualenv/Lib/site-packages/pyphonetics/utils.py",
"virtualenv/lib64/python3.7/base64.py",
// packages
"cde-root/usr/lib64/python2.4/site-packages/Numeric.pth",
"lib/python3.9/site-packages/setuptools/_distutils/msvccompiler.py",
"lib/python3.8/site-packages/botocore/data/alexaforbusiness/2017-11-09/service-2.json",
"code/python/3.7.4/Lib/site-packages/dask/bytes/tests/test_bytes_utils.py",
"python/3.7.4/Lib/site-packages/fsspec/utils.py",
"python/2.7.16.32/Lib/bsddb/test/test_dbenv.py",
"python/lib/python3.8/site-packages/boto3/data/ec2/2016-04-01/resources-1.json",
// distinfo
"libs/PyX-0.15.dist-info/AUTHORS",
},
},
}
cfg := CreateGlobalConfig()
allowlist := cfg.Allowlist
for name, cases := range tests {
t.Run(name, func(t *testing.T) {
for _, c := range cases.invalid {
if !allowlist.PathAllowed(c) {
t.Errorf("invalid path not marked as allowed: %s", c)
}
}
for _, c := range cases.valid {
if allowlist.PathAllowed(c) {
t.Errorf("valid path marked as allowed: %s", c)
}
}
})
}
}
+28 -8
View File
@@ -1,14 +1,13 @@
package main package main
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/base"
"os" "os"
"text/template" "text/template"
"github.com/rs/zerolog/log" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/base"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/rules" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/rules"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/logging"
) )
const ( const (
@@ -25,6 +24,7 @@ func main() {
gitleaksConfigPath := os.Args[1] gitleaksConfigPath := os.Args[1]
configRules := []*config.Rule{ configRules := []*config.Rule{
rules.OnePasswordServiceAccountToken(),
rules.AdafruitAPIKey(), rules.AdafruitAPIKey(),
rules.AdobeClientID(), rules.AdobeClientID(),
rules.AdobeClientSecret(), rules.AdobeClientSecret(),
@@ -38,6 +38,7 @@ func main() {
rules.Atlassian(), rules.Atlassian(),
rules.Authress(), rules.Authress(),
rules.AWS(), rules.AWS(),
rules.AzureActiveDirectoryClientSecret(),
rules.BitBucketClientID(), rules.BitBucketClientID(),
rules.BitBucketClientSecret(), rules.BitBucketClientSecret(),
rules.BittrexAccessKey(), rules.BittrexAccessKey(),
@@ -53,6 +54,8 @@ func main() {
rules.ConfluentAccessToken(), rules.ConfluentAccessToken(),
rules.ConfluentSecretKey(), rules.ConfluentSecretKey(),
rules.Contentful(), rules.Contentful(),
rules.CurlHeaderAuth(),
rules.CurlBasicAuth(),
rules.Databricks(), rules.Databricks(),
rules.DatadogtokenAccessToken(), rules.DatadogtokenAccessToken(),
rules.DefinedNetworkingAPIToken(), rules.DefinedNetworkingAPIToken(),
@@ -85,6 +88,7 @@ func main() {
rules.FlutterwaveEncKey(), rules.FlutterwaveEncKey(),
rules.FlyIOAccessToken(), rules.FlyIOAccessToken(),
rules.FrameIO(), rules.FrameIO(),
rules.Freemius(),
rules.FreshbooksAccessToken(), rules.FreshbooksAccessToken(),
rules.GoCardless(), rules.GoCardless(),
// TODO figure out what makes sense for GCP // TODO figure out what makes sense for GCP
@@ -95,9 +99,20 @@ func main() {
rules.GitHubOauth(), rules.GitHubOauth(),
rules.GitHubApp(), rules.GitHubApp(),
rules.GitHubRefresh(), rules.GitHubRefresh(),
rules.GitlabCiCdJobToken(),
rules.GitlabDeployToken(),
rules.GitlabFeatureFlagClientToken(),
rules.GitlabFeedToken(),
rules.GitlabIncomingMailToken(),
rules.GitlabKubernetesAgentToken(),
rules.GitlabOauthAppSecret(),
rules.GitlabPat(), rules.GitlabPat(),
rules.GitlabPatRoutable(),
rules.GitlabPipelineTriggerToken(), rules.GitlabPipelineTriggerToken(),
rules.GitlabRunnerRegistrationToken(), rules.GitlabRunnerRegistrationToken(),
rules.GitlabRunnerAuthenticationToken(),
rules.GitlabScimToken(),
rules.GitlabSessionCookie(),
rules.GitterAccessToken(), rules.GitterAccessToken(),
rules.GrafanaApiKey(), rules.GrafanaApiKey(),
rules.GrafanaCloudApiToken(), rules.GrafanaCloudApiToken(),
@@ -142,6 +157,7 @@ func main() {
rules.NPM(), rules.NPM(),
rules.NugetConfigPassword(), rules.NugetConfigPassword(),
rules.NytimesAccessToken(), rules.NytimesAccessToken(),
rules.OctopusDeployApiKey(),
rules.OktaAccessToken(), rules.OktaAccessToken(),
rules.OpenAI(), rules.OpenAI(),
rules.OpenshiftUserToken(), rules.OpenshiftUserToken(),
@@ -166,6 +182,11 @@ func main() {
rules.SendGridAPIToken(), rules.SendGridAPIToken(),
rules.SendInBlueAPIToken(), rules.SendInBlueAPIToken(),
rules.SentryAccessToken(), rules.SentryAccessToken(),
rules.SentryOrgToken(),
rules.SentryUserToken(),
rules.SettlemintApplicationAccessToken(),
rules.SettlemintPersonalAccessToken(),
rules.SettlemintServiceAccessToken(),
rules.ShippoAPIToken(), rules.ShippoAPIToken(),
rules.ShopifyAccessToken(), rules.ShopifyAccessToken(),
rules.ShopifyCustomAccessToken(), rules.ShopifyCustomAccessToken(),
@@ -214,7 +235,7 @@ func main() {
for _, rule := range configRules { for _, rule := range configRules {
// check if rule is in ruleLookUp // check if rule is in ruleLookUp
if _, ok := ruleLookUp[rule.RuleID]; ok { if _, ok := ruleLookUp[rule.RuleID]; ok {
log.Fatal().Msgf("rule id %s is not unique", rule.RuleID) logging.Fatal().Msgf("rule id %s is not unique", rule.RuleID)
} }
// TODO: eventually change all the signatures to get ride of this // TODO: eventually change all the signatures to get ride of this
// nasty dereferencing. // nasty dereferencing.
@@ -223,18 +244,17 @@ func main() {
tmpl, err := template.ParseFiles(templatePath) tmpl, err := template.ParseFiles(templatePath)
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("Failed to parse template") logging.Fatal().Err(err).Msg("Failed to parse template")
} }
f, err := os.Create(gitleaksConfigPath) f, err := os.Create(gitleaksConfigPath)
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("Failed to create rules.toml") logging.Fatal().Err(err).Msg("Failed to create rules.toml")
} }
cfg := base.CreateGlobalConfig() cfg := base.CreateGlobalConfig()
cfg.Rules = ruleLookUp cfg.Rules = ruleLookUp
if err = tmpl.Execute(f, cfg); err != nil { if err = tmpl.Execute(f, cfg); err != nil {
log.Fatal().Err(err).Msg("could not execute template") logging.Fatal().Err(err).Msg("could not execute template")
} }
} }
+43
View File
@@ -0,0 +1,43 @@
package rules
import (
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
// https://developer.1password.com/docs/service-accounts/security/?token-example=encoded
func OnePasswordServiceAccountToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "1password-service-account-token",
Description: "Uncovered a possible 1Password service account token, potentially compromising access to secrets in vaults.",
Regex: regexp.MustCompile(`ops_eyJ[a-zA-Z0-9+/]{250,}={0,3}`),
Entropy: 4,
Keywords: []string{"ops_"},
}
// validate
tps := []string{
utils.GenerateSampleSecret("1password", secrets.NewSecret(`ops_eyJ[a-zA-Z0-9+/]{250,}={0,3}`)),
`### 1Password System Vault Name
export OP_SERVICE_ACCOUNT_TOKEN=ops_eyJzaWduSW5BZGRyZXNzIjoibXkuMXBhc3N3b3JkLmNvbSIsInVzZXJBdXRoIjp7Im1ldGhvZCI6IlNSUGctNDA5NiIsImFsZyI6IlBCRVMyZy1IUzI1NiIsIml0ZXJhdGlvbnMiOjY1MdAwMCwic2FsdCI6InE2dE0tYzNtRDhiNUp2OHh1YVzsUmcifSwiZW1haWwiOiJ5Z3hmcm0zb21oY3NtQDFwYXNzd29yZHNlcnZpY2VhY2NvdW50cy5jb20iLCJzcnBYIjoiM2E5NDdhZmZhMDQ5NTAxZjkxYzk5MGFiY2JiYWRlZjFjMjM5Y2Q3YTMxYmI1MmQyZjUzOTA2Y2UxOTA1OTYwYiIsIm11ayI6eyJhbGciOiJBMjU2R0NNIiwiZXh0Ijp0cnVlLCJrIjoiVVpleERsLVgyUWxpa0VqRjVUUjRoODhOd29ZcHRqSHptQmFTdlNrWGZmZyIsImtleV9vcHMiOlsiZW5jcnlwdCIsImRlY3J5cHQiXSwia3R5Ijoib2N0Iiwia2lkIjoibXAifSwic2VjcmV0S2V5IjoiQTMtNDZGUUVNLUVZS1hTQS1NUU0yUy04U0JSUS01QjZGUC1HS1k2ViIsInRocm90dGxlU2VjcmV0Ijp7InNlZWQiOiJjZmU2ZTU0NGUxZTlmY2NmZjJlYjBhYWZmYTEzNjZlMmE2ZmUwZDVlZGI2ZTUzOTVkZTljZmY0NDY3NDUxOGUxIiwidXVpZCI6IjNVMjRMNVdCNkpFQ0pEQlhJNFZOSTRCUzNRIn0sImRldmljZVV1aWQiOiJqaGVlY3F4cm41YTV6ZzRpMnlkbjRqd3U3dSJ9
`,
`PYTEST_SVC_ACCT_TOKEN=ops_eyJzaWduSW5BZGRyZXNzIjoiemFjaC1hbmQtbGVhbm5lLjFwYXNzd29yZC5jb20iLCJ1c2VyQXV0aCI6eyJtZXRob2QiOiJTUlBnLTQwOTYiLCJhbGciOiJQQkVLMmctSFMyNTYiLCJpdGVyYXRpb25zIjo2NTAwMDAsInNhbHQiOiJlYUZRQmNVemJyTHhnM2d4bHFQLVVBIn0sImVtYWlsIjoiMm9iNGRpeDdiNTdrYUAxcGFzc3dvcmRzZXJ2aWNlYWNjb3VudHMuY29tIiwic3JwWCI6ImVmZDY4YjNhZTkwMmRjZjRiMzEzYjE5MjYwZmY0OGUzMjU2ZDlhOGNkM2JmMmY3YzI2YzU1ZWJkNjZlZGU4NWEiLCJtdWsiOnsiYWxnIjoiQTI1NkdDTSIsImV4dCI6dHJ1ZSwiayI6IlMwaGE0SDhqbEhRblJCWmxvYnBmR1BneERmbS1pRGNkZWY0bFdYU0VSbmMiLCJrZXlfb3BzIjpbImRlY3J5cHQiLCJlbmNyeXB0Il0sImt0eSI6Im9jdCIsImtpZCI6Im1wIn0sInNlY3JldEtleSI6IkEzLUdHOUVRNi1LUzQ0QVctQU5QVkYtUkdQTDktQlNKUTMtR1NHR0giLCJ0aHJvdHRsZVNlY3JldCI6eyJzZWVkIjoiN2I0OTMxMmJiOTlkZTFiNjU5ODZkYzIzOWU4YWNmZWMxMTU0M2E2OGQxYmYwMjZmZTgzMjg3NWYxNmJlOWY2NiIsInV1aWQiOiJDV1RHQ0hMNlNWRkdSTlg0SzNENUJVSDZDSSJ9LCJkZXZpY2VVdWlkIjoiMnFld3JpaGtqbmt1Zmh6ZGdmZ2hnNmM1cGUifQ`,
` "sourceContent": "ops_eyJlbWFpbCI6ImVqd2U2NHFtbHhocmlAMXBhc3N3b3Jkc2VydmljZWFjY291bnRzLmxjbCIsIm11ayI6eyJhbGciOiJBMjU2R0NNIiwiZXh0Ijp0cnVlLCJrIjoiTThWUGZJYzhWRWZUaGNNWExhS0NLRjhzTWg1Sk1ac1BBdHU5MmZRTmItbyIsImtleV9vcHMiOlsiZW5jcnlwdCIsImRlY3J5cHQiXSwia3R5Ijoib2N0Iiwia2lkIjoibXAifSwic2VjcmV0S2V5IjoiQTMtQzRaSk1OLVBRVFpUTC1IR0w4NC1HNjRNNy1LVlpSTi00WlZQNiIsInNycFgiOiI4NzBkNjdhOWU2MjY2MjVkOWUzNjg1MDc4MDRjOWMzMmU2NjFjNTdlN2U1NTg3NzgyOTFiZjI5ZDVhMjc5YWUxIiwic2lnbkluQWRkcmVzcyI6ImdvdGhhbS5iNWxvY2FsLmNvbTo0MDAwIiwidXNlckF1dGgiOnsibWV0aG9kIjoiU1JQZy00MDk2IiwiYWxnIjoiUEJFUzJnLUhTMjU2IiwiaXRlcmF0aW9ucyI6MTAwMDAwLCJzYWx0IjoiRk1SVVBpeXJONFhmXzhIb2g2WVJYUSJ9fQ\n\nops_token is secret.\n",`,
}
fps := []string{
// Invalid
` login:
serviceAccountToken:
fn::secret: ops_eyJzaWduSW5B..[Redacted]`,
`: To start using this service account, run the following command:
:
: export OP_SERVICE_ACCOUNT_TOKEN=ops_eyJzaWduSW5BZGRyZXNzIjoiaHR0cHM6...`,
// Low entropy.
`ops_eyJxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`,
}
return utils.Validate(r, tps, fps)
}
+1 -3
View File
@@ -16,8 +16,6 @@ func AdafruitAPIKey() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("adafruit", secrets.NewSecret(utils.AlphaNumericExtendedShort("32")))
utils.GenerateSampleSecret("adafruit", secrets.NewSecret(utils.AlphaNumericExtendedShort("32"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+6 -6
View File
@@ -9,25 +9,25 @@ import (
func AdobeClientID() *config.Rule { func AdobeClientID() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Detected a pattern that resembles an Adobe OAuth Web Client ID, posing a risk of compromised Adobe integrations and data breaches.",
RuleID: "adobe-client-id", RuleID: "adobe-client-id",
Description: "Detected a pattern that resembles an Adobe OAuth Web Client ID, posing a risk of compromised Adobe integrations and data breaches.",
Regex: utils.GenerateSemiGenericRegex([]string{"adobe"}, utils.Hex("32"), true), Regex: utils.GenerateSemiGenericRegex([]string{"adobe"}, utils.Hex("32"), true),
Entropy: 2,
Keywords: []string{"adobe"}, Keywords: []string{"adobe"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("adobe", secrets.NewSecret(utils.Hex("32")))
utils.GenerateSampleSecret("adobe", secrets.NewSecret(utils.Hex("32"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func AdobeClientSecret() *config.Rule { func AdobeClientSecret() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Discovered a potential Adobe Client Secret, which, if exposed, could allow unauthorized Adobe service access and data manipulation.",
RuleID: "adobe-client-secret", RuleID: "adobe-client-secret",
Regex: utils.GenerateUniqueTokenRegex(`(p8e-)(?i)[a-z0-9]{32}`, true), Description: "Discovered a potential Adobe Client Secret, which, if exposed, could allow unauthorized Adobe service access and data manipulation.",
Regex: utils.GenerateUniqueTokenRegex(`p8e-(?i)[a-z0-9]{32}`, false),
Entropy: 2,
Keywords: []string{"p8e-"}, Keywords: []string{"p8e-"},
} }
+3 -5
View File
@@ -1,9 +1,9 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" regexp "github.com/wasilibs/go-re2"
"regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -17,8 +17,6 @@ func AgeSecretKey() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("age", `AGE-SECRET-KEY-1QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ`) // gitleaks:allow
`apiKey := "AGE-SECRET-KEY-1QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ`, // gitleaks:allow
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+1 -3
View File
@@ -16,8 +16,6 @@ func Airtable() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("airtable", secrets.NewSecret(utils.AlphaNumeric("17")))
utils.GenerateSampleSecret("airtable", secrets.NewSecret(utils.AlphaNumeric("17"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+1 -3
View File
@@ -16,8 +16,6 @@ func AlgoliaApiKey() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("algolia", secrets.NewSecret(utils.Hex("32")))
"algolia_key := " + secrets.NewSecret(utils.Hex("32")),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+8 -10
View File
@@ -9,9 +9,10 @@ import (
func AlibabaAccessKey() *config.Rule { func AlibabaAccessKey() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Detected an Alibaba Cloud AccessKey ID, posing a risk of unauthorized cloud resource access and potential data compromise.",
RuleID: "alibaba-access-key-id", RuleID: "alibaba-access-key-id",
Regex: utils.GenerateUniqueTokenRegex(`(LTAI)(?i)[a-z0-9]{20}`, true), Description: "Detected an Alibaba Cloud AccessKey ID, posing a risk of unauthorized cloud resource access and potential data compromise.",
Regex: utils.GenerateUniqueTokenRegex(`LTAI(?i)[a-z0-9]{20}`, false),
Entropy: 2,
Keywords: []string{"LTAI"}, Keywords: []string{"LTAI"},
} }
@@ -26,17 +27,14 @@ func AlibabaAccessKey() *config.Rule {
func AlibabaSecretKey() *config.Rule { func AlibabaSecretKey() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Discovered a potential Alibaba Cloud Secret Key, potentially allowing unauthorized operations and data access within Alibaba Cloud.",
RuleID: "alibaba-secret-key", RuleID: "alibaba-secret-key",
Regex: utils.GenerateSemiGenericRegex([]string{"alibaba"}, Description: "Discovered a potential Alibaba Cloud Secret Key, potentially allowing unauthorized operations and data access within Alibaba Cloud.",
utils.AlphaNumeric("30"), true), Regex: utils.GenerateSemiGenericRegex([]string{"alibaba"}, utils.AlphaNumeric("30"), true),
Entropy: 2,
Keywords: []string{"alibaba"}, Keywords: []string{"alibaba"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("alibaba", secrets.NewSecret(utils.AlphaNumeric("30")))
utils.GenerateSampleSecret("alibaba", secrets.NewSecret(utils.AlphaNumeric("30"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+2 -6
View File
@@ -16,9 +16,7 @@ func AsanaClientID() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("asana", secrets.NewSecret(utils.Numeric("16")))
utils.GenerateSampleSecret("asana", secrets.NewSecret(utils.Numeric("16"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -33,8 +31,6 @@ func AsanaClientSecret() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("asana", secrets.NewSecret(utils.AlphaNumeric("32")))
utils.GenerateSampleSecret("asana", secrets.NewSecret(utils.AlphaNumeric("32"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+15 -7
View File
@@ -11,15 +11,23 @@ func Atlassian() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Detected an Atlassian API token, posing a threat to project management and collaboration tool security and data confidentiality.", Description: "Detected an Atlassian API token, posing a threat to project management and collaboration tool security and data confidentiality.",
RuleID: "atlassian-api-token", RuleID: "atlassian-api-token",
Regex: utils.GenerateSemiGenericRegex([]string{ Regex: utils.MergeRegexps(
"atlassian", "confluence", "jira"}, utils.AlphaNumeric("24"), true), utils.GenerateSemiGenericRegex(
Keywords: []string{"atlassian", "confluence", "jira"}, []string{"atlassian", "confluence", "jira"},
`[a-zA-Z0-9]{24}`,
false,
),
utils.GenerateUniqueTokenRegex(`ATATT3[A-Za-z0-9_\-=]{186}`, false),
),
Entropy: 3.5,
Keywords: []string{"atlassian", "confluence", "jira", "atatt3"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("atlassian", secrets.NewSecret(utils.AlphaNumeric("24")))
utils.GenerateSampleSecret("atlassian", secrets.NewSecret(utils.AlphaNumeric("24"))), tps = append(tps, utils.GenerateSampleSecrets("confluence", secrets.NewSecret(utils.AlphaNumeric("24")))...)
utils.GenerateSampleSecret("confluence", secrets.NewSecret(utils.AlphaNumeric("24"))), tps = append(tps, utils.GenerateSampleSecrets("jira", secrets.NewSecret(utils.AlphaNumeric("24")))...)
} tps = append(tps, utils.GenerateSampleSecrets("jira", "ATATT3xFfGF0K3irG5tKKi-6u-wwaXQFeGwZ-IHR-hQ3CulkKtMSuteRQFfLZ6jihHThzZCg_UjnDt-4Wl_gIRf4zrZJs5JqaeuBhsfJ4W5GD6yGg3W7903gbvaxZPBjxIQQ7BgFDSkPS8oPispw4KLz56mdK-G6CIvLO6hHRrZHY0Q3tvJ6JxE=C63992E6")...)
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+5 -6
View File
@@ -2,8 +2,8 @@ package rules
import ( import (
"fmt" "fmt"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -12,9 +12,10 @@ func Authress() *config.Rule {
// Rule Definition // Rule Definition
// (Note: When changes are made to this, rerun `go generate ./...` and commit the config/gitleaks.toml file // (Note: When changes are made to this, rerun `go generate ./...` and commit the config/gitleaks.toml file
r := config.Rule{ r := config.Rule{
Description: "Uncovered a possible Authress Service Client Access Key, which may compromise access control services and sensitive data.",
RuleID: "authress-service-client-access-key", RuleID: "authress-service-client-access-key",
Regex: utils.GenerateUniqueTokenRegex(`(?:sc|ext|scauth|authress)_[a-z0-9]{5,30}\.[a-z0-9]{4,6}\.acc[_-][a-z0-9-]{10,32}\.[a-z0-9+/_=-]{30,120}`, true), Description: "Uncovered a possible Authress Service Client Access Key, which may compromise access control services and sensitive data.",
Regex: utils.GenerateUniqueTokenRegex(`(?:sc|ext|scauth|authress)_(?i)[a-z0-9]{5,30}\.[a-z0-9]{4,6}\.(?-i:acc)[_-][a-z0-9-]{10,32}\.[a-z0-9+/_=-]{30,120}`, false),
Entropy: 2,
Keywords: []string{"sc_", "ext_", "scauth_", "authress_"}, Keywords: []string{"sc_", "ext_", "scauth_", "authress_"},
} }
@@ -25,8 +26,6 @@ func Authress() *config.Rule {
account_id := "acc_" + utils.AlphaNumeric("10") account_id := "acc_" + utils.AlphaNumeric("10")
signature_key := utils.AlphaNumericExtendedShort("40") signature_key := utils.AlphaNumericExtendedShort("40")
tps := []string{ tps := utils.GenerateSampleSecrets("authress", secrets.NewSecret(fmt.Sprintf(`%s\.%s\.%s\.%s`, service_client_id, access_key_id, account_id, signature_key)))
utils.GenerateSampleSecret("authress", secrets.NewSecret(fmt.Sprintf(`%s\.%s\.%s\.%s`, service_client_id, access_key_id, account_id, signature_key))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+33 -11
View File
@@ -1,28 +1,50 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" regexp "github.com/wasilibs/go-re2"
"regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
func AWS() *config.Rule { func AWS() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Identified a pattern that may indicate AWS credentials, risking unauthorized cloud resource access and data breaches on AWS platforms.",
RuleID: "aws-access-token", RuleID: "aws-access-token",
Regex: regexp.MustCompile( Description: "Identified a pattern that may indicate AWS credentials, risking unauthorized cloud resource access and data breaches on AWS platforms.",
"(?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}"), Regex: regexp.MustCompile(`\b((?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16})\b`),
Entropy: 3,
Keywords: []string{ Keywords: []string{
"AKIA", // https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html#identifiers-unique-ids
"ASIA", "A3T", // todo: might not be a valid AWS token
"ABIA", "AKIA", // Access key
"ACCA", "ASIA", // Temporary (AWS STS) access key
"ABIA", // AWS STS service bearer token
"ACCA", // Context-specific credential
},
Allowlists: []config.Allowlist{
{
Regexes: []*regexp.Regexp{
regexp.MustCompile(`.+EXAMPLE$`),
},
},
}, },
} }
// validate // validate
tps := []string{utils.GenerateSampleSecret("AWS", "AKIALALEMEL33243OLIB")} // gitleaks:allow tps := utils.GenerateSampleSecrets("AWS", "AKIALALEMEL33243OLIB") // gitleaks:allow
return utils.Validate(r, tps, nil) // current AWS tokens cannot contain [0,1,8,9], so their entropy is slightly lower than expected.
tps = append(tps, utils.GenerateSampleSecrets("AWS", "AKIA"+secrets.NewSecret("[A-Z2-7]{16}"))...)
tps = append(tps, utils.GenerateSampleSecrets("AWS", "ASIA"+secrets.NewSecret("[A-Z2-7]{16}"))...)
tps = append(tps, utils.GenerateSampleSecrets("AWS", "ABIA"+secrets.NewSecret("[A-Z2-7]{16}"))...)
tps = append(tps, utils.GenerateSampleSecrets("AWS", "ACCA"+secrets.NewSecret("[A-Z2-7]{16}"))...)
fps := []string{
`key = AKIAXXXXXXXXXXXXXXXX`, // Low entropy
`aws_access_key: AKIAIOSFODNN7EXAMPLE`, // Placeholder
`msgstr "Näytä asiakirjamallikansio."`, // Lowercase
`TODAYINASIAASACKOFRICEFELLOVER`, // wrong length
`CTTCATAGGGTTCACGCTGTGTAAT-ACG--CCTGAGGC-CACA-AGGGGACTTCAGCAACCGTCGGG-GATTC-ATTGCCA-A--TGGAAGCAATC-TA-TGGGTTA-TCGCGGAGTCCGCAAAGACGGCCAGTATG-AAGCAGATTTCGCAC-CAATGTGACTGCATTTCGTG-ATCGGGGTAAGTA-TC-GCCGATTC-GC--CCGTCCA-AGT-CGAAG-TA--GGCAATATAAAGCTGC-CATTGCCGAAGCTATCTCGCTA-TACTTGAT-AATCGGCGG-TAG-CACAG-GTCGCAGTATCG-AC-T--AGG-CCTCTCAAAAGTT-GGGTCCCGGCCTCTGGGAAAAACACCTCT-A-AGCGTCAATCAGCTCGGTTTCGCATATTA-TGATATCCCCCGTTGACCAATTGA--TAGTACCCGAGCTTACCGTCGG-ATTCTGGAGTCTT-ATGAGGTTACCGACGA-CGCAGTACCATAAGT-GCGCAATTTGACTGTTCCCGTCGAGTAACCA-AGCTTTGCTCA-CCGGGATGCGCGCCGATGTGACCAGGGGGCGCATGTTACATTGAC-A-GCTGGATCATGTTATGAC-GTGGGTC-ATGCTAAAAGCCTAAAGGACGGT-GCATTAGTAT-TACCGGGACCTCATATCAATGCGCTCGCTAGTTCCTCTTCTCTTGATAACGTATATGCGTCAGGCGCCCGTCCGCCTCCAATACGTG-ACAACGTC-AGTACTGAGCCTC--AA-ACATCGTCTTGTTCG-CC-TACAAAGGATCGGTAGAAAACTCAATATTCGGGTATAAGGTCGTAGGAAGTGTGTCGCCCAGGGCCG-CTAGA-AGCGCACACAAGCG-CTCCTGTCAAGGAGTTG-GTGAAAA-ATGAAC--GACT-ATTGCGTCAC--CTACCTCT-AAGTTTTT-GACAATTTCATGGACGAATTGA-AGCGTCCACAAGCATCTGCCGTAGATATGCGGTAGGTTTTTACATATG-TCACTGCAGAGTCACGGACA-CACATCGCTGTCAAAATGCTCGTACCTAGT-GT-TTGCGATCCCCC-GCGGCATTA-TCTTTTGAACCCTCGTCCCTGTGG-CTCTGATGATTGAG-GTCTGTA-TTCCCTCGTTGTGGGGGGATTGGACCTT-TGTATAGGTTCTTTAACCG-ATGGGGGGCCG--ATCGA-A-TA-TGCTCCTGTTTGCCCCGAACCTT-ACCTCGG-TCCAGACA-CTAAGAAAAACCCC-C-ACTGTAAGGTGCTGAGCCTTTGGATAGCC-CGCGAATGAT-CC-TAGTTGACAA-CTGAACGCGCTCGAACA-TGCCC-GCCCTCTGA--CTGCTGTCTG-GCACCTTTAGACACGCGTCGAC-CATATATT-AGCGCTGTCTGTGG-AGGT-TGTGTCTTGTTGCTCA-CT-CATTATCTGT-AACTGGCTCC-CTC-CCAT-TGGCGTCTTTACACCAACCGCTAGGTTACAGTGCA-TCTAGCGCCTATTATCAGGGCGT-TTGCAGCGGCGCGGTGGCTATGT-GTTAGACATATC-CTTACACTGTATGCTAG-AGCAAGCCAC-TCTGAATGGGTTGC-CGATGAATGA-TCTTGATC-GAGCTCGCA-AC---TACATGGAGTCCGAAGTGAACCTACGGATGATCGTATTCCAACACGAGGATC-TATACGTATAGG-A-GGCG-TAATCCACAATTTAGTAACTCTTGACGC---GGATGAAAAT-GTCGTTACACCTTCCAGAGGCTCGG-GTATATATATGACCT--TGTGATTGAGGACGATCTAGAATAA-CT-GT-G-CT-AAAGTACAGTAGTTTCTATGT-GGTAGGTGGAGAATACAGAGTAG-ATGATTC-GTGGGCCACA-C--T-ACTTTCAT-TAGAGCAGAGA-C-GTGAGTGAGTTTTACACTAGCCAGATGGACCG-GTGA-AGTCTAACAGCCACCGCTT-GTGAGGTCGTTTCCCAGTC-ACCCTACTACAGGCAAAAACTCAGTGT-CC-GTGA-GTGCGTTAGTGATATTCCCTAACGGTTAGGTAACT-CATGAATTCA-AT-TAAGCGTGTCC-CGGT-CACGCCCCCATGGGGGCCTTCTTGGGAGG--AGCATCTTAT--AT-GCTCACGTGGTT-GATAGG-A-T-AATACACTTTTAGTCAGTCCATCAATAAC-AAAGGAAC---CAGGTGGTCGCAGATA-TCCCGCTGATATAGCACTGTGTAAACTCAGGTGATA-CTAAGC--GCTCTAAT-ACG-CTTAATGGCAATGCCCAGTTC--ACGACTAGCTTATGAGGCCCAGCTATGGACTGCGGC-GGCATGTCGGC-GATGGTTGCCCTCGCCCTAAATTATGTACGA-T-ACCGCCT-CTTGTTCT-CCGCCCATAGGGT-C--AGCAGGCGATAGACTCCCAGAAATTTCCTCGTCGT-CCGAATAAGACTAACACGACTA-TT-CCTCTAC-GT-G-AA-CTTATCA-CAAATG-GCT-TACC-TAGGTGGTGGCAGATCACTTTCCGGTG-TATTACGAATTGACGCATACCGAC-A-CGC-GCTTGTTGGATAATCGACTCTAACCTCCTCTCTGGCACATGT-GCTGGATTACCTC-TATTTT-TCTCGCTTAG--GGAACG-T-CCTCTGTCGCGTGAG-GTACGTTTCACGGGAG-CGGCTTGTTCATGCCACGTCCATTATCGA-AGTG-C-GTAAGG-A-GAGCCCTA--GACTCTACACGGAAA-TC-AAC-GTAGAAGGCTC-A-CT`,
}
return utils.Validate(r, tps, fps)
} }
+67
View File
@@ -0,0 +1,67 @@
package rules
import (
"fmt"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
)
// References:
// - https://learn.microsoft.com/en-us/microsoft-365/compliance/sit-defn-azure-ad-client-secret
// - https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app#add-credentials
func AzureActiveDirectoryClientSecret() *config.Rule {
// define rule
r := config.Rule{
RuleID: "azure-ad-client-secret",
Description: "Azure AD Client Secret",
// After inspecting dozens of secrets, I'm fairly confident that they start with `xxx\dQ~`.
// However, this may not be (entirely) true, and this rule might need to be further refined in the future.
// Furthermore, it's possible that secrets have a checksum that could be used to further constrain this pattern.
Regex: regexp.MustCompile(`(?:^|[\\'"\x60\s>=:(,)])([a-zA-Z0-9_~.]{3}\dQ~[a-zA-Z0-9_~.-]{31,34})(?:$|[\\'"\x60\s<),])`), // wtf, Go? https://github.com/golang/go/issues/18221
Entropy: 3,
Keywords: []string{
"Q~",
},
}
// validate
tps := []string{
`client_secret=bP88Q~rcBcYjzzOhg1Hnn76Wm3jGgakZiZ.8vMgR`, // gitleaks:allow
`client_secret=bP88Q~rcBcYjzzOhg1Hnn76Wm3jGgakZiZ.8vMgR
`, // gitleaks:allow
`client_secret: .IQ8Q~79R7TOWOspFnWcEG-dYt4KXqFqxK16cxr`, // gitleaks:allow
`AUTH_CLIENTSECRET = _V28Q~IC8qxmlWNpHuDm34JlbKv9LXV5MvUR3a-P`, // gitleaks:allow
`<value xsi:type="xsd:string">~Gg8Q~nVhlLi2vpg_nXBGqFsbGK-t~Hus1JmTa0y</value>`, // gitleaks:allow
`"CLIENT_SECRET": "YYz7Q~Sudoqwap1PnzEBA3zqBK~i5uesDIv.C"`, // gitleaks:allow
`Set-PSUAuthenticationMethod -Type 'OpenIDConnect' -CallbackPath '/auth/oidc' -ClientId 'fake' -ClientSecret '2Vq7Q~q5VgKljZ7cb3.0sp0Apz.vOjRIPyeTr'`, // gitleaks:allow
`client-secret: "t028Q~-aLbmQuinnZtzbgtlEAYstnBWEmGPAoBm"`, // gitleaks:allow
`"cas.authn.azure-active-directory.client-secret=qHF8Q~PCM5HhMoyTFc5TYEomnzR6Kim9UJhe8a.P",`, // gitleaks:allow
`"line": "client_srt = \"qpF8Q~PCM5MhMoyTFc5TYEomnYRUKim9UJhe8a2P\";",`, // gitleaks:allow
`"client_secret": acctest.Representation{RepType: acctest.Required, Create: 'dO29Q~F5-VwnW.lZdd11xFF_t5NAXCaGwDl9NbT1'},`, // gitleaks:allow
`Example= GN.7Q~4AkLZBNEbz4Jxlm~O5G6SsyFxYg6zMR`, // gitleaks:allow
`"the_value": "QtT8Q~9C-_Ij~RouHVpD2Tuf3oHWGh.DQ3kcjbAn"`, // gitleaks:allow
`QtT8Q~9C-_Ij~RouHVpD2Tuf3oHWGh.DQ3kcjbAn`, // gitleaks:allow
`(use the client secret: QtT8Q~9C-_Ij~RouHVpD2Tuf3oHWGh.DQ3kcjbAn)`, // gitleaks:allow
`(QtT8Q~9C-_Ij~RouHVpD2Tuf3oHWGh.DQ3kcjbAn)`, // gitleaks:allow
`\"pass\": \"` + fmt.Sprintf("%s%sQ~%s", secrets.NewSecret(`[\w~.]{3}`), secrets.NewSecret(utils.Numeric("1")), secrets.NewSecret(`[\w~.-]{31,34}`)),
}
fps := []string{
`![图源:《深入拆解Tomcat & Jetty》](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/6a9e704af49b4380bb686f0c96d33b81~tplv-k3u1fbpfcp-watermark.image)`,
`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`,
`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`,
`.ui.visible.right.sidebar~.ui.visible.left.sidebar~.pusher{transform:translate3d(0,0,0)}`,
`buf.WriteString("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n::\n\n")`,
`'url': 'http://www.2doc.nl/speel~VARA_101375237~mh17-het-verdriet-van-nederland~.html',`,
`@ar = split("~", "965f1453~47~09414c93e4cef985416f472549220827da3ba6fed8ad28e29ef6ad170ad53a69051e9b06f439ef6da5df8670181f7eb2481650");`,
`'#!/registries/5/portainer.demo~2Fportainerregistrytesting~2Falpine',`,
`// CloudFront-Signature: Ixn4bF1LLrLcB8XG-t5bZbIB0vfwSF2s4gkef~PcNBdx73MVvZD3v8DZ5GzcqNrybMiqdYJY5KqK6vTsf5JXDgwFFz-h98wdsbV-izcuonPdzMHp4Ay4qyXM6Ed5jB9dUWYGwMkA6rsWXpftfX8xmk4tG1LwFuJV6nAsx4cfpuKwo4vU2Hyr2-fkA7MZG8AHkpDdVUnjm1q-Re9HdG0nCq-2lnBAdOchBpJt37narOj-Zg6cbx~6rzQLVQd8XIv-Bn7VTc1tkBAJVtGOHb0Q~PLzSRmtNGYTnpL0z~gp3tq8lhZc2HuvJW5-tZaYP9yufeIzk5bqsT6DT4iDuclKKw__, , , false`,
`+ "<Trust Comment=\"\" Identity=\"USK@u2vn3Lh6Kte2-TgBSNKorbsKkuAt34ckoLmgx0ndXO0,4~q8Q~3wIHjX9DT0yCNfQmr9oxmYrDZoQVLOdNg~yk0,AQACAAE/WebOfTrustRC2/2\" Value=\"100\"/>"`,
`client_secret=bP88Q~xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`,
}
return utils.Validate(r, tps, fps)
}
+4 -3
View File
@@ -17,8 +17,9 @@ func Beamer() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("beamer", "b_"+secrets.NewSecret(utils.AlphaNumericExtended("44")))
utils.GenerateSampleSecret("beamer", "b_"+secrets.NewSecret(utils.AlphaNumericExtended("44"))), fps := []string{
`│   ├── R21A-A-V010SP13RC181024R16900-CN-B_250K-Release-OTA-97B6C6C59241976086FABDC41472150C.bfu`,
} }
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, fps)
} }
+2 -6
View File
@@ -16,9 +16,7 @@ func BitBucketClientID() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("bitbucket", secrets.NewSecret(utils.AlphaNumeric("32")))
utils.GenerateSampleSecret("bitbucket", secrets.NewSecret(utils.AlphaNumeric("32"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -33,8 +31,6 @@ func BitBucketClientSecret() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("bitbucket", secrets.NewSecret(utils.AlphaNumeric("64")))
utils.GenerateSampleSecret("bitbucket", secrets.NewSecret(utils.AlphaNumeric("64"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+2 -6
View File
@@ -16,9 +16,7 @@ func BittrexAccessKey() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("bittrex", secrets.NewSecret(utils.AlphaNumeric("32")))
utils.GenerateSampleSecret("bittrex", secrets.NewSecret(utils.AlphaNumeric("32"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -33,8 +31,6 @@ func BittrexSecretKey() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("bittrex", secrets.NewSecret(utils.AlphaNumeric("32")))
utils.GenerateSampleSecret("bittrex", secrets.NewSecret(utils.AlphaNumeric("32"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+7 -7
View File
@@ -1,25 +1,25 @@
package rules package rules
import ( import (
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
) )
func Clojars() *config.Rule { func Clojars() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Uncovered a possible Clojars API token, risking unauthorized access to Clojure libraries and potential code manipulation.",
RuleID: "clojars-api-token", RuleID: "clojars-api-token",
Description: "Uncovered a possible Clojars API token, risking unauthorized access to Clojure libraries and potential code manipulation.",
Regex: regexp.MustCompile(`(?i)CLOJARS_[a-z0-9]{60}`), Regex: regexp.MustCompile(`(?i)CLOJARS_[a-z0-9]{60}`),
Keywords: []string{"clojars"}, Entropy: 2,
Keywords: []string{"clojars_"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("clojars", "CLOJARS_"+secrets.NewSecret(utils.AlphaNumeric("60")))
utils.GenerateSampleSecret("clojars", "CLOJARS_"+secrets.NewSecret(utils.AlphaNumeric("60"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+15 -11
View File
@@ -2,6 +2,7 @@ package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -27,15 +28,16 @@ var identifiers = []string{"cloudflare"}
func CloudflareGlobalAPIKey() *config.Rule { func CloudflareGlobalAPIKey() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Detected a Cloudflare Global API Key, potentially compromising cloud application deployments and operational security.",
RuleID: "cloudflare-global-api-key", RuleID: "cloudflare-global-api-key",
Description: "Detected a Cloudflare Global API Key, potentially compromising cloud application deployments and operational security.",
Regex: utils.GenerateSemiGenericRegex(identifiers, utils.Hex("37"), true), Regex: utils.GenerateSemiGenericRegex(identifiers, utils.Hex("37"), true),
Entropy: 2,
Keywords: identifiers, Keywords: identifiers,
} }
// validate // validate
tps := global_keys tps := utils.GenerateSampleSecrets("cloudflare", secrets.NewSecret(utils.Hex("37")))
tps = append(tps, global_keys...)
fps := append(api_keys, origin_ca_keys...) fps := append(api_keys, origin_ca_keys...)
return utils.Validate(r, tps, fps) return utils.Validate(r, tps, fps)
@@ -44,15 +46,16 @@ func CloudflareGlobalAPIKey() *config.Rule {
func CloudflareAPIKey() *config.Rule { func CloudflareAPIKey() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Detected a Cloudflare API Key, potentially compromising cloud application deployments and operational security.",
RuleID: "cloudflare-api-key", RuleID: "cloudflare-api-key",
Description: "Detected a Cloudflare API Key, potentially compromising cloud application deployments and operational security.",
Regex: utils.GenerateSemiGenericRegex(identifiers, utils.AlphaNumericExtendedShort("40"), true), Regex: utils.GenerateSemiGenericRegex(identifiers, utils.AlphaNumericExtendedShort("40"), true),
Entropy: 2,
Keywords: identifiers, Keywords: identifiers,
} }
// validate // validate
tps := api_keys tps := utils.GenerateSampleSecrets("cloudflare", secrets.NewSecret(utils.AlphaNumericExtendedShort("40")))
tps = append(tps, api_keys...)
fps := append(global_keys, origin_ca_keys...) fps := append(global_keys, origin_ca_keys...)
return utils.Validate(r, tps, fps) return utils.Validate(r, tps, fps)
@@ -65,12 +68,13 @@ func CloudflareOriginCAKey() *config.Rule {
Description: "Detected a Cloudflare Origin CA Key, potentially compromising cloud application deployments and operational security.", Description: "Detected a Cloudflare Origin CA Key, potentially compromising cloud application deployments and operational security.",
RuleID: "cloudflare-origin-ca-key", RuleID: "cloudflare-origin-ca-key",
Regex: utils.GenerateUniqueTokenRegex(`v1\.0-`+utils.Hex("24")+"-"+utils.Hex("146"), false), Regex: utils.GenerateUniqueTokenRegex(`v1\.0-`+utils.Hex("24")+"-"+utils.Hex("146"), false),
Entropy: 2,
Keywords: ca_identifiers, Keywords: ca_identifiers,
} }
// validate // validate
tps := origin_ca_keys tps := utils.GenerateSampleSecrets("cloudflare", "v1.0-aaa334dc886f30631ba0a610-0d98ef66290d7e50aac7c27b5986c99e6f3f1084c881d8ac0eae5de1d1aa0644076ff57022069b3237d19afe60ad045f207ef2b16387ee37b749441b2ae2e9ebe5b4606e846475d4a5")
tps = append(tps, origin_ca_keys...)
fps := append(global_keys, api_keys...) fps := append(global_keys, api_keys...)
return utils.Validate(r, tps, fps) return utils.Validate(r, tps, fps)
+1 -3
View File
@@ -18,8 +18,6 @@ func CodecovAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("codecov", secrets.NewSecret(utils.AlphaNumeric("32")))
utils.GenerateSampleSecret("codecov", secrets.NewSecret(utils.AlphaNumeric("32"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+1 -4
View File
@@ -19,9 +19,6 @@ func CoinbaseAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("coinbase", secrets.NewSecret(utils.AlphaNumericExtendedShort("64")))
utils.GenerateSampleSecret("coinbase",
secrets.NewSecret(utils.AlphaNumericExtendedShort("64"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+16 -17
View File
@@ -22,8 +22,11 @@ regexes = [{{ range $i, $regex := . }}
paths = [{{ range $i, $path := . }} paths = [{{ range $i, $path := . }}
'''{{ $path }}''',{{ end }} '''{{ $path }}''',{{ end }}
]{{ end }} ]{{ end }}
{{- with .Allowlist.StopWords }}{{println}}stopwords = [{{ range $j, $stopword := . }}
"{{ $stopword }}",{{ end }}
]{{ end }}{{println}}
{{ range $i, $rule := .Rules }}[[rules]] {{- range $i, $rule := .Rules }}{{println}}[[rules]]
id = "{{$rule.RuleID}}" id = "{{$rule.RuleID}}"
description = "{{$rule.Description}}" description = "{{$rule.Description}}"
regex = '''{{$rule.Regex}}''' regex = '''{{$rule.Regex}}'''
@@ -43,23 +46,19 @@ keywords = [{{ range $j, $keyword := . }}"{{ $keyword }}"{{ end }}]{{end}}{{ end
tags = [ tags = [
{{ range $j, $tag := . }}"{{ $tag }}",{{ end }} {{ range $j, $tag := . }}"{{ $tag }}",{{ end }}
]{{ end }} ]{{ end }}
{{ if or $rule.Allowlist.Regexes $rule.Allowlist.Paths $rule.Allowlist.Commits $rule.Allowlist.StopWords }} {{- with $rule.Allowlists }}{{ range $i, $allowlist := . }}{{ if or $allowlist.Regexes $allowlist.Paths $allowlist.Commits $allowlist.StopWords }}{{println}}[[rules.allowlists]]
[rules.allowlist] {{- with .MatchCondition }}{{println}}condition = "{{ .MatchCondition.String }}"{{ end }}
{{- with $rule.Allowlist.RegexTarget }} {{- with .Commits -}}{{println}}commits = [
regexTarget = "{{ . }}"{{ end -}}
{{- with $rule.Allowlist.Regexes }}
regexes = [{{ range $i, $regex := . }}
'''{{ $regex }}''',{{ end }}
]{{ end }}
{{- with $rule.Allowlist.Paths }}paths = [
{{ range $j, $path := . }}'''{{ $path }}''',{{ end }}
]{{ end }}
{{- with $rule.Allowlist.Commits }}commits = [
{{ range $j, $commit := . }}"{{ $commit }}",{{ end }} {{ range $j, $commit := . }}"{{ $commit }}",{{ end }}
]{{ end }} ]{{ end }}
{{- with $rule.Allowlist.StopWords }} {{- with .Paths }}{{println}}paths = [
stopwords = [{{ range $j, $stopword := . }} {{ range $j, $path := . }}'''{{ $path }}''',{{ end }}
"{{ $stopword }}",{{ end }}
]{{ end }} ]{{ end }}
{{- if and .RegexTarget .Regexes }}{{println}}regexTarget = "{{ .RegexTarget }}"{{ end -}}
{{- with .Regexes }}{{println}}regexes = [{{ range $i, $regex := . }}
'''{{ $regex }}''',{{ end }}
]{{ end }}
{{- with .StopWords }}{{println}}stopwords = [{{ range $j, $stopword := . }}
"{{ $stopword }}",{{ end }}
]{{ end }}{{ end }}{{ end }}{{ end }}
{{ end }} {{ end }}
{{ end -}}
+2 -6
View File
@@ -18,9 +18,7 @@ func ConfluentSecretKey() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("confluent", secrets.NewSecret(utils.AlphaNumeric("64")))
utils.GenerateSampleSecret("confluent", secrets.NewSecret(utils.AlphaNumeric("64"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -37,8 +35,6 @@ func ConfluentAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("confluent", secrets.NewSecret(utils.AlphaNumeric("16")))
utils.GenerateSampleSecret("confluent", secrets.NewSecret(utils.AlphaNumeric("16"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+1 -3
View File
@@ -17,8 +17,6 @@ func Contentful() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("contentful", secrets.NewSecret(utils.AlphaNumeric("43")))
utils.GenerateSampleSecret("contentful", secrets.NewSecret(utils.AlphaNumeric("43"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+198
View File
@@ -0,0 +1,198 @@
package rules
import (
"fmt"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
)
// https://curl.se/docs/manpage.html#-u
func CurlBasicAuth() *config.Rule {
r := config.Rule{
RuleID: "curl-auth-user",
Description: "Discovered a potential basic authorization token provided in a curl command, which could compromise the curl accessed resource.",
Regex: regexp.MustCompile(`\bcurl\b(?:.*|.*(?:[\r\n]{1,2}.*){1,5})[ \t\n\r](?:-u|--user)(?:=|[ \t]{0,5})(?:"([^:"]{3,}:[^"]{3,})"|'([^:']{3,}:[^']{3,})'|((?:"[^"]{3,}"|'[^']{3,}'|[\w$@.-]+):(?:"[^"]{3,}"|'[^']{3,}'|[\w${}@.-]+)))(?:\s|\z)`),
Keywords: []string{"curl"},
Entropy: 2,
Allowlists: []config.Allowlist{
{
Regexes: []*regexp.Regexp{
regexp.MustCompile(`[^:]+:(change(it|me)|pass(word)?|pwd|test|token|\*+|x+)`), // common placeholder passwords
regexp.MustCompile(`['"]?<[^>]+>['"]?:['"]?<[^>]+>|<[^:]+:[^>]+>['"]?`), // <placeholder>
regexp.MustCompile(`[^:]+:\[[^]]+]`), // [placeholder]
regexp.MustCompile(`['"]?[^:]+['"]?:['"]?\$(\d|\w+|\{(\d|\w+)})['"]?`), // $1 or $VARIABLE
regexp.MustCompile(`\$\([^)]+\):\$\([^)]+\)`), // $(cat login.txt)
regexp.MustCompile(`['"]?\$?{{[^}]+}}['"]?:['"]?\$?{{[^}]+}}['"]?`), // ${{ secrets.FOO }} or {{ .Values.foo }}
},
},
},
}
// validate
tps := []string{
// short
`curl --cacert ca.crt -u elastic:P@ssw0rd$1 https://localhost:9200`, // same lines, no quotes
`sh-5.0$ curl -k -X POST https://infinispan:11222/rest/v2/caches/default/hello \
-H 'Content-type: text/plain' \
-d 'world' \
-u developer:yqDVtkqPECriaLRi`, // different line
// long
`curl -sw '%{http_code}' -X POST --user 'johns:h0pk1ns~21s' $GItHUB_API_URL/$GIT_COMMIT --data`,
`curl --user roger23@gmail.com:pQ9wTxu4Fg https://www.dropbox.com/cli_link?host_id=abcdefg -v`, // same line, no quotes
`curl -s --user 'api:d2LkV78zLx!t' \
https://api.mailgun.net/v2/sandbox91d3515882ecfaa1c65be642.mailgun.org/messages`, // same line, single quotes
`curl -s -v --user "j.smith:dB2yF6@qL9vZm1P#4J" "https://api.contoso.org/user/me"`, // same line, double quotes
`curl -X POST --user "{acd3c08b-74e8-4f44-a2d0-80694le24f46}":"{ZqL5kVrX1n8tA2}" --header "Accept: application/json" --data "{\"text\":\"Hello, world\",\"source\":\"en\",\"target\":\"es\"}" https://gateway.watsonplatform.net/language-translator/api`,
`curl --user kevin:'pRf7vG2h1L8nQkW9' -iX PATCH -H "Content-Type: application/json" -d`, // same line, mixed quoting
`$ curl https://api.dropbox.com/oauth2/token \
--user c28wlsosanujy2z:qgsnai0xokrw4j1 --data grant_type=authorization_code`, // different line
// TODO
//` curl -s --insecure --url "imaps://whatever.imap.server" --user\
//"myuserid:mypassword" --request "STATUS INBOX (UNSEEN)"`,
}
fps := []string{
// short
`curl -i -u 'test:test'`,
` curl -sL --user "$1:$2" "$3" > "$4"`, // environment variable
`curl -u <user:password> https://test.com/endpoint`, // placeholder
`curl --user neo4j:[PASSWORD] http://[IP]:7474/db/data/`, // placeholder
`curl -u "myusername" http://localhost:15130/api/check_user/`, // no password
`curl -u username:token`,
`curl -u "${_username}:${_password}"`,
`curl -u "${username}":"${password}"`,
`curl -k -X POST -I -u "SRVC_JENKINS:${APPID}"`,
// long
`curl -sw '%{http_code}' -X POST --user '$USERNAME:$PASSWORD' $GItHUB_API_URL/$GIT_COMMIT --data`,
`curl --user "xxx:yyy"`,
` curl -sL --user "$GITHUB_USERNAME:$GITHUB_PASSWORD" "$GITHUB_URL" > "$TESTS_PATH"`, // environment variable
// variable interpolation
`curl --silent --fail {{- if and $.Values.username $.Values.password }} --user "{{ $.Values.username }}:{{ $.Values.password }}"`,
`curl -XGET -i -u "${{ env.ELK_ID }}:${{ build.env.ELK_PASS }}"`,
`curl -XGET -i -u "${{needs.vault.outputs.account_id}}:${{needs.vault.outputs.account_password}}"`,
`curl -XGET -i -u "${{ steps.vault.outputs.account_id }}:${{ steps.vault.outputs.account_password }}"`,
`curl -X POST --user "$(cat ./login.txt):$(cat ./password.txt)"`, // command
`curl http://127.0.0.1:5000/file --user user:pass --digest # digest auth`, // placeholder
` curl -X GET --insecure --user "username:password" \`, // placeholder
`curl --silent --insecure --user ${f5user}:${f5pass} \`, // placeholder
`curl --insecure --ssl-reqd "smtps://smtp.gmail.com" --mail-from "src@gmail.com" --mail-rcpt "dst@gmail.com" --user "src@gmail.com" --upload-file out.txt`, // no password
// different command
`#HTTP command line test
curl -X POST -H "Content-Type: application/json" -d '{"id":12345,"geo":{"latitude":28.50,"longitude":-81.14}}' http://<ip>:8080/serve
#UDP command line test
echo -n '{"type":"serve","channel":"/","data":{"site_id":8,"post_id":12345,"geo":{"lat":28.50,"long":-81.14}}}' >/dev/udp/127.0.0.1/41234
#UDP Listener (for confirmation)
nc -u -l 41234`,
}
return utils.Validate(r, tps, fps)
}
// https://curl.se/docs/manpage.html#-H
func CurlHeaderAuth() *config.Rule {
// language=regexp
authPat := `(?i)(?:Authorization:[ \t]{0,5}(?:Basic[ \t]([a-z0-9+/]{8,}={0,3})|(?:Bearer|(?:Api-)?Token)[ \t]([\w=~@.+/-]{8,})|([\w=~@.+/-]{8,}))|(?:(?:X-(?:[a-z]+-)?)?(?:Api-?)?(?:Key|Token)):[ \t]{0,5}([\w=~@.+/-]{8,}))`
r := config.Rule{
RuleID: "curl-auth-header",
Description: "Discovered a potential authorization token provided in a curl command header, which could compromise the curl accessed resource.",
Regex: regexp.MustCompile(
// language=regexp
fmt.Sprintf(`\bcurl\b(?:.*?|.*?(?:[\r\n]{1,2}.*?){1,5})[ \t\n\r](?:-H|--header)(?:=|[ \t]{0,5})(?:"%s"|'%s')(?:\B|\s|\z)`, authPat, authPat)),
Entropy: 2.75,
Keywords: []string{"curl"},
//Allowlists: []config.Allowlist{
// {
// Regexes: []*regexp.Regexp{},
// },
//},
}
tps := []string{
`curl --header 'Authorization: 5eb4223e-5008-46e5-be67-c7b8f2732305'`,
// Short flag.
`curl -H 'Authorization: Basic YnJvd3Nlcjo=' \`, // same line, single quotes
// TODO: Handle short flags combined.
//`TOKEN=$(curl -sH "Authorization: Basic $BASIC_TOKEN" "https://$REGISTRY/oauth2/token?service=$REGISTRY&scope=repository:$REPO:pull" | jq -r .access_token)`,
// Long flag.
`curl -k -X POST --header "Authorization: Basic djJlNEpYa0NJUHZ5a2FWT0VRXzRqZmZUdDkwYTp2emNBZGFzZWpmlWZiUDc2VUJjNDNNVDExclVh" "https://api-qa.example.com:8243/token" -d "grant_type=client_credentials"`, // same line, double quotes
// Basic auth.
`curl -X POST -H "Content-Type: application/json" \
-H "Authorization: Basic MzUzYjMwMmM0NDU3NGY1NjUwNDU2ODdlNTM0ZTdkNmE6Mjg2OTI0Njk3ZTYxNWE2NzJhNjQ2YTQ5MzU0NTY0NmM=" \
-d '{"user":{"emailAddress":"test@example.com"}, "password":"password"}' \
'http://localhost:8080/oauth2-provider/v1.0/users'`, // different line, double quotes
`#curl -X POST \
# https://api.mailgun.net/v3/sandbox7dbcabccd4314c123e8b23599d35f5b6.mailgun.org/messages \
# -H 'Authorization: Basic YXBpOmtleS1hN2MzNDJ3MzNhNWQxLTU2M2U3MjlwLTZhYjI3YzYzNzM0Ng==' \
# -F from='Excited User <mailgun@sandbox7dbc123bccd4314c0aae8b23599d35f5b6.mailgun.org>' \
# -F to='joe@example.com' \
# -F subject='Hello' \
# -F text='Testing some Mailgun awesomness!'`, // different line, single quotes
// Bearer auth
`# curl -X GET "http://localhost:3000/api/cron/status" -H "Authorization: Bearer cfcabd11c7ed9a41b1a3e063c32d5114"`, // same line, double quotes
`curl -X PUT -H 'Authorization: Bearer jC+6TUUjCNHcVtAXpcqBCgxnA8r+qD6MatnYaf/+289y7HWpK0BWPyLHv/K4DMN32fufwmeVVjlo8zjgBh8kx3GfS6IqO70w1DVMSCTwX7fhEpiXaxzv0mhSMHDX9Kw63Q6DkavUWUV+MDNhCF5wGQrcdQNncVRF3YkuDHDT/xw2YWyZ/DX8k+gAYiC8gcD8Ueg0ljBVS1IDwPjuGoFPESJVxYr0MDPF2D8Pn2S5rq692U4D9ZLuluS46VA4DK6ig5P7QM5XVXi4V7vXM8qpN/zqneyz+w4PUh6NIX7QG6JczMhYd9maWRWVat5jDdyII63P6sNAy9QZjw+ClW211Q==' -d 'user={"account":"user@domain.com", "roles":["user"]}' http://127.0.0.1:8443/desks/1/occupy`, // same line, single quotes
`curl https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer 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" \`, // different line, double quotes
`curl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \
-H "Authorization: Bearer _FXNljbSRYMWx3TWrd7lgKhLtVZX6iskC8Wcbb4b" \
-H "Content-Type:application/json"`,
`curl -H "Authorization: Bearer sha256~bRLFnzd59Z3XpZH5_seJPHALOuvbWiKwbFKSsoALkgp"`,
// Token auth
`curl -H "Authorization: Api-Token 22cb987851bc5659l29114c62e60c79abd0d2c08" --request PUT https://appsecclass.report/api/use/635`, // token
`curl -H "Authorization: Token 22cb987851bc5659229114c62e60c79abd0d2c08" --request PUT https://appsecclass.report/api/use/635`, // token
// Nothing
`curl -L -H "Authorization:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb25maWRlbmNlIjowLjh9.kvRPfjAhLhtRTczoRgctVGp7KY1QVH3UBZM-gM0x8ec" service1.local -> correct jwt `, // no prefix
`curl -L -H "Authorization: sha256~bRLFnzd5@=-.a+/hgdS"`, // no prefix
// Non-authorization headers.
`curl -X GET \
-H "apikey: c4ed6c21-9dd5-4a05-8e3f-c56d1151cce8" \
-H "Accept: application/json" \`, // apikey
`curl -X POST --header "Api-Token: Sk94HG7f6KB"`, // api-token
`curl -XPOST http://localhost:8080/api/tasks -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" -H "Token: 3fea6af1349166ea" -d "content=hello-curl"`, // token
`curl -X GET https://octopus.corp.net/
-H "X-Octopus-ApiKey: 3a16750d-d363-41a4-8ebd-035408f7730f" \`, // X-$thing-ApiKey
}
fps := []string{
// Placeholders
`curl https://example.com/micropub -d h=entry -d "content=Hello World" -H "Authorization: Bearer XXXXXXXXXXXX"`,
`curl -X POST https://accounts.spotify.com/api/token -d grant_type=client_credentials --header "Authorization: Basic ..."`,
`curl \
-H "Authorization: Bearer <Openverse API token>" \
"https://api.openverse.org/v1/audio/?q=test"`,
`curl -v -v -v -X POST https://domain/api/v1/authentication/sso/login-url/ \
-H 'Content-Type: application/json' \
-H "Authorization: Token **********" \
-d '{"username": "test", "next": "/luna/"}'`,
// Variables
`curl -XPOST http://localhost:8080/api/token -H "Authorization: basic {base64(email:password[\n])}" => token`, // same line, invalid base64
`curl -X GET \
-H "apikey: $API_KEY" \
-H "Accept: $FORMAT" \
"$API_URL/rest/v1/stats_derniere_labellisation"`, // API Key placeholder
`$ curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d '{
"model": "chatglm3-6b-32k",
"messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"}]
}'`, // different line, placeholder
`curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $(gcloud auth print-access-token)" https://workflowexecutions.googleapis.com/v1/projects/244283331594/locations/us-central1/workflows/sample-workflow/executions/43c925aa-514a-44c1-a0a4-a9f8f26fd2cb/callbacks/1705791f-d446-4e92-a6d0-a13622422e80_31864a51-8c13-4b03-ad4d-945cdc8d0631`, // script
// Not valid BASIC
`curl -X POST -H "Content-Type: application/json" -H "Authorization: Basic eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb25maWRlbmNlIjowLjh9.kvRPfjAhLhtRTczoRgctVGp7KY1QVH3UBZM-gM0x8ec" \`,
}
return utils.Validate(r, tps, fps)
}
+8 -5
View File
@@ -9,15 +9,18 @@ import (
func Databricks() *config.Rule { func Databricks() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Uncovered a Databricks API token, which may compromise big data analytics platforms and sensitive data processing.",
RuleID: "databricks-api-token", RuleID: "databricks-api-token",
Regex: utils.GenerateUniqueTokenRegex(`dapi[a-h0-9]{32}`, true), Description: "Uncovered a Databricks API token, which may compromise big data analytics platforms and sensitive data processing.",
Regex: utils.GenerateUniqueTokenRegex(`dapi[a-f0-9]{32}(?:-\d)?`, false),
Entropy: 3,
Keywords: []string{"dapi"}, Keywords: []string{"dapi"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("databricks", "dapi"+secrets.NewSecret(utils.Hex("32")))
utils.GenerateSampleSecret("databricks", "dapi"+secrets.NewSecret(utils.Hex("32"))), tps = append(tps, `token = dapif13ac4b49d1cb31f69f678e39602e381-2`) // gitleaks:ignore
fps := []string{
`DATABRICKS_TOKEN=dapi123456789012345678a9bc01234defg5`,
} }
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, fps)
} }
+1 -3
View File
@@ -19,8 +19,6 @@ func DatadogtokenAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("datadog", secrets.NewSecret(utils.AlphaNumeric("40")))
utils.GenerateSampleSecret("datadog", secrets.NewSecret(utils.AlphaNumeric("40"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -23,8 +23,6 @@ func DefinedNetworkingAPIToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("dnkey", "dnkey-"+secrets.NewSecret(utils.AlphaNumericExtended("26"))+"-"+secrets.NewSecret(utils.AlphaNumericExtended("52")))
utils.GenerateSampleSecret("dnkey", "dnkey-"+secrets.NewSecret(utils.AlphaNumericExtended("26"))+"-"+secrets.NewSecret(utils.AlphaNumericExtended("52"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+10 -15
View File
@@ -8,30 +8,27 @@ import (
func DigitalOceanPAT() *config.Rule { func DigitalOceanPAT() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Discovered a DigitalOcean Personal Access Token, posing a threat to cloud infrastructure security and data privacy.",
RuleID: "digitalocean-pat", RuleID: "digitalocean-pat",
Regex: utils.GenerateUniqueTokenRegex(`dop_v1_[a-f0-9]{64}`, true), Description: "Discovered a DigitalOcean Personal Access Token, posing a threat to cloud infrastructure security and data privacy.",
Regex: utils.GenerateUniqueTokenRegex(`dop_v1_[a-f0-9]{64}`, false),
Entropy: 3,
Keywords: []string{"dop_v1_"}, Keywords: []string{"dop_v1_"},
} }
tps := []string{ tps := utils.GenerateSampleSecrets("do", "dop_v1_"+secrets.NewSecret(utils.Hex("64")))
utils.GenerateSampleSecret("do", "dop_v1_"+secrets.NewSecret(utils.Hex("64"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func DigitalOceanOAuthToken() *config.Rule { func DigitalOceanOAuthToken() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Found a DigitalOcean OAuth Access Token, risking unauthorized cloud resource access and data compromise.",
RuleID: "digitalocean-access-token", RuleID: "digitalocean-access-token",
Description: "Found a DigitalOcean OAuth Access Token, risking unauthorized cloud resource access and data compromise.",
Regex: utils.GenerateUniqueTokenRegex(`doo_v1_[a-f0-9]{64}`, true), Entropy: 3,
Keywords: []string{"doo_v1_"}, Regex: utils.GenerateUniqueTokenRegex(`doo_v1_[a-f0-9]{64}`, false),
Keywords: []string{"doo_v1_"},
} }
tps := []string{ tps := utils.GenerateSampleSecrets("do", "doo_v1_"+secrets.NewSecret(utils.Hex("64")))
utils.GenerateSampleSecret("do", "doo_v1_"+secrets.NewSecret(utils.Hex("64"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -44,8 +41,6 @@ func DigitalOceanRefreshToken() *config.Rule {
Keywords: []string{"dor_v1_"}, Keywords: []string{"dor_v1_"},
} }
tps := []string{ tps := utils.GenerateSampleSecrets("do", "dor_v1_"+secrets.NewSecret(utils.Hex("64")))
utils.GenerateSampleSecret("do", "dor_v1_"+secrets.NewSecret(utils.Hex("64"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+18 -12
View File
@@ -9,47 +9,53 @@ import (
func DiscordAPIToken() *config.Rule { func DiscordAPIToken() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Detected a Discord API key, potentially compromising communication channels and user data privacy on Discord.",
RuleID: "discord-api-token", RuleID: "discord-api-token",
Description: "Detected a Discord API key, potentially compromising communication channels and user data privacy on Discord.",
Regex: utils.GenerateSemiGenericRegex([]string{"discord"}, utils.Hex("64"), true), Regex: utils.GenerateSemiGenericRegex([]string{"discord"}, utils.Hex("64"), true),
Keywords: []string{"discord"}, Keywords: []string{"discord"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("discord", secrets.NewSecret(utils.Hex("64")))
utils.GenerateSampleSecret("discord", secrets.NewSecret(utils.Hex("64"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func DiscordClientID() *config.Rule { func DiscordClientID() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Identified a Discord client ID, which may lead to unauthorized integrations and data exposure in Discord applications.",
RuleID: "discord-client-id", RuleID: "discord-client-id",
Description: "Identified a Discord client ID, which may lead to unauthorized integrations and data exposure in Discord applications.",
Regex: utils.GenerateSemiGenericRegex([]string{"discord"}, utils.Numeric("18"), true), Regex: utils.GenerateSemiGenericRegex([]string{"discord"}, utils.Numeric("18"), true),
Entropy: 2,
Keywords: []string{"discord"}, Keywords: []string{"discord"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("discord", secrets.NewSecret(utils.Numeric("18")))
utils.GenerateSampleSecret("discord", secrets.NewSecret(utils.Numeric("18"))), fps := []string{
// Low entropy
`discord=000000000000000000`,
} }
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, fps)
} }
func DiscordClientSecret() *config.Rule { func DiscordClientSecret() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Discovered a potential Discord client secret, risking compromised Discord bot integrations and data leaks.",
RuleID: "discord-client-secret", RuleID: "discord-client-secret",
Description: "Discovered a potential Discord client secret, risking compromised Discord bot integrations and data leaks.",
Regex: utils.GenerateSemiGenericRegex([]string{"discord"}, utils.AlphaNumericExtended("32"), true), Regex: utils.GenerateSemiGenericRegex([]string{"discord"}, utils.AlphaNumericExtended("32"), true),
Entropy: 2,
Keywords: []string{"discord"}, Keywords: []string{"discord"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("discord", secrets.NewSecret(utils.Numeric("32")))
utils.GenerateSampleSecret("discord", secrets.NewSecret(utils.Numeric("32"))), fps := []string{
// Low entropy
`discord=00000000000000000000000000000000`,
// TODO:
//`discord=01234567890123456789012345678901`,
} }
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, fps)
} }
+7 -7
View File
@@ -1,26 +1,26 @@
package rules package rules
import ( import (
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
) )
func Doppler() *config.Rule { func Doppler() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Discovered a Doppler API token, posing a risk to environment and secrets management security.",
RuleID: "doppler-api-token", RuleID: "doppler-api-token",
Description: "Discovered a Doppler API token, posing a risk to environment and secrets management security.",
Regex: regexp.MustCompile(`dp\.pt\.(?i)[a-z0-9]{43}`), Regex: regexp.MustCompile(`dp\.pt\.(?i)[a-z0-9]{43}`),
Keywords: []string{"doppler"}, Entropy: 2,
Keywords: []string{`dp.pt.`},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("doppler", "dp.pt."+secrets.NewSecret(utils.AlphaNumeric("43")))
utils.GenerateSampleSecret("doppler", "dp.pt."+secrets.NewSecret(utils.AlphaNumeric("43"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+1 -3
View File
@@ -19,8 +19,6 @@ func DroneciAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("droneci", secrets.NewSecret(utils.AlphaNumeric("32")))
utils.GenerateSampleSecret("droneci", secrets.NewSecret(utils.AlphaNumeric("32"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+1 -3
View File
@@ -17,9 +17,7 @@ func DropBoxAPISecret() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("dropbox", secrets.NewSecret(utils.AlphaNumeric("15")))
utils.GenerateSampleSecret("dropbox", secrets.NewSecret(utils.AlphaNumeric("15"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+6 -6
View File
@@ -1,11 +1,12 @@
package rules package rules
import ( import (
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
) )
func Duffel() *config.Rule { func Duffel() *config.Rule {
@@ -14,12 +15,11 @@ func Duffel() *config.Rule {
RuleID: "duffel-api-token", RuleID: "duffel-api-token",
Description: "Uncovered a Duffel API token, which may compromise travel platform integrations and sensitive customer data.", Description: "Uncovered a Duffel API token, which may compromise travel platform integrations and sensitive customer data.",
Regex: regexp.MustCompile(`duffel_(?:test|live)_(?i)[a-z0-9_\-=]{43}`), Regex: regexp.MustCompile(`duffel_(?:test|live)_(?i)[a-z0-9_\-=]{43}`),
Keywords: []string{"duffel"}, Entropy: 2,
Keywords: []string{"duffel_"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("duffel", "duffel_test_"+secrets.NewSecret(utils.AlphaNumericExtended("43")))
utils.GenerateSampleSecret("duffel", "duffel_test_"+secrets.NewSecret(utils.AlphaNumericExtended("43"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+7 -7
View File
@@ -1,25 +1,25 @@
package rules package rules
import ( import (
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
) )
func Dynatrace() *config.Rule { func Dynatrace() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Detected a Dynatrace API token, potentially risking application performance monitoring and data exposure.",
RuleID: "dynatrace-api-token", RuleID: "dynatrace-api-token",
Description: "Detected a Dynatrace API token, potentially risking application performance monitoring and data exposure.",
Regex: regexp.MustCompile(`dt0c01\.(?i)[a-z0-9]{24}\.[a-z0-9]{64}`), Regex: regexp.MustCompile(`dt0c01\.(?i)[a-z0-9]{24}\.[a-z0-9]{64}`),
Keywords: []string{"dynatrace"}, Entropy: 4,
Keywords: []string{"dt0c01"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("dynatrace", "dt0c01."+secrets.NewSecret(utils.AlphaNumeric("24"))+"."+secrets.NewSecret(utils.AlphaNumeric("64")))
utils.GenerateSampleSecret("dynatrace", "dt0c01."+secrets.NewSecret(utils.AlphaNumeric("24"))+"."+secrets.NewSecret(utils.AlphaNumeric("64"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+28 -12
View File
@@ -1,41 +1,57 @@
package rules package rules
import ( import (
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
) )
func EasyPost() *config.Rule { func EasyPost() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Identified an EasyPost API token, which could lead to unauthorized postal and shipment service access and data exposure.",
RuleID: "easypost-api-token", RuleID: "easypost-api-token",
Regex: regexp.MustCompile(`\bEZAK(?i)[a-z0-9]{54}`), Description: "Identified an EasyPost API token, which could lead to unauthorized postal and shipment service access and data exposure.",
Regex: regexp.MustCompile(`\bEZAK(?i)[a-z0-9]{54}\b`),
Entropy: 2,
Keywords: []string{"EZAK"}, Keywords: []string{"EZAK"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("EZAK", "EZAK"+secrets.NewSecret(`[a-zA-Z0-9]{54}`))
utils.GenerateSampleSecret("EZAK", "EZAK"+secrets.NewSecret(utils.AlphaNumeric("54"))), tps = append(tps,
"EZAK"+secrets.NewSecret(`[a-zA-Z0-9]{54}`),
"example.com?t=EZAK"+secrets.NewSecret(`[a-zA-Z0-9]{54}`)+"&q=1",
)
fps := []string{
// random base64 encoded string
`...6wqX6fNUXA/rYqRvfQ+EZAKGqQRiRyqAFRQshGPWOIAwNWGORfKHSBnVNFtVmWYoW6PH23lkqbbDWep95C/3VmWq/edti6...`, // gitleaks:allow
} }
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, fps)
} }
func EasyPostTestAPI() *config.Rule { func EasyPostTestAPI() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Detected an EasyPost test API token, risking exposure of test environments and potentially sensitive shipment data.",
RuleID: "easypost-test-api-token", RuleID: "easypost-test-api-token",
Regex: regexp.MustCompile(`\bEZTK(?i)[a-z0-9]{54}`), Description: "Detected an EasyPost test API token, risking exposure of test environments and potentially sensitive shipment data.",
Regex: regexp.MustCompile(`\bEZTK(?i)[a-z0-9]{54}\b`),
Entropy: 2,
Keywords: []string{"EZTK"}, Keywords: []string{"EZTK"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("EZTK", secrets.NewSecret(`EZTK[a-zA-Z0-9]{54}`))
utils.GenerateSampleSecret("EZTK", "EZTK"+secrets.NewSecret(utils.AlphaNumeric("54"))), tps = append(tps, secrets.NewSecret(`EZTK[a-zA-Z0-9]{54}`))
tps = append(tps,
"EZTK"+secrets.NewSecret(`[a-zA-Z0-9]{54}`),
"example.com?t=EZTK"+secrets.NewSecret(`[a-zA-Z0-9]{54}`)+"&q=1",
)
fps := []string{
// random base64 encoded string
`...6wqX6fNUXA/rYqRvfQ+EZTKGqQRiRyqAFRQshGPWOIAwNWGORfKHSBnVNFtVmWYoW6PH23lkqbbDWep95C/3VmWq/edti6...`, // gitleaks:allow
} }
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, fps)
} }
+4 -5
View File
@@ -2,6 +2,7 @@ package rules
import ( import (
"fmt" "fmt"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
@@ -20,11 +21,9 @@ func EtsyAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("ETSY", secrets.NewSecret(utils.AlphaNumeric("24")))
utils.GenerateSampleSecret("ETSY", secrets.NewSecret(utils.AlphaNumeric("24"))), tps = append(tps, utils.GenerateSampleSecrets("etsy", secrets.NewSecret(utils.AlphaNumeric("24")))...)
utils.GenerateSampleSecret("etsy", secrets.NewSecret(utils.AlphaNumeric("24"))), tps = append(tps, utils.GenerateSampleSecrets("Etsy", secrets.NewSecret(utils.AlphaNumeric("24")))...)
utils.GenerateSampleSecret("Etsy", secrets.NewSecret(utils.AlphaNumeric("24"))),
}
fps := []string{ fps := []string{
fmt.Sprintf(`SetSysctl = "%s"`, secrets.NewSecret(utils.AlphaNumeric("24"))), fmt.Sprintf(`SetSysctl = "%s"`, secrets.NewSecret(utils.AlphaNumeric("24"))),
` if err := sysctl.SetSysctl(sysctlBridgeCallIPTables); err != nil {`, ` if err := sysctl.SetSysctl(sysctlBridgeCallIPTables); err != nil {`,
+22 -11
View File
@@ -11,19 +11,19 @@ import (
func FacebookSecret() *config.Rule { func FacebookSecret() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Discovered a Facebook Application secret, posing a risk of unauthorized access to Facebook accounts and personal data exposure.",
RuleID: "facebook-secret", RuleID: "facebook-secret",
Description: "Discovered a Facebook Application secret, posing a risk of unauthorized access to Facebook accounts and personal data exposure.",
Regex: utils.GenerateSemiGenericRegex([]string{"facebook"}, utils.Hex("32"), true), Regex: utils.GenerateSemiGenericRegex([]string{"facebook"}, utils.Hex("32"), true),
Entropy: 3,
Keywords: []string{"facebook"}, Keywords: []string{"facebook"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("facebook", secrets.NewSecret(utils.Hex("32")))
utils.GenerateSampleSecret("facebook", secrets.NewSecret(utils.Hex("32"))), tps = append(tps,
`facebook_app_secret = "6dca6432e45d933e13650d1882bd5e69"`, // gitleaks:allow `facebook_app_secret = "6dca6432e45d933e13650d1882bd5e69"`, // gitleaks:allow
`facebook_client_access_token: 26f5fd13099f2c1331aafb86f6489692`, // gitleaks:allow `facebook_client_access_token: 26f5fd13099f2c1331aafb86f6489692`, // gitleaks:allow
} )
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -31,9 +31,10 @@ func FacebookSecret() *config.Rule {
func FacebookAccessToken() *config.Rule { func FacebookAccessToken() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Discovered a Facebook Access Token, posing a risk of unauthorized access to Facebook accounts and personal data exposure.",
RuleID: "facebook-access-token", RuleID: "facebook-access-token",
Description: "Discovered a Facebook Access Token, posing a risk of unauthorized access to Facebook accounts and personal data exposure.",
Regex: utils.GenerateUniqueTokenRegex(`\d{15,16}(\||%)[0-9a-z\-_]{27,40}`, true), Regex: utils.GenerateUniqueTokenRegex(`\d{15,16}(\||%)[0-9a-z\-_]{27,40}`, true),
Entropy: 3,
} }
// validate // validate
@@ -49,9 +50,10 @@ func FacebookAccessToken() *config.Rule {
func FacebookPageAccessToken() *config.Rule { func FacebookPageAccessToken() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Discovered a Facebook Page Access Token, posing a risk of unauthorized access to Facebook accounts and personal data exposure.",
RuleID: "facebook-page-access-token", RuleID: "facebook-page-access-token",
Regex: utils.GenerateUniqueTokenRegex("EAA[MC]"+utils.AlphaNumeric("20,"), true), Description: "Discovered a Facebook Page Access Token, posing a risk of unauthorized access to Facebook accounts and personal data exposure.",
Regex: utils.GenerateUniqueTokenRegex("EAA[MC](?i)[a-z0-9]{100,}", false),
Entropy: 4,
Keywords: []string{"EAAM", "EAAC"}, Keywords: []string{"EAAM", "EAAC"},
} }
@@ -60,7 +62,16 @@ func FacebookPageAccessToken() *config.Rule {
`EAAM9GOnCB9kBO2frzOAWGN2zMnZClQshlWydZCrBNdodesbwimx1mfVJgqZBP5RSpMfUzWhtjTTXHG5I1UlvlwRZCgjm3ZBVGeTYiqAAoxyED6HaUdhpGVNoPUwAuAWWFsi9OvyYBQt22DGLqMIgD7VktuCTTZCWKasz81Q822FPhMTB9VFFyClNzQ0NLZClt9zxpsMMrUZCo1VU1rL3CKavir5QTfBjfCEzHNlWAUDUV2YZD`, // gitleaks:allow `EAAM9GOnCB9kBO2frzOAWGN2zMnZClQshlWydZCrBNdodesbwimx1mfVJgqZBP5RSpMfUzWhtjTTXHG5I1UlvlwRZCgjm3ZBVGeTYiqAAoxyED6HaUdhpGVNoPUwAuAWWFsi9OvyYBQt22DGLqMIgD7VktuCTTZCWKasz81Q822FPhMTB9VFFyClNzQ0NLZClt9zxpsMMrUZCo1VU1rL3CKavir5QTfBjfCEzHNlWAUDUV2YZD`, // gitleaks:allow
`EAAM9GOnCB9kBO2zXpAtRBmCrsPPjdA3KeBl4tqsEpcYd09cpjm9MZCBIklZBjIQBKGIJgFwm8IE17G5pipsfRBRBEHMWxvJsL7iHLUouiprxKRQfAagw8BEEDucceqxTiDhVW2IZAQNNbf0d1JhcapAGntx5S1Csm4j0GgZB3DuUfI2HJ9aViTtdfH2vjBy0wtpXm2iamevohGfoF4NgyRHusDLjqy91uYMkfrkc`, // gitleaks:allow `EAAM9GOnCB9kBO2zXpAtRBmCrsPPjdA3KeBl4tqsEpcYd09cpjm9MZCBIklZBjIQBKGIJgFwm8IE17G5pipsfRBRBEHMWxvJsL7iHLUouiprxKRQfAagw8BEEDucceqxTiDhVW2IZAQNNbf0d1JhcapAGntx5S1Csm4j0GgZB3DuUfI2HJ9aViTtdfH2vjBy0wtpXm2iamevohGfoF4NgyRHusDLjqy91uYMkfrkc`, // gitleaks:allow
`- name: FACEBOOK_TOKEN `- name: FACEBOOK_TOKEN
value: "EAACEdEose0cBA1bad3afsf2aew"`, // gitleaks:allow value: "EAACEdEose0cBA1bad3afsf286JZCOV1XmV4NobAXqUXZA7U9F1UaaOdQZABvz73030MJoC3gGoQrE8IEoMl4gFA6MmQadlJQBqtRsgIcIhtelIJOJaew"`, // gitleaks:allow
} }
return utils.Validate(r, tps, nil) fps := []string{
`eaaaC0b75a9329fded2ffa9a02b47e0117831b82`,
`"strict-uri-encode@npm:^2.0.0":
version: 2.0.0
resolution: "strict-uri-encode@npm:2.0.0"
checksum: eaac4cf978b6fbd480f1092cab8b233c9b949bcabfc9b598dd79a758f7243c28765ef7639c876fa72940dac687181b35486ea01ff7df3e65ce3848c64822c581
languageName: node
linkType: hard`,
}
return utils.Validate(r, tps, fps)
} }
+1 -3
View File
@@ -17,8 +17,6 @@ func FastlyAPIToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("fastly", secrets.NewSecret(utils.AlphaNumericExtended("32")))
utils.GenerateSampleSecret("fastly", secrets.NewSecret(utils.AlphaNumericExtended("32"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+2 -6
View File
@@ -17,9 +17,7 @@ func FinicityClientSecret() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("finicity", secrets.NewSecret(utils.AlphaNumeric("20")))
utils.GenerateSampleSecret("finicity", secrets.NewSecret(utils.AlphaNumeric("20"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -34,8 +32,6 @@ func FinicityAPIToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("finicity", secrets.NewSecret(utils.Hex("32")))
utils.GenerateSampleSecret("finicity", secrets.NewSecret(utils.Hex("32"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+1 -3
View File
@@ -19,8 +19,6 @@ func FinnhubAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("finnhub", secrets.NewSecret(utils.AlphaNumeric("20")))
utils.GenerateSampleSecret("finnhub", secrets.NewSecret(utils.AlphaNumeric("20"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+1 -3
View File
@@ -19,8 +19,6 @@ func FlickrAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("flickr", secrets.NewSecret(utils.AlphaNumeric("32")))
utils.GenerateSampleSecret("flickr", secrets.NewSecret(utils.AlphaNumeric("32"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+12 -14
View File
@@ -1,57 +1,55 @@
package rules package rules
import ( import (
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
) )
func FlutterwavePublicKey() *config.Rule { func FlutterwavePublicKey() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Detected a Finicity Public Key, potentially exposing public cryptographic operations and integrations.",
RuleID: "flutterwave-public-key", RuleID: "flutterwave-public-key",
Description: "Detected a Finicity Public Key, potentially exposing public cryptographic operations and integrations.",
Regex: regexp.MustCompile(`FLWPUBK_TEST-(?i)[a-h0-9]{32}-X`), Regex: regexp.MustCompile(`FLWPUBK_TEST-(?i)[a-h0-9]{32}-X`),
Entropy: 2,
Keywords: []string{"FLWPUBK_TEST"}, Keywords: []string{"FLWPUBK_TEST"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("flutterwavePubKey", "FLWPUBK_TEST-"+secrets.NewSecret(utils.Hex("32"))+"-X")
utils.GenerateSampleSecret("flutterwavePubKey", "FLWPUBK_TEST-"+secrets.NewSecret(utils.Hex("32"))+"-X"),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func FlutterwaveSecretKey() *config.Rule { func FlutterwaveSecretKey() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Identified a Flutterwave Secret Key, risking unauthorized financial transactions and data breaches.",
RuleID: "flutterwave-secret-key", RuleID: "flutterwave-secret-key",
Description: "Identified a Flutterwave Secret Key, risking unauthorized financial transactions and data breaches.",
Regex: regexp.MustCompile(`FLWSECK_TEST-(?i)[a-h0-9]{32}-X`), Regex: regexp.MustCompile(`FLWSECK_TEST-(?i)[a-h0-9]{32}-X`),
Entropy: 2,
Keywords: []string{"FLWSECK_TEST"}, Keywords: []string{"FLWSECK_TEST"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("flutterwavePubKey", "FLWSECK_TEST-"+secrets.NewSecret(utils.Hex("32"))+"-X")
utils.GenerateSampleSecret("flutterwavePubKey", "FLWSECK_TEST-"+secrets.NewSecret(utils.Hex("32"))+"-X"),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func FlutterwaveEncKey() *config.Rule { func FlutterwaveEncKey() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Uncovered a Flutterwave Encryption Key, which may compromise payment processing and sensitive financial information.",
RuleID: "flutterwave-encryption-key", RuleID: "flutterwave-encryption-key",
Description: "Uncovered a Flutterwave Encryption Key, which may compromise payment processing and sensitive financial information.",
Regex: regexp.MustCompile(`FLWSECK_TEST-(?i)[a-h0-9]{12}`), Regex: regexp.MustCompile(`FLWSECK_TEST-(?i)[a-h0-9]{12}`),
Entropy: 2,
Keywords: []string{"FLWSECK_TEST"}, Keywords: []string{"FLWSECK_TEST"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("flutterwavePubKey", "FLWSECK_TEST-"+secrets.NewSecret(utils.Hex("12")))
utils.GenerateSampleSecret("flutterwavePubKey", "FLWSECK_TEST-"+secrets.NewSecret(utils.Hex("12"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+12 -9
View File
@@ -20,23 +20,26 @@ func FlyIOAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{ // fo1_
// fo1_ tps := utils.GenerateSampleSecrets("fly", secrets.NewSecret(`fo1_[\w-]{43}`))
utils.GenerateSampleSecret("fly", secrets.NewSecret(`fo1_[\w-]{43}`)), tps = append(tps,
`Fly access token: fo1_8rz-j7r2eqJ2U7affEOO3HJN0j63DInyog3eV-glQSc `Fly access token: fo1_8rz-j7r2eqJ2U7affEOO3HJN0j63DInyog3eV-glQSc
`, `,
`============================================================================================================= `=============================================================================================================
fo1_BtKlzvfztw0M2hlLgTdsfPgDFiwM2jJjQXXy6I2pjuQ fo1_BtKlzvfztw0M2hlLgTdsfPgDFiwM2jJjQXXy6I2pjuQ
fly deploy`, fly deploy`)
// fm1 // fm1
utils.GenerateSampleSecret("fly", secrets.NewSecret(`fm1[ar]_[a-zA-Z0-9+\/]{100,}={0,3}`)), tps = append(tps, utils.GenerateSampleSecrets("fly", secrets.NewSecret(`fm1[ar]_[a-zA-Z0-9+\/]{100,}={0,3}`))...)
tps = append(tps,
`ENV FLY_API_TOKEN="FlyV1 fm1r_lJPECAAAAAAAAMqcxBBLMJKXYKJiT0CI58XmukX/wrVodHlwczovL2FwaS5mbHkuaW8vdjGWAJLOAAFmXh8Lk7lodHRwczovL2FwaS5mbHkuaW8vYWFhL3YxxDy5OfA2M6K6aLEoEDKxehojbj+8ZT9IrXCF5sL/r8m6/1gylwySsNxpD40wnpd/G2ZdjwVaQev1kEuFUgzERxPbtWHDNa+NYIZwbKN6b7/JxdbUprq0M10HI4fwtlxhqhdA/mMaMw70EC4TsfJyghIL98KP4ry5AaXiroRdjrSsFExc/xRCDZKUA5GBzgATuNsfBZGCp2J1aWxkZXIfondnHwHEIMa6NWc4b52S+UY7vjPdwKrz00Uzrc1830mOHzQNLun7,fm1a_lJPERxPbtWHDNa+NYIZwbKN6b7/JxdbUprq0M10HI4fwtlxhqhdA/mMaMw70EC4TsfJyghIL98KP4ry4AaXiroRdjrSsFExc/xRCxBCVlAoRzKV/+qYkxuipIbIcw7lodHRwczovL2FwaS5mbHkuaW8vYWFhL3YxlgSSzmS4Y7nPAAAAASCwgdcKkc4AAUktDMQQURck2h+upbiOrW66Nf5SA8QgrD03xlWju1WQi0AUhlk7YYFzOLDfhRyJ6nEziO37NUE="`, `ENV FLY_API_TOKEN="FlyV1 fm1r_lJPECAAAAAAAAMqcxBBLMJKXYKJiT0CI58XmukX/wrVodHlwczovL2FwaS5mbHkuaW8vdjGWAJLOAAFmXh8Lk7lodHRwczovL2FwaS5mbHkuaW8vYWFhL3YxxDy5OfA2M6K6aLEoEDKxehojbj+8ZT9IrXCF5sL/r8m6/1gylwySsNxpD40wnpd/G2ZdjwVaQev1kEuFUgzERxPbtWHDNa+NYIZwbKN6b7/JxdbUprq0M10HI4fwtlxhqhdA/mMaMw70EC4TsfJyghIL98KP4ry5AaXiroRdjrSsFExc/xRCDZKUA5GBzgATuNsfBZGCp2J1aWxkZXIfondnHwHEIMa6NWc4b52S+UY7vjPdwKrz00Uzrc1830mOHzQNLun7,fm1a_lJPERxPbtWHDNa+NYIZwbKN6b7/JxdbUprq0M10HI4fwtlxhqhdA/mMaMw70EC4TsfJyghIL98KP4ry4AaXiroRdjrSsFExc/xRCxBCVlAoRzKV/+qYkxuipIbIcw7lodHRwczovL2FwaS5mbHkuaW8vYWFhL3YxlgSSzmS4Y7nPAAAAASCwgdcKkc4AAUktDMQQURck2h+upbiOrW66Nf5SA8QgrD03xlWju1WQi0AUhlk7YYFzOLDfhRyJ6nEziO37NUE="`,
// fm2 )
utils.GenerateSampleSecret("fly", secrets.NewSecret(`fm2_[a-zA-Z0-9+\/]{100,}={0,3}`)), // fm2
tps = append(tps, utils.GenerateSampleSecrets("fly", secrets.NewSecret(`fm2_[a-zA-Z0-9+\/]{100,}={0,3}`))...)
tps = append(tps,
`# FLY_API_TOKEN: FlyV1 fm2_lJPECAAAAAAAAyZtxBD1hSZ7L5leXsj64ZbDlkm/wrVodHRwczovL2FwaS5mbHkuaW8vdjGWAJLOAAwMDB8Lk7lodHRwczovL2FwaS5mbHkuaW8vYWFhL3YxxDwDnhgJj/ML/nRKMiAYgnvXfNacrGWffj5TdfgGY2LU0ZetT7WzTLQQMO8cN2nRTztl/xLjnnZg5pBwFonETmhNA6Yl0X1tatt8ezA0UjVQiJr93VQ7qAmD5GG2Ce5txhbQv3tmIGsvaC7BOkIqAiR273bhZkO44AYsrCPr2XF8W6Twk7NyU+3UUeDwjw2SlAORgc4APu7vHwWRgqdidWlsZGVyH6J3Zx8BxCAlmLbu1HQDg8ZAGKKmEt4Mbnbqli6lbzBDHsawhcUF4A==,fm2_lJPETmhNA6Yl0X1tatt8ezA0UjVQiJr93VQ7qAmD5GG2Ce5txhbQv3tmIGsvaC7BOkIqAij273bhZkO44AYsrCPr2XF8W6Twk7NyU+3UUeDwj8QQbn07DOV+7SmoLj/uT+dbr8O5aHR0cHM6Ly9hcGkuZmx5LmlvL2FhYS92MZgEks5mqfbvzwAAAAE9PYz9F84AC7QACpHOAAu0AAzEEFfW3B+SzffV/KrAYa8qqpnEIIlD6DqZMZQ9Kt7fEenCCOLA+tUSJ+kmEFIUcc83npOI`, `# FLY_API_TOKEN: FlyV1 fm2_lJPECAAAAAAAAyZtxBD1hSZ7L5leXsj64ZbDlkm/wrVodHRwczovL2FwaS5mbHkuaW8vdjGWAJLOAAwMDB8Lk7lodHRwczovL2FwaS5mbHkuaW8vYWFhL3YxxDwDnhgJj/ML/nRKMiAYgnvXfNacrGWffj5TdfgGY2LU0ZetT7WzTLQQMO8cN2nRTztl/xLjnnZg5pBwFonETmhNA6Yl0X1tatt8ezA0UjVQiJr93VQ7qAmD5GG2Ce5txhbQv3tmIGsvaC7BOkIqAiR273bhZkO44AYsrCPr2XF8W6Twk7NyU+3UUeDwjw2SlAORgc4APu7vHwWRgqdidWlsZGVyH6J3Zx8BxCAlmLbu1HQDg8ZAGKKmEt4Mbnbqli6lbzBDHsawhcUF4A==,fm2_lJPETmhNA6Yl0X1tatt8ezA0UjVQiJr93VQ7qAmD5GG2Ce5txhbQv3tmIGsvaC7BOkIqAij273bhZkO44AYsrCPr2XF8W6Twk7NyU+3UUeDwj8QQbn07DOV+7SmoLj/uT+dbr8O5aHR0cHM6Ly9hcGkuZmx5LmlvL2FhYS92MZgEks5mqfbvzwAAAAE9PYz9F84AC7QACpHOAAu0AAzEEFfW3B+SzffV/KrAYa8qqpnEIIlD6DqZMZQ9Kt7fEenCCOLA+tUSJ+kmEFIUcc83npOI`,
`"BindToParentToken": "FlyV1 fm2_lJPEEKnzKy0lkwV3B+WIlmrdwejEEFv5qmevHU4fMs+2Gr6oOiPC2SAyOTc0NWI4ZmJlNjBlNjJmZTgzNTkxOThhZWE4MjY0M5IMxAMBAgPEIH7VG8u74KwO62hmx8SZO8WaU5o1g3W2IVc7QN6T1VTr",`, `"BindToParentToken": "FlyV1 fm2_lJPEEKnzKy0lkwV3B+WIlmrdwejEEFv5qmevHU4fMs+2Gr6oOiPC2SAyOTc0NWI4ZmJlNjBlNjJmZTgzNTkxOThhZWE4MjY0M5IMxAMBAgPEIH7VG8u74KwO62hmx8SZO8WaU5o1g3W2IVc7QN6T1VTr",`,
} )
fps := []string{ fps := []string{
// fo1_ // fo1_
`resource "doppler_integration_flyio" "prod" { `resource "doppler_integration_flyio" "prod" {
+4 -5
View File
@@ -1,11 +1,12 @@
package rules package rules
import ( import (
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
) )
func FrameIO() *config.Rule { func FrameIO() *config.Rule {
@@ -18,8 +19,6 @@ func FrameIO() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("frameio", "fio-u-"+secrets.NewSecret(utils.AlphaNumericExtended("64")))
utils.GenerateSampleSecret("frameio", "fio-u-"+secrets.NewSecret(utils.AlphaNumericExtended("64"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+48
View File
@@ -0,0 +1,48 @@
package rules
import (
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
)
func Freemius() *config.Rule {
// define rule
r := config.Rule{
RuleID: "freemius-secret-key",
Description: "Detected a Freemius secret key, potentially exposing sensitive information.",
Regex: regexp.MustCompile(`(?i)["']secret_key["']\s*=>\s*["'](sk_[\S]{29})["']`),
Keywords: []string{"secret_key"},
Path: regexp.MustCompile(`(?i)\.php$`),
}
// validate
tps := map[string]string{
"file.php": `$config = array(
"secret_key" => "sk_ubb4yN3mzqGR2x8#P7r5&@*xC$utE",
);`,
}
// It's only used in PHP SDK snippet.
// see https://freemius.com/help/documentation/wordpress-sdk/integrating-freemius-sdk/
fps := map[string]string{
// Invalid format: missing quotes around `secret_key`.
"foo.php": `$config = array(
secret_key => "sk_abcdefghijklmnopqrstuvwxyz123",
);`,
// Invalid format: missing quotes around the key value.
"bar.php": `$config = array(
"secret_key" => sk_abcdefghijklmnopqrstuvwxyz123,
);`,
// Invalid: different key name.
"baz.php": `$config = array(
"other_key" => "sk_abcdefghijklmnopqrstuvwxyz123",
);`,
// Invalid: file extension, should validate only .php files.
"foo.html": `$config = array(
"secret_key" => "sk_ubb4yN3mzqGR2x8#P7r5&@*xC$utE",
);`,
}
return utils.ValidateWithPaths(r, tps, fps)
}
+1 -3
View File
@@ -19,8 +19,6 @@ func FreshbooksAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("freshbooks", secrets.NewSecret(utils.AlphaNumeric("64")))
utils.GenerateSampleSecret("freshbooks", secrets.NewSecret(utils.AlphaNumeric("64"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+46 -5
View File
@@ -1,11 +1,12 @@
package rules package rules
import ( import (
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
) )
// TODO this one could probably use some work // TODO this one could probably use some work
@@ -35,19 +36,59 @@ func GCPAPIKey() *config.Rule {
Keywords: []string{ Keywords: []string{
"AIza", "AIza",
}, },
Allowlists: []config.Allowlist{
{
Regexes: []*regexp.Regexp{
// example keys from https://github.com/firebase/firebase-android-sdk
regexp.MustCompile(`AIzaSyabcdefghijklmnopqrstuvwxyz1234567`),
regexp.MustCompile(`AIzaSyAnLA7NfeLquW1tJFpx_eQCxoX-oo6YyIs`),
regexp.MustCompile(`AIzaSyCkEhVjf3pduRDt6d1yKOMitrUEke8agEM`),
regexp.MustCompile(`AIzaSyDMAScliyLx7F0NPDEJi1QmyCgHIAODrlU`),
regexp.MustCompile(`AIzaSyD3asb-2pEZVqMkmL6M9N6nHZRR_znhrh0`),
regexp.MustCompile(`AIzayDNSXIbFmlXbIE6mCzDLQAqITYefhixbX4A`),
regexp.MustCompile(`AIzaSyAdOS2zB6NCsk1pCdZ4-P6GBdi_UUPwX7c`),
regexp.MustCompile(`AIzaSyASWm6HmTMdYWpgMnjRBjxcQ9CKctWmLd4`),
regexp.MustCompile(`AIzaSyANUvH9H9BsUccjsu2pCmEkOPjjaXeDQgY`),
regexp.MustCompile(`AIzaSyA5_iVawFQ8ABuTZNUdcwERLJv_a_p4wtM`),
regexp.MustCompile(`AIzaSyA4UrcGxgwQFTfaI3no3t7Lt1sjmdnP5sQ`),
regexp.MustCompile(`AIzaSyDSb51JiIcB6OJpwwMicseKRhhrOq1cS7g`),
regexp.MustCompile(`AIzaSyBF2RrAIm4a0mO64EShQfqfd2AFnzAvvuU`),
regexp.MustCompile(`AIzaSyBcE-OOIbhjyR83gm4r2MFCu4MJmprNXsw`),
regexp.MustCompile(`AIzaSyB8qGxt4ec15vitgn44duC5ucxaOi4FmqE`),
regexp.MustCompile(`AIzaSyA8vmApnrHNFE0bApF4hoZ11srVL_n0nvY`),
},
},
},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("gcp", secrets.NewSecret(`AIza[\w-]{35}`))
utils.GenerateSampleSecret("gcp", secrets.NewSecret(`AIza[\w-]{35}`)), tps = append(tps,
// non-word character at end // non-word character at end
`AIzaSyNHxIf32IQ1a1yjl3ZJIqKZqzLAK1XhDk-`, // gitleaks:allow `AIzaSyNHxIf32IQ1a1yjl3ZJIqKZqzLAK1XhDk-`, // gitleaks:allow
} )
fps := []string{ fps := []string{
`GWw4hjABFzZCGiRpmlDyDdo87Jn9BN9THUA47muVRNunLxsa82tMAdvmrhOqNkRKiYMEAFbTJAIzaTesb6Tscfcni8vIpWZqNCXFDFslJtVSvFDq`, // text boundary start `GWw4hjABFzZCGiRpmlDyDdo87Jn9BN9THUA47muVRNunLxsa82tMAdvmrhOqNkRKiYMEAFbTJAIzaTesb6Tscfcni8vIpWZqNCXFDFslJtVSvFDq`, // text boundary start
`AIzaTesb6Tscfcni8vIpWZqNCXFDFslJtVSvFDqabcd123`, // text boundary end `AIzaTesb6Tscfcni8vIpWZqNCXFDFslJtVSvFDqabcd123`, // text boundary end
`apiKey: "AIzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"`, // not enough entropy `apiKey: "AIzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"`, // not enough entropy
`AIZASYCO2CXRMC9ELSKLHLHRMBSWDEVEDZTLO2O`, // incorrect case `AIZASYCO2CXRMC9ELSKLHLHRMBSWDEVEDZTLO2O`, // incorrect case
// example keys from https://github.com/firebase/firebase-android-sdk
`AIzaSyabcdefghijklmnopqrstuvwxyz1234567`,
`AIzaSyAnLA7NfeLquW1tJFpx_eQCxoX-oo6YyIs`,
`AIzaSyCkEhVjf3pduRDt6d1yKOMitrUEke8agEM`,
`AIzaSyDMAScliyLx7F0NPDEJi1QmyCgHIAODrlU`,
`AIzaSyD3asb-2pEZVqMkmL6M9N6nHZRR_znhrh0`,
`AIzayDNSXIbFmlXbIE6mCzDLQAqITYefhixbX4A`,
`AIzaSyAdOS2zB6NCsk1pCdZ4-P6GBdi_UUPwX7c`,
`AIzaSyASWm6HmTMdYWpgMnjRBjxcQ9CKctWmLd4`,
`AIzaSyANUvH9H9BsUccjsu2pCmEkOPjjaXeDQgY`,
`AIzaSyA5_iVawFQ8ABuTZNUdcwERLJv_a_p4wtM`,
`AIzaSyA4UrcGxgwQFTfaI3no3t7Lt1sjmdnP5sQ`,
`AIzaSyDSb51JiIcB6OJpwwMicseKRhhrOq1cS7g`,
`AIzaSyBF2RrAIm4a0mO64EShQfqfd2AFnzAvvuU`,
`AIzaSyBcE-OOIbhjyR83gm4r2MFCu4MJmprNXsw`,
`AIzaSyB8qGxt4ec15vitgn44duC5ucxaOi4FmqE`,
`AIzaSyA8vmApnrHNFE0bApF4hoZ11srVL_n0nvY`,
} }
return utils.Validate(r, tps, fps) return utils.Validate(r, tps, fps)
} }
+189 -20
View File
@@ -1,7 +1,10 @@
package rules package rules
import ( import (
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -11,45 +14,211 @@ func GenericCredential() *config.Rule {
RuleID: "generic-api-key", RuleID: "generic-api-key",
Description: "Detected a Generic API Key, potentially exposing access to various services and sensitive operations.", Description: "Detected a Generic API Key, potentially exposing access to various services and sensitive operations.",
Regex: utils.GenerateSemiGenericRegex([]string{ Regex: utils.GenerateSemiGenericRegex([]string{
"access",
"auth",
`(?-i:[Aa]pi|API)`,
"credential",
"creds",
"key", "key",
"api",
"token",
"secret",
"client",
"passwd", "passwd",
"password", "password",
"auth", "secret",
"access", "token",
}, `[0-9a-z\-_.=]{10,150}`, true), }, `[\w.=-]{10,150}`, true),
Keywords: []string{ Keywords: []string{
"key", "access",
"api", "api",
"token", "auth",
"secret", "key",
"client", "credential",
"creds",
"passwd", "passwd",
"password", "password",
"auth", "secret",
"access", "token",
}, },
Entropy: 3.5, Entropy: 3.5,
Allowlist: config.Allowlist{ Allowlists: []config.Allowlist{
StopWords: DefaultStopWords, {
// NOTE: this is a goofy hack to get around the fact there golang's regex engine does not support positive lookaheads.
// Ideally we would want to ensure the secret contains both numbers and alphabetical characters, not just alphabetical characters.
Regexes: []*regexp.Regexp{
regexp.MustCompile(`^[a-zA-Z_.-]+$`),
},
},
{
Description: "Allowlist for Generic API Keys",
MatchCondition: config.AllowlistMatchOr,
RegexTarget: "match",
Regexes: []*regexp.Regexp{
regexp.MustCompile(`(?i)(` +
// Access
`accessor` +
`|access[_.-]?id` +
// API
`|api[_.-]?(version|id)` + // version/id -> not a secret
`|rapid|capital` + // common words containing "api"
`|[a-z0-9-]*?api[a-z0-9-]*?:jar:` + // Maven META-INF dependencies that contain "api" in the name.
// Auth
`|author` +
`|X-MS-Exchange-Organization-Auth` + // email header
`|Authentication-Results` + // email header
// Credentials
`|(credentials?[_.-]?id|withCredentials)` + // Jenkins plugins
// Key
`|(bucket|foreign|hot|natural|primary|schema|sequence)[_.-]?key` +
`|key[_.-]?(alias|board|code|ring|selector|size|stone|storetype|word|up|down|left|right)` +
`|key(store|tab)[_.-]?(file|path)` +
`|issuerkeyhash` + // part of ssl cert
`|(?-i:[DdMm]onkey|[DM]ONKEY)|keying` + // common words containing "key"
// Secret
`|(secret)[_.-]?name` + // name of e.g. env variable
`|UserSecretsId` + // https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-8.0&tabs=linux
// Token
// General
`|(api|credentials|token)[_.-]?(endpoint|ur[il])` +
`|public[_.-]?(key|token)` + // public key -> not a secret
`|(key|token)[_.-]?file` +
`)`),
},
StopWords: DefaultStopWords,
},
}, },
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("generic", "CLOJARS_34bf0e88955ff5a1c328d6a7491acc4f48e865a7b8dd4d70a70749037443") //gitleaks:allow
tps = append(tps, utils.GenerateSampleSecrets("generic", "Zf3D0LXCM3EIMbgJpUNnkRtOfOueHznB")...)
tps = append(tps,
// Access
`'access_token': 'eyJ0eXAioiJKV1slS3oASx=='`,
// API
`some_api_token_123 = "`+newPlausibleSecret(`[a-zA-Z0-9]{60}`)+`"`,
// Auth
// Credentials
`"credentials" : "0afae57f3ccfd9d7f5767067bc48b30f719e271ba470488056e37ab35d4b6506"`,
`creds = `+newPlausibleSecret(`[a-zA-Z0-9]{30}`),
// Key
`private-key: `+newPlausibleSecret(`[a-zA-Z0-9\-_.=]{100}`),
// Password
`passwd = `+newPlausibleSecret(`[a-zA-Z0-9\-_.=]{30}`),
// TODO: `ID=dbuser;password=` + newPlausibleSecret(`[a-zA-Z0-9+/]{30}={0,3}`) + `;"`,
// Secret
`"client_secret" : "6da89121079f83b2eb6acccf8219ea982c3d79bccc3e9c6a85856480661f8fde",`,
`mySecretString=`+newPlausibleSecret(`[a-zA-Z0-9]{30}`),
`todo_secret_do_not_commit = `+newPlausibleSecret(`[a-zA-Z0-9]{30}`),
// Token
utils.GenerateSampleSecret("generic", "CLOJARS_34bf0e88955ff5a1c328d6a7491acc4f48e865a7b8dd4d70a70749037443"), //gitleaks:allow utils.GenerateSampleSecret("generic", "CLOJARS_34bf0e88955ff5a1c328d6a7491acc4f48e865a7b8dd4d70a70749037443"), //gitleaks:allow
utils.GenerateSampleSecret("generic", "Zf3D0LXCM3EIMbgJpUNnkRtOfOueHznB"), utils.GenerateSampleSecret("generic", "Zf3D0LXCM3EIMbgJpUNnkRtOfOueHznB"),
`"client_id" : "0afae57f3ccfd9d7f5767067bc48b30f719e271ba470488056e37ab35d4b6506"`, )
`"client_secret" : "6da89121079f83b2eb6acccf8219ea982c3d79bccc3e9c6a85856480661f8fde",`,
}
fps := []string{ fps := []string{
`client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.client-vpn-endpoint.id`, // Access
`"accessor":"rA1wk0Y45YCufyfq",`,
`report_access_id: e8e4df51-2054-49b0-ab1c-516ac95c691d`,
// API
`this.ultraPictureBox1.Name = "ultraPictureBox1";`,
`rapidstring:marm64-uwp=fail`,
`event-bus-message-api:rc0.15.0_20231217_1420-SNAPSHOT'`,
`COMMUNICATION_API_VERSION=rc0.13.0_20230412_0712-SNAPSHOT`,
`MantleAPI_version=9a038989604e8da62ecddbe2094b16ce1b778be1`,
`[DEBUG] org.slf4j.slf4j-api:jar:1.7.8.:compile (version managed from default)`,
`[DEBUG] org.neo4j.neo4j-graphdb-api:jar:3.5.12:test`,
`apiUrl=apigee.corpint.com`,
// TODO: Jetbrains IML files (requires line-level allowlist).
// `<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.directory.api:api-asn1-api:1.0.0-M20" level="projcet" />`
// Auth
`author = "james.fake@ymail.com",`,
`X-MS-Exchange-Organization-AuthSource: sm02915.int.contoso.com`,
`Authentication-Results: 5h.ca.iphmx.com`,
// Credentials
`withCredentials([usernamePassword(credentialsId: '29f63271-dc2f-4734-8221-5b31b5169bac', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {`,
`credentialsId: 'ff083f76-7804-4ef1-80e4-fe975bb9141b'`,
`jobCredentialsId: 'f4aeb6bc-2a25-458a-8111-9be9e502c0e7'`,
` "credentialId": "B9mTcFSck2LzJO2S3ols63",`,
`environment {
CREDENTIALS_ID = "K8S_CRED"
}`,
`dev.credentials.url=dev-lb1.api.f4ke.com:5215`,
// Key
`keyword: "Befaehigung_P2"`,
`public_key = "9Cnzj4p4WGeKLs1Pt8QuKUpRKfFLfRYC9AIKjbJTWit"`,
`monkeys-audio:mx64-uwp=fail`,
`primaryKey=` + newPlausibleSecret(`[a-zA-Z0-9\-_.=]{30}`),
`foreignKey=` + newPlausibleSecret(`[a-zA-Z0-9\-_.=]{30}`),
`key_down_event=` + newPlausibleSecret(`[a-zA-Z0-9\-_.=]{30}`),
`issuerKeyHash=` + newPlausibleSecret(`[a-zA-Z0-9\-_.=]{30}`),
`<entry key="jetbrains.mps.v8_elimination" value="executed" />`,
`minisat-master-keying:x64-uwp=fail`,
`IceSSL.KeyFile=s_rsa1024_priv.pem`,
`"bucket_key": "SalesResults-1.2"`,
// `<TAR key="REF_ID_923.properties" value="/opts/config/alias/"/>`,
`<key tag="SecurityIdentifier" name="SecurityIdentifier" type="STRING" />`,
// `packageKey":` + newPlausibleSecret(`[a-zA-Z0-9\-_.=]{30}`),
`schemaKey = 'DOC_Vector_5_32'`,
`sequenceKey = "18"`,
`app.keystore.file=env/cert.p12`,
`-DKEYTAB_FILE=/tmp/app.keytab`,
` doc.Security.KeySize = PdfEncryptionKeySize.Key128Bit;`,
`o.keySelector=n,o.haKey=!1,`,
// TODO: Requires line-level allowlists.
// `<add key="SchemaTable" value="G:\SchemaTable.xml" />`,
// `secret:
// secretName: app-decryption-secret
// items:
// - key: app-k8s.yml
// path: app-k8s.yml`,
// TODO: https://learn.microsoft.com/en-us/windows/apps/design/style/xaml-theme-resources
// `<Color x:Key="NormalBrushGradient1">#FFBAE4FF</Color>`,
// Password
`password combination. `password combination.
R5: Regulatory--21`, R5: Regulatory--21`,
`PuttyPassword=0`,
// Secret
`LLM_SECRET_NAME = "NEXUS-GPT4-API-KEY"`,
` <UserSecretsId>79a3edd0-2092-40a2-a04d-dcb46d5ca9ed</UserSecretsId>`,
// Token
` access_token_url='https://github.com/login/oauth/access_token',`,
`publicToken = "9Cnzj4p4WGeKLs1Pt8QuKUpRKfFLfRYC9AIKjbJTWit"`,
`<SourceFile SourceLocation="F:\Extracts\" TokenFile="RTL_INST_CODE.cer">`,
// TODO: `TOKEN_AUDIENCE = "25872395-ed3a-4703-b647-22ec53f3683c"`,
// General
`clientId = "73082700-1f09-405b-80d0-3131bfd6272d"`,
} }
return utils.Validate(r, tps, fps) return utils.Validate(r, tps, fps)
} }
func newPlausibleSecret(regex string) string {
allowList := config.Allowlist{StopWords: DefaultStopWords}
// attempt to generate a random secret,
// retrying until it contains at least one digit and no stop words
// TODO: currently the DefaultStopWords list contains many short words,
// so there is a significant chance of generating a secret that contains a stop word
for {
secret := secrets.NewSecret(regex)
if !regexp.MustCompile(`[1-9]`).MatchString(secret) {
continue
}
if allowList.ContainsStopWord(secret) {
continue
}
return secret
}
}
+25 -23
View File
@@ -1,27 +1,36 @@
package rules package rules
import ( import (
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
) )
var githubAllowlist = []config.Allowlist{
{
Paths: []*regexp.Regexp{
// https://github.com/octokit/auth-token.js/?tab=readme-ov-file#createtokenauthtoken-options
regexp.MustCompile(`(^|/)@octokit/auth-token/README\.md$`),
},
},
}
func GitHubPat() *config.Rule { func GitHubPat() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Uncovered a GitHub Personal Access Token, potentially leading to unauthorized repository access and sensitive content exposure.",
RuleID: "github-pat", RuleID: "github-pat",
Description: "Uncovered a GitHub Personal Access Token, potentially leading to unauthorized repository access and sensitive content exposure.",
Regex: regexp.MustCompile(`ghp_[0-9a-zA-Z]{36}`), Regex: regexp.MustCompile(`ghp_[0-9a-zA-Z]{36}`),
Entropy: 3, Entropy: 3,
Keywords: []string{"ghp_"}, Keywords: []string{"ghp_"},
Allowlists: githubAllowlist,
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("github", "ghp_"+secrets.NewSecret(utils.AlphaNumeric("36")))
utils.GenerateSampleSecret("github", "ghp_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
}
fps := []string{ fps := []string{
"ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
} }
@@ -31,17 +40,15 @@ func GitHubPat() *config.Rule {
func GitHubFineGrainedPat() *config.Rule { func GitHubFineGrainedPat() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Found a GitHub Fine-Grained Personal Access Token, risking unauthorized repository access and code manipulation.",
RuleID: "github-fine-grained-pat", RuleID: "github-fine-grained-pat",
Description: "Found a GitHub Fine-Grained Personal Access Token, risking unauthorized repository access and code manipulation.",
Regex: regexp.MustCompile(`github_pat_\w{82}`), Regex: regexp.MustCompile(`github_pat_\w{82}`),
Entropy: 3, Entropy: 3,
Keywords: []string{"github_pat_"}, Keywords: []string{"github_pat_"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("github", "github_pat_"+secrets.NewSecret(utils.AlphaNumeric("82")))
utils.GenerateSampleSecret("github", "github_pat_"+secrets.NewSecret(utils.AlphaNumeric("82"))),
}
fps := []string{ fps := []string{
"github_pat_xxxxxxxxxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "github_pat_xxxxxxxxxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
} }
@@ -51,17 +58,15 @@ func GitHubFineGrainedPat() *config.Rule {
func GitHubOauth() *config.Rule { func GitHubOauth() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Discovered a GitHub OAuth Access Token, posing a risk of compromised GitHub account integrations and data leaks.",
RuleID: "github-oauth", RuleID: "github-oauth",
Description: "Discovered a GitHub OAuth Access Token, posing a risk of compromised GitHub account integrations and data leaks.",
Regex: regexp.MustCompile(`gho_[0-9a-zA-Z]{36}`), Regex: regexp.MustCompile(`gho_[0-9a-zA-Z]{36}`),
Entropy: 3, Entropy: 3,
Keywords: []string{"gho_"}, Keywords: []string{"gho_"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("github", "gho_"+secrets.NewSecret(utils.AlphaNumeric("36")))
utils.GenerateSampleSecret("github", "gho_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
}
fps := []string{ fps := []string{
"gho_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "gho_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
} }
@@ -71,18 +76,17 @@ func GitHubOauth() *config.Rule {
func GitHubApp() *config.Rule { func GitHubApp() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Identified a GitHub App Token, which may compromise GitHub application integrations and source code security.",
RuleID: "github-app-token", RuleID: "github-app-token",
Description: "Identified a GitHub App Token, which may compromise GitHub application integrations and source code security.",
Regex: regexp.MustCompile(`(?:ghu|ghs)_[0-9a-zA-Z]{36}`), Regex: regexp.MustCompile(`(?:ghu|ghs)_[0-9a-zA-Z]{36}`),
Entropy: 3, Entropy: 3,
Keywords: []string{"ghu_", "ghs_"}, Keywords: []string{"ghu_", "ghs_"},
Allowlists: githubAllowlist,
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("github", "ghs_"+secrets.NewSecret(utils.AlphaNumeric("36")))
utils.GenerateSampleSecret("github", "ghu_"+secrets.NewSecret(utils.AlphaNumeric("36"))), tps = append(tps, utils.GenerateSampleSecrets("github", "ghu_"+secrets.NewSecret(utils.AlphaNumeric("36")))...)
utils.GenerateSampleSecret("github", "ghs_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
}
fps := []string{ fps := []string{
"ghu_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "ghu_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"ghs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "ghs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
@@ -93,17 +97,15 @@ func GitHubApp() *config.Rule {
func GitHubRefresh() *config.Rule { func GitHubRefresh() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Detected a GitHub Refresh Token, which could allow prolonged unauthorized access to GitHub services.",
RuleID: "github-refresh-token", RuleID: "github-refresh-token",
Description: "Detected a GitHub Refresh Token, which could allow prolonged unauthorized access to GitHub services.",
Regex: regexp.MustCompile(`ghr_[0-9a-zA-Z]{36}`), Regex: regexp.MustCompile(`ghr_[0-9a-zA-Z]{36}`),
Entropy: 3, Entropy: 3,
Keywords: []string{"ghr_"}, Keywords: []string{"ghr_"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("github", "ghr_"+secrets.NewSecret(utils.AlphaNumeric("36")))
utils.GenerateSampleSecret("github", "ghr_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
}
fps := []string{ fps := []string{
"ghr_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "ghr_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
} }
+169 -19
View File
@@ -1,57 +1,207 @@
package rules package rules
import ( import (
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
) )
// overview with all GitLab tokens:
// https://docs.gitlab.com/ee/security/tokens/index.html#token-prefixes
func GitlabCiCdJobToken() *config.Rule {
r := config.Rule{
RuleID: "gitlab-cicd-job-token",
Description: "Identified a GitLab CI/CD Job Token, potential access to projects and some APIs on behalf of a user while the CI job is running.",
Regex: regexp.MustCompile(`glcbt-[0-9a-zA-Z]{1,5}_[0-9a-zA-Z_-]{20}`),
Entropy: 3,
Keywords: []string{"glcbt-"},
}
tps := utils.GenerateSampleSecrets("gitlab", "glcbt-"+secrets.NewSecret(utils.AlphaNumeric("5"))+"_"+secrets.NewSecret(utils.AlphaNumeric("20")))
return utils.Validate(r, tps, nil)
}
func GitlabDeployToken() *config.Rule {
r := config.Rule{
Description: "Identified a GitLab Deploy Token, risking access to repositories, packages and containers with write access.",
RuleID: "gitlab-deploy-token",
Regex: regexp.MustCompile(`gldt-[0-9a-zA-Z_\-]{20}`),
Entropy: 3,
Keywords: []string{"gldt-"},
}
tps := []string{
utils.GenerateSampleSecret("gitlab", "gldt-"+secrets.NewSecret(utils.AlphaNumeric("20"))),
}
return utils.Validate(r, tps, nil)
}
func GitlabFeatureFlagClientToken() *config.Rule {
r := config.Rule{
RuleID: "gitlab-feature-flag-client-token",
Description: "Identified a GitLab feature flag client token, risks exposing user lists and features flags used by an application.",
Regex: regexp.MustCompile(`glffct-[0-9a-zA-Z_\-]{20}`),
Entropy: 3,
Keywords: []string{"glffct-"},
}
tps := utils.GenerateSampleSecrets("gitlab", "glffct-"+secrets.NewSecret(utils.AlphaNumeric("20")))
return utils.Validate(r, tps, nil)
}
func GitlabFeedToken() *config.Rule {
r := config.Rule{
RuleID: "gitlab-feed-token",
Description: "Identified a GitLab feed token, risking exposure of user data.",
Regex: regexp.MustCompile(`glft-[0-9a-zA-Z_\-]{20}`),
Entropy: 3,
Keywords: []string{"glft-"},
}
tps := utils.GenerateSampleSecrets("gitlab", "glft-"+secrets.NewSecret(utils.AlphaNumeric("20")))
return utils.Validate(r, tps, nil)
}
func GitlabIncomingMailToken() *config.Rule {
r := config.Rule{
RuleID: "gitlab-incoming-mail-token",
Description: "Identified a GitLab incoming mail token, risking manipulation of data sent by mail.",
Regex: regexp.MustCompile(`glimt-[0-9a-zA-Z_\-]{25}`),
Entropy: 3,
Keywords: []string{"glimt-"},
}
tps := utils.GenerateSampleSecrets("gitlab", "glimt-"+secrets.NewSecret(utils.AlphaNumeric("25")))
return utils.Validate(r, tps, nil)
}
func GitlabKubernetesAgentToken() *config.Rule {
r := config.Rule{
RuleID: "gitlab-kubernetes-agent-token",
Description: "Identified a GitLab Kubernetes Agent token, risking access to repos and registry of projects connected via agent.",
Regex: regexp.MustCompile(`glagent-[0-9a-zA-Z_\-]{50}`),
Entropy: 3,
Keywords: []string{"glagent-"},
}
tps := utils.GenerateSampleSecrets("gitlab", "glagent-"+secrets.NewSecret(utils.AlphaNumeric("50")))
return utils.Validate(r, tps, nil)
}
func GitlabOauthAppSecret() *config.Rule {
r := config.Rule{
RuleID: "gitlab-oauth-app-secret",
Description: "Identified a GitLab OIDC Application Secret, risking access to apps using GitLab as authentication provider.",
Regex: regexp.MustCompile(`gloas-[0-9a-zA-Z_\-]{64}`),
Entropy: 3,
Keywords: []string{"gloas-"},
}
tps := utils.GenerateSampleSecrets("gitlab", "gloas-"+secrets.NewSecret(utils.AlphaNumeric("64")))
return utils.Validate(r, tps, nil)
}
func GitlabPat() *config.Rule { func GitlabPat() *config.Rule {
// define rule
r := config.Rule{ r := config.Rule{
Description: "Identified a GitLab Personal Access Token, risking unauthorized access to GitLab repositories and codebase exposure.",
RuleID: "gitlab-pat", RuleID: "gitlab-pat",
Regex: regexp.MustCompile(`glpat-[0-9a-zA-Z\-\_]{20}`), Description: "Identified a GitLab Personal Access Token, risking unauthorized access to GitLab repositories and codebase exposure.",
Regex: regexp.MustCompile(`glpat-[\w-]{20}`),
Entropy: 3,
Keywords: []string{"glpat-"}, Keywords: []string{"glpat-"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("gitlab", "glpat-"+secrets.NewSecret(utils.AlphaNumeric("20")))
utils.GenerateSampleSecret("gitlab", "glpat-"+secrets.NewSecret(utils.AlphaNumeric("20"))), fps := []string{
"glpat-XXXXXXXXXXX-XXXXXXXX",
} }
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, fps)
}
func GitlabPatRoutable() *config.Rule {
r := config.Rule{
RuleID: "gitlab-pat-routable",
Description: "Identified a GitLab Personal Access Token (routable), risking unauthorized access to GitLab repositories and codebase exposure.",
Regex: regexp.MustCompile(`\bglpat-[0-9a-zA-Z_-]{27,300}\.[0-9a-z]{2}[0-9a-z]{7}\b`),
Entropy: 4,
Keywords: []string{"glpat-"},
}
// validate
tps := utils.GenerateSampleSecrets("gitlab", "glpat-"+secrets.NewSecret(utils.AlphaNumeric("27"))+"."+secrets.NewSecret(utils.AlphaNumeric("2"))+secrets.NewSecret(utils.AlphaNumeric("7")))
fps := []string{
"glpat-xxxxxxxx-xxxxxxxxxxxxxxxxxx.xxxxxxxxx",
}
return utils.Validate(r, tps, fps)
} }
func GitlabPipelineTriggerToken() *config.Rule { func GitlabPipelineTriggerToken() *config.Rule {
// define rule
r := config.Rule{ r := config.Rule{
Description: "Found a GitLab Pipeline Trigger Token, potentially compromising continuous integration workflows and project security.",
RuleID: "gitlab-ptt", RuleID: "gitlab-ptt",
Description: "Found a GitLab Pipeline Trigger Token, potentially compromising continuous integration workflows and project security.",
Regex: regexp.MustCompile(`glptt-[0-9a-f]{40}`), Regex: regexp.MustCompile(`glptt-[0-9a-f]{40}`),
Entropy: 3,
Keywords: []string{"glptt-"}, Keywords: []string{"glptt-"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("gitlab", "glptt-"+secrets.NewSecret(utils.Hex("40")))
utils.GenerateSampleSecret("gitlab", "glptt-"+secrets.NewSecret(utils.Hex("40"))), fps := []string{
"glptt-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
} }
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, fps)
} }
func GitlabRunnerRegistrationToken() *config.Rule { func GitlabRunnerRegistrationToken() *config.Rule {
// define rule
r := config.Rule{ r := config.Rule{
Description: "Discovered a GitLab Runner Registration Token, posing a risk to CI/CD pipeline integrity and unauthorized access.",
RuleID: "gitlab-rrt", RuleID: "gitlab-rrt",
Regex: regexp.MustCompile(`GR1348941[0-9a-zA-Z\-\_]{20}`), Description: "Discovered a GitLab Runner Registration Token, posing a risk to CI/CD pipeline integrity and unauthorized access.",
Regex: regexp.MustCompile(`GR1348941[\w-]{20}`),
Entropy: 3,
Keywords: []string{"GR1348941"}, Keywords: []string{"GR1348941"},
} }
// validate tps := utils.GenerateSampleSecrets("gitlab", "GR1348941"+secrets.NewSecret(utils.AlphaNumeric("20")))
tps := []string{ fps := []string{
utils.GenerateSampleSecret("gitlab", "GR1348941"+secrets.NewSecret(utils.AlphaNumeric("20"))), "GR134894112312312312312312312",
"GR1348941XXXXXXXXXXXXXXXXXXXX",
} }
return utils.Validate(r, tps, fps)
}
func GitlabRunnerAuthenticationToken() *config.Rule {
r := config.Rule{
RuleID: "gitlab-runner-authentication-token",
Description: "Discovered a GitLab Runner Authentication Token, posing a risk to CI/CD pipeline integrity and unauthorized access.",
Regex: regexp.MustCompile(`glrt-[0-9a-zA-Z_\-]{20}`),
Entropy: 3,
Keywords: []string{"glrt-"},
}
tps := utils.GenerateSampleSecrets("gitlab", "glrt-"+secrets.NewSecret(utils.AlphaNumeric("20")))
return utils.Validate(r, tps, nil)
}
func GitlabScimToken() *config.Rule {
r := config.Rule{
RuleID: "gitlab-scim-token",
Description: "Discovered a GitLab SCIM Token, posing a risk to unauthorized access for a organization or instance.",
Regex: regexp.MustCompile(`glsoat-[0-9a-zA-Z_\-]{20}`),
Entropy: 3,
Keywords: []string{"glsoat-"},
}
tps := utils.GenerateSampleSecrets("gitlab", "glsoat-"+secrets.NewSecret(utils.AlphaNumeric("20")))
return utils.Validate(r, tps, nil)
}
func GitlabSessionCookie() *config.Rule {
r := config.Rule{
RuleID: "gitlab-session-cookie",
Description: "Discovered a GitLab Session Cookie, posing a risk to unauthorized access to a user account.",
Regex: regexp.MustCompile(`_gitlab_session=[0-9a-z]{32}`),
Entropy: 3,
Keywords: []string{"_gitlab_session="},
}
// validate
tps := utils.GenerateSampleSecrets("gitlab", "_gitlab_session="+secrets.NewSecret(utils.AlphaNumeric("32")))
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+1 -4
View File
@@ -20,9 +20,6 @@ func GitterAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("gitter", secrets.NewSecret(utils.AlphaNumericExtendedShort("40")))
utils.GenerateSampleSecret("gitter",
secrets.NewSecret(utils.AlphaNumericExtendedShort("40"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+1 -3
View File
@@ -20,8 +20,6 @@ func GoCardless() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("gocardless", "live_"+secrets.NewSecret(utils.AlphaNumericExtended("40")))
utils.GenerateSampleSecret("gocardless", "live_"+secrets.NewSecret(utils.AlphaNumericExtended("40"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+40 -26
View File
@@ -9,58 +9,72 @@ import (
func GrafanaApiKey() *config.Rule { func GrafanaApiKey() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Identified a Grafana API key, which could compromise monitoring dashboards and sensitive data analytics.",
RuleID: "grafana-api-key", RuleID: "grafana-api-key",
Description: "Identified a Grafana API key, which could compromise monitoring dashboards and sensitive data analytics.",
Regex: utils.GenerateUniqueTokenRegex(`eyJrIjoi[A-Za-z0-9]{70,400}={0,2}`, true), Regex: utils.GenerateUniqueTokenRegex(`eyJrIjoi[A-Za-z0-9]{70,400}={0,3}`, true),
Keywords: []string{"eyJrIjoi"}, Entropy: 3,
Keywords: []string{"eyJrIjoi"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("grafana-api-key", "eyJrIjoi"+secrets.NewSecret(utils.AlphaNumeric("70")))
utils.GenerateSampleSecret("grafana-api-key",
"eyJrIjoi"+
secrets.NewSecret(utils.AlphaNumeric("70"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func GrafanaCloudApiToken() *config.Rule { func GrafanaCloudApiToken() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Found a Grafana cloud API token, risking unauthorized access to cloud-based monitoring services and data exposure.",
RuleID: "grafana-cloud-api-token", RuleID: "grafana-cloud-api-token",
Description: "Found a Grafana cloud API token, risking unauthorized access to cloud-based monitoring services and data exposure.",
Regex: utils.GenerateUniqueTokenRegex(`glc_[A-Za-z0-9+/]{32,400}={0,2}`, true), Regex: utils.GenerateUniqueTokenRegex(`glc_[A-Za-z0-9+/]{32,400}={0,3}`, true),
Keywords: []string{"glc_"}, Entropy: 3,
Keywords: []string{"glc_"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("grafana-cloud-api-token", "glc_"+secrets.NewSecret(utils.AlphaNumeric("32")))
tps = append(tps,
utils.GenerateSampleSecret("grafana-cloud-api-token", utils.GenerateSampleSecret("grafana-cloud-api-token",
"glc_"+ "glc_"+
secrets.NewSecret(utils.AlphaNumeric("32"))), secrets.NewSecret(utils.AlphaNumeric("32"))),
`loki_key: glc_eyJvIjoiNzQ0NTg3IiwibiI7InN0YWlrLTQ3NTgzMC1obC13cml0ZS1oYW5kc29uJG9raSIsImsiOiI4M2w3cmdYUlBoMTUyMW1lMU023nl5UDUiLCJtIjp7IOIiOiJ1cyJ9fQ==`,
// TODO:
//` loki:
//endpoint: https://322137:glc_eyJvIjoiNzQ0NTg3IiwibiI7InN0YWlrLTQ3NTgzMC1obC13cml0ZS1oYW5kc29uJG9raSIsImsiOiI4M2w3cmdYUlBoMTUyMW1lMU023nl5UDUiLCJtIjp7IOIiOiJ1cyJ9fQ==@logs-prod4.grafana.net/loki/api/v1/push`,
)
fps := []string{
// Low entropy.
`glc_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`,
` API_KEY="glc_111111111111111111111111111111111111111111="`,
// Invalid.
`static void GLC_CreateLightmapTextureArray(void);
static void GLC_CreateLightmapTexturesIndividual(void);
void GLC_UploadLightmap(int textureUnit, int lightmapnum);`,
`// Alias models
void GLC_StateBeginUnderwaterAliasModelCaustics(texture_ref base_texture, texture_ref caustics_texture)
{`,
} }
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, fps)
} }
func GrafanaServiceAccountToken() *config.Rule { func GrafanaServiceAccountToken() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Discovered a Grafana service account token, posing a risk of compromised monitoring services and data integrity.",
RuleID: "grafana-service-account-token", RuleID: "grafana-service-account-token",
Description: "Discovered a Grafana service account token, posing a risk of compromised monitoring services and data integrity.",
Regex: utils.GenerateUniqueTokenRegex(`glsa_[A-Za-z0-9]{32}_[A-Fa-f0-9]{8}`, true), Regex: utils.GenerateUniqueTokenRegex(`glsa_[A-Za-z0-9]{32}_[A-Fa-f0-9]{8}`, true),
Keywords: []string{"glsa_"}, Entropy: 3,
Keywords: []string{"glsa_"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("grafana-service-account-token", "glsa_"+secrets.NewSecret(utils.AlphaNumeric("32"))+"_"+secrets.NewSecret(utils.Hex("8")))
utils.GenerateSampleSecret("grafana-service-account-token", tps = append(tps,
"glsa_"+ `'Authorization': 'Bearer glsa_pITqMOBIfNH2KL4PkXJqmTyQl0D9QGxF_486f63e1'`,
secrets.NewSecret(utils.AlphaNumeric("32"))+ )
"_"+ fps := []string{
secrets.NewSecret((utils.Hex("8")))), "glsa_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX_AAAAAAAA",
} }
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, fps)
} }
+5 -6
View File
@@ -1,12 +1,13 @@
package rules package rules
import ( import (
"regexp" regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
) )
func HarnessApiKey() *config.Rule { func HarnessApiKey() *config.Rule {
@@ -19,10 +20,8 @@ func HarnessApiKey() *config.Rule {
} }
// Generate a sample secret for validation // Generate a sample secret for validation
tps := []string{ tps := utils.GenerateSampleSecrets("harness", "pat."+secrets.NewSecret(utils.AlphaNumeric("22"))+"."+secrets.NewSecret(utils.AlphaNumeric("24"))+"."+secrets.NewSecret(utils.AlphaNumeric("20")))
utils.GenerateSampleSecret("harness", "pat."+secrets.NewSecret(utils.AlphaNumeric("22"))+"."+secrets.NewSecret(utils.AlphaNumeric("24"))+"."+secrets.NewSecret(utils.AlphaNumeric("20"))), tps = append(tps, utils.GenerateSampleSecrets("harness", "sat."+secrets.NewSecret(utils.AlphaNumeric("22"))+"."+secrets.NewSecret(utils.AlphaNumeric("24"))+"."+secrets.NewSecret(utils.AlphaNumeric("20")))...)
utils.GenerateSampleSecret("harness", "sat."+secrets.NewSecret(utils.AlphaNumeric("22"))+"."+secrets.NewSecret(utils.AlphaNumeric("24"))+"."+secrets.NewSecret(utils.AlphaNumeric("20"))),
}
// validate the rule // validate the rule
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
+11 -8
View File
@@ -2,28 +2,30 @@ package rules
import ( import (
"fmt" "fmt"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
) )
func HashiCorpTerraform() *config.Rule { func HashiCorpTerraform() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Uncovered a HashiCorp Terraform user/org API token, which may lead to unauthorized infrastructure management and security breaches.",
RuleID: "hashicorp-tf-api-token", RuleID: "hashicorp-tf-api-token",
Description: "Uncovered a HashiCorp Terraform user/org API token, which may lead to unauthorized infrastructure management and security breaches.",
Regex: regexp.MustCompile(`(?i)[a-z0-9]{14}\.(?-i:atlasv1)\.[a-z0-9\-_=]{60,70}`), Regex: regexp.MustCompile(`(?i)[a-z0-9]{14}\.(?-i:atlasv1)\.[a-z0-9\-_=]{60,70}`),
Entropy: 3.5, Entropy: 3.5,
Keywords: []string{"atlasv1"}, Keywords: []string{"atlasv1"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("hashicorpToken", secrets.NewSecret(utils.Hex("14"))+".atlasv1."+secrets.NewSecret(utils.AlphaNumericExtended("60,70")))
utils.GenerateSampleSecret("hashicorpToken", secrets.NewSecret(utils.Hex("14"))+".atlasv1."+secrets.NewSecret(utils.AlphaNumericExtended("60,70"))), tps = append(tps,
`#token = "hE1hlYILrSqpqh.atlasv1.ARjZuyzl33F71WR55s6ln5GQ1HWIwTDDH3MiRjz7OnpCfaCb1RCF5zGaSncCWmJdcYA"`, `#token = "hE1hlYILrSqpqh.atlasv1.ARjZuyzl33F71WR55s6ln5GQ1HWIwTDDH3MiRjz7OnpCfaCb1RCF5zGaSncCWmJdcYA"`,
} )
fps := []string{ fps := []string{
`token = "xxxxxxxxxxxxxx.atlasv1.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"`, // low entropy `token = "xxxxxxxxxxxxxx.atlasv1.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"`, // low entropy
} }
@@ -34,11 +36,12 @@ func HashicorpField() *config.Rule {
keywords := []string{"administrator_login_password", "password"} keywords := []string{"administrator_login_password", "password"}
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Identified a HashiCorp Terraform password field, risking unauthorized infrastructure configuration and security breaches.",
RuleID: "hashicorp-tf-password", RuleID: "hashicorp-tf-password",
Description: "Identified a HashiCorp Terraform password field, risking unauthorized infrastructure configuration and security breaches.",
Regex: utils.GenerateSemiGenericRegex(keywords, fmt.Sprintf(`"%s"`, utils.AlphaNumericExtended("8,20")), true), Regex: utils.GenerateSemiGenericRegex(keywords, fmt.Sprintf(`"%s"`, utils.AlphaNumericExtended("8,20")), true),
Keywords: keywords, Entropy: 2,
Path: regexp.MustCompile(`(?i)\.(?:tf|hcl)$`), Path: regexp.MustCompile(`(?i)\.(?:tf|hcl)$`),
Keywords: keywords,
} }
tps := map[string]string{ tps := map[string]string{
+20 -15
View File
@@ -1,10 +1,12 @@
package rules package rules
import ( import (
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
"regexp"
) )
func VaultServiceToken() *config.Rule { func VaultServiceToken() *config.Rule {
@@ -14,11 +16,13 @@ func VaultServiceToken() *config.Rule {
Description: "Identified a Vault Service Token, potentially compromising infrastructure security and access to sensitive credentials.", Description: "Identified a Vault Service Token, potentially compromising infrastructure security and access to sensitive credentials.",
Regex: utils.GenerateUniqueTokenRegex(`(?:hvs\.[\w-]{90,120}|s\.(?i:[a-z0-9]{24}))`, false), Regex: utils.GenerateUniqueTokenRegex(`(?:hvs\.[\w-]{90,120}|s\.(?i:[a-z0-9]{24}))`, false),
Entropy: 3.5, Entropy: 3.5,
Keywords: []string{"hvs", "s."}, Keywords: []string{"hvs.", "s."},
Allowlist: config.Allowlist{ Allowlists: []config.Allowlist{
Regexes: []*regexp.Regexp{ {
// https://github.com/gitleaks/gitleaks/issues/1490#issuecomment-2334166357 Regexes: []*regexp.Regexp{
regexp.MustCompile(`s\.[A-Za-z]{24}`), // https://github.com/gitleaks/gitleaks/issues/1490#issuecomment-2334166357
regexp.MustCompile(`s\.[A-Za-z]{24}`),
},
}, },
}, },
} }
@@ -26,12 +30,13 @@ func VaultServiceToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
// Old // Old
utils.GenerateSampleSecret("vault", "s."+secrets.NewSecret(utils.AlphaNumeric("24"))), utils.GenerateSampleSecret("vault", secrets.NewSecret(`s\.[0-9][a-zA-Z0-9]{23}`)),
`token: s.ZC9Ecf4M5g9o34Q6RkzGsj0z`, `token: s.ZC9Ecf4M5g9o34Q6RkzGsj0z`,
// New // New
utils.GenerateSampleSecret("vault", "hvs."+secrets.NewSecret(utils.AlphaNumericExtendedShort("90"))), utils.GenerateSampleSecret("vault", secrets.NewSecret(`hvs\.[0-9][\w\-]{89}`)),
`-vaultToken hvs.CAESIP2jTxc9S2K7Z6CtcFWQv7-044m_oSsxnPE1H3nF89l3GiYKHGh2cy5sQmlIZVNyTWJNcDRsYWJpQjlhYjVlb1cQh6PL8wEYAg"`, // longer than 100 chars `-vaultToken hvs.CAESIP2jTxc9S2K7Z6CtcFWQv7-044m_oSsxnPE1H3nF89l3GiYKHGh2cy5sQmlIZVNyTWJNcDRsYWJpQjlhYjVlb1cQh6PL8wEYAg"`, // longer than 100 chars
} }
fps := []string{ fps := []string{
// Old // Old
` credentials: new AWS.SharedIniFileCredentials({ profile: '<YOUR_PROFILE>' })`, // word boundary start ` credentials: new AWS.SharedIniFileCredentials({ profile: '<YOUR_PROFILE>' })`, // word boundary start
@@ -50,15 +55,15 @@ func VaultServiceToken() *config.Rule {
func VaultBatchToken() *config.Rule { func VaultBatchToken() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Detected a Vault Batch Token, risking unauthorized access to secret management services and sensitive data.",
RuleID: "vault-batch-token", RuleID: "vault-batch-token",
Regex: utils.GenerateUniqueTokenRegex(`hvb\.[a-z0-9_-]{138,212}`, true), Description: "Detected a Vault Batch Token, risking unauthorized access to secret management services and sensitive data.",
Keywords: []string{"hvb"}, Regex: utils.GenerateUniqueTokenRegex(`hvb\.[\w-]{138,300}`, false),
Entropy: 4,
Keywords: []string{"hvb."},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("vault", "hvb."+secrets.NewSecret(utils.AlphaNumericExtendedShort("138")))
utils.GenerateSampleSecret("vault", "hvb."+secrets.NewSecret(utils.AlphaNumericExtendedShort("138"))), tps = append(tps, `hvb.AAAAAQJgxDgqsGNorpoOR7hPZ5SU-ynBvCl764jyRP_fnX7WvkdkDzGjbLNGdPdtlY33Als2P36yDZueqzfdGw9RsaTeaYXSH7E4RYSWuRoQ9YRKIw8o7mDDY2ZcT3KOB7RwtW1w1FN2eDqcy_sbCjXPaM1iBVH-mqMSYRmRd2nb5D1SJPeBzIYRqSglLc31wUGN7xEzyrKUczqOKsIcybQA`) // gitleaks:allow
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -2
View File
@@ -2,6 +2,7 @@ package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -16,9 +17,10 @@ func Heroku() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("heroku", secrets.NewSecret(utils.Hex8_4_4_4_12()))
tps = append(tps,
`const HEROKU_KEY = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow `const HEROKU_KEY = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow
`heroku_api_key = "832d2129-a846-4e27-99f4-7004b6ad53ef"`, // gitleaks:allow `heroku_api_key = "832d2129-a846-4e27-99f4-7004b6ad53ef"`, // gitleaks:allow
} )
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -2
View File
@@ -2,6 +2,7 @@ package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -17,8 +18,9 @@ func HubSpot() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("hubspot", secrets.NewSecret(utils.Hex8_4_4_4_12()))
tps = append(tps,
`const hubspotKey = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow `const hubspotKey = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow
} )
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+15 -15
View File
@@ -2,9 +2,8 @@ package rules
import ( import (
"fmt" "fmt"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -18,16 +17,16 @@ func HuggingFaceAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "huggingface-access-token", RuleID: "huggingface-access-token",
Description: "Discovered a Hugging Face Access token, which could lead to unauthorized access to AI models and sensitive data.", Description: "Discovered a Hugging Face Access token, which could lead to unauthorized access to AI models and sensitive data.",
Regex: regexp.MustCompile(`(?:^|[\\'"` + "`" + ` >=:])(hf_[a-zA-Z]{34})(?:$|[\\'"` + "`" + ` <])`), Regex: utils.GenerateUniqueTokenRegex("hf_(?i:[a-z]{34})", false),
Entropy: 2,
Entropy: 1,
Keywords: []string{ Keywords: []string{
"hf_", "hf_",
}, },
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("huggingface", "hf_"+secrets.NewSecret("[a-zA-Z]{34}"))
tps = append(tps,
`huggingface-cli login --token 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`, `huggingface-cli login --token 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`,
`huggingface-cli login --token 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`, `huggingface-cli login --token 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`,
`huggingface-cli login --token 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`, `huggingface-cli login --token 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`,
@@ -41,11 +40,11 @@ func HuggingFaceAccessToken() *config.Rule {
`use_auth_token='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')`, `use_auth_token='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')`,
`CI_HUB_USER_TOKEN = "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"`, `CI_HUB_USER_TOKEN = "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"`,
`- Change line 5 and add your Hugging Face token, that is, instead of 'hf_token = "ADD_YOUR_HUGGING_FACE_TOKEN_HERE"', you will need to change it to something like'hf_token = "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"'`, `- Change line 5 and add your Hugging Face token, that is, instead of 'hf_token = "ADD_YOUR_HUGGING_FACE_TOKEN_HERE"', you will need to change it to something like'hf_token = "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"'`,
` " hf_token = \"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\"\n",`, //TODO: ` " hf_token = \"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\"\n",`,
`# Not critical, only usable on the sandboxed CI instance. `# Not critical, only usable on the sandboxed CI instance.
TOKEN = "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"`, TOKEN = "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"`,
` parser.add_argument("--hf_token", type=str, default='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', help="Hugging Face Access Token to access PyAnnote gated models")`, ` parser.add_argument("--hf_token", type=str, default='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', help="Hugging Face Access Token to access PyAnnote gated models")`,
} )
fps := []string{ fps := []string{
`- (id)hf_requiredCharacteristicTypesForDisplayMetadata;`, `- (id)hf_requiredCharacteristicTypesForDisplayMetadata;`,
`amazon.de#@#div[data-cel-widget="desktop-rhf_SponsoredProductsRemoteRHFSearchEXPSubsK2ClickPagination"]`, `amazon.de#@#div[data-cel-widget="desktop-rhf_SponsoredProductsRemoteRHFSearchEXPSubsK2ClickPagination"]`,
@@ -73,7 +72,7 @@ func HuggingFaceOrganizationApiToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "huggingface-organization-api-token", RuleID: "huggingface-organization-api-token",
Description: "Uncovered a Hugging Face Organization API token, potentially compromising AI organization accounts and associated data.", Description: "Uncovered a Hugging Face Organization API token, potentially compromising AI organization accounts and associated data.",
Regex: regexp.MustCompile(`(?:^|[\\'"` + "`" + ` >=:\(,)])(api_org_[a-zA-Z]{34})(?:$|[\\'"` + "`" + ` <\),])`), Regex: utils.GenerateUniqueTokenRegex("api_org_(?i:[a-z]{34})", false),
Entropy: 2, Entropy: 2,
Keywords: []string{ Keywords: []string{
@@ -82,14 +81,15 @@ func HuggingFaceOrganizationApiToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("huggingface", "api_org_"+secrets.NewSecret("[a-zA-Z]{34}"))
tps = append(tps,
`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`, `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`,
"`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`", "`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`",
`\'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'\`, `\'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'\`,
`\"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\"`, //TODO: `\"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\"`,
`,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,`, //TODO: `,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,`,
`(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)`, //TODO: `(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)`,
`<foo>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</foo>`, //TODO: `<foo>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</foo>`,
`def test_private_space(self): `def test_private_space(self):
hf_token = "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" # Intentionally revealing this key for testing purposes hf_token = "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" # Intentionally revealing this key for testing purposes
io = gr.load(`, io = gr.load(`,
@@ -97,7 +97,7 @@ func HuggingFaceOrganizationApiToken() *config.Rule {
`"news_train_dataset = datasets.load_dataset('nlpHakdang/aihub-news30k', data_files = \"train_news_text.csv\", use_auth_token='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')\n",`, `"news_train_dataset = datasets.load_dataset('nlpHakdang/aihub-news30k', data_files = \"train_news_text.csv\", use_auth_token='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')\n",`,
`os.environ['HUGGINGFACEHUB_API_TOKEN'] = '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'`, `os.environ['HUGGINGFACEHUB_API_TOKEN'] = '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'`,
fmt.Sprintf("api_org_%s", secrets.NewSecret(`[a-zA-Z]{34}`)), fmt.Sprintf("api_org_%s", secrets.NewSecret(`[a-zA-Z]{34}`)),
} )
fps := []string{ fps := []string{
`public static final String API_ORG_EXIST = "APIOrganizationExist";`, `public static final String API_ORG_EXIST = "APIOrganizationExist";`,
`const api_org_controller = require('../../controllers/api/index').organizations;`, `const api_org_controller = require('../../controllers/api/index').organizations;`,
+25 -15
View File
@@ -9,24 +9,34 @@ import (
func InfracostAPIToken() *config.Rule { func InfracostAPIToken() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
// Human readable description of the rule RuleID: "infracost-api-token",
Description: "Detected an Infracost API Token, risking unauthorized access to cloud cost estimation tools and financial data.", Description: "Detected an Infracost API Token, risking unauthorized access to cloud cost estimation tools and financial data.",
Regex: utils.GenerateUniqueTokenRegex(`ico-[a-zA-Z0-9]{32}`, false),
// Unique ID for the rule Entropy: 3,
RuleID: "infracost-api-token", Keywords: []string{"ico-"},
// Regex capture group for the actual secret
// Regex used for detecting secrets. See regex section below for more details
Regex: utils.GenerateUniqueTokenRegex(`ico-[a-zA-Z0-9]{32}`, true),
// Keywords used for string matching on fragments (think of this as a prefilter)
Keywords: []string{"ico-"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("ico", "ico-"+secrets.NewSecret("[A-Za-z0-9]{32}"))
utils.GenerateSampleSecret("ico", "ico-"+secrets.NewSecret("[A-Za-z0-9]{32}")), tps = append(tps,
` variable {
name = "INFRACOST_API_KEY"
secret_value = "ico-mlCr1Mn3SRcRiZMObUZOTHLcgtH2Lpgt"
is_secret = true
}`,
// TODO: New format with longer keys?
// ` headers = {
//'X-Api-Key': 'ico-EeDdSfctrmjD14f45f45te5gJ7l6lw4o6M36sXT62a6',
//'Content-Type': 'application/json',
//}`,
)
fps := []string{
// Low entropy
`ico-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX`,
// Invalid
`http://assets.r7.com/assets/media_box_tv_tres_colunas/video_box.ico-7a388b69018576d24b59331fd60aab0c.png`,
`https://explosivelab.notion.site/Pianificazione-Nerdz-Ng-pubblico-1bc826ecc0994dd8915be97fc3489cde?pvs=74`,
`http://ece252-2.uwaterloo.ca:2540/image?q=gAAAAABdHkoqb9ZaJ3q4dlzEvTgG9WYwKcD9Aw7OUXeFicO-5M5IdNDjHBpKw7KBK3nCVqtuga4yzUaFEpJn8BqA1LzZprIJBw==`,
} }
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, fps)
} }
+1 -3
View File
@@ -17,8 +17,6 @@ func Intercom() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("intercom", secrets.NewSecret(utils.AlphaNumericExtended("60")))
utils.GenerateSampleSecret("intercom", secrets.NewSecret(utils.AlphaNumericExtended("60"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+2 -1
View File
@@ -11,7 +11,8 @@ func Intra42ClientSecret() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Found a Intra42 client secret, which could lead to unauthorized access to the 42School API and sensitive data.", Description: "Found a Intra42 client secret, which could lead to unauthorized access to the 42School API and sensitive data.",
RuleID: "intra42-client-secret", RuleID: "intra42-client-secret",
Regex: utils.GenerateUniqueTokenRegex(`s-s4t2(?:ud|af)-[abcdef0123456789]{64}`, true), Regex: utils.GenerateUniqueTokenRegex(`s-s4t2(?:ud|af)-(?i)[abcdef0123456789]{64}`, false),
Entropy: 3,
Keywords: []string{ Keywords: []string{
"intra", "intra",
"s-s4t2ud-", "s-s4t2ud-",
+6 -7
View File
@@ -2,8 +2,8 @@ package rules
import ( import (
"fmt" "fmt"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -55,11 +55,10 @@ func JFrogIdentityToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("jfrog", secrets.NewSecret(utils.AlphaNumeric("64")))
utils.GenerateSampleSecret("jfrog", secrets.NewSecret(utils.AlphaNumeric("64"))), tps = append(tps, utils.GenerateSampleSecrets("artifactory", secrets.NewSecret(utils.AlphaNumeric("64")))...)
utils.GenerateSampleSecret("artifactory", secrets.NewSecret(utils.AlphaNumeric("64"))), tps = append(tps, utils.GenerateSampleSecrets("bintray", secrets.NewSecret(utils.AlphaNumeric("64")))...)
utils.GenerateSampleSecret("bintray", secrets.NewSecret(utils.AlphaNumeric("64"))), tps = append(tps, utils.GenerateSampleSecrets("xray", secrets.NewSecret(utils.AlphaNumeric("64")))...)
utils.GenerateSampleSecret("xray", secrets.NewSecret(utils.AlphaNumeric("64"))), tps = append(tps, fmt.Sprintf("\"artifactory\", \"%s\"", secrets.NewSecret(utils.AlphaNumeric("64"))))
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+9 -4
View File
@@ -3,9 +3,10 @@ package rules
import ( import (
b64 "encoding/base64" b64 "encoding/base64"
"fmt" "fmt"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -15,11 +16,14 @@ func JWT() *config.Rule {
Description: "Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.", Description: "Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.",
RuleID: "jwt", RuleID: "jwt",
Regex: utils.GenerateUniqueTokenRegex(`ey[a-zA-Z0-9]{17,}\.ey[a-zA-Z0-9\/\\_-]{17,}\.(?:[a-zA-Z0-9\/\\_-]{10,}={0,2})?`, false), Regex: utils.GenerateUniqueTokenRegex(`ey[a-zA-Z0-9]{17,}\.ey[a-zA-Z0-9\/\\_-]{17,}\.(?:[a-zA-Z0-9\/\\_-]{10,}={0,2})?`, false),
Entropy: 3,
Keywords: []string{"ey"}, Keywords: []string{"ey"},
} }
// validate // validate
tps := []string{`eyJhbGciOieeeiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwic3ViZSI6IjEyMzQ1Njc4OTAiLCJuYW1lZWEiOiJKb2huIERvZSIsInN1ZmV3YWZiIjoiMTIzNDU2Nzg5MCIsIm5hbWVmZWF3ZnciOiJKb2huIERvZSIsIm5hbWVhZmV3ZmEiOiJKb2huIERvZSIsInN1ZndhZndlYWIiOiIxMjM0NTY3ODkwIiwibmFtZWZ3YWYiOiJKb2huIERvZSIsInN1YmZ3YWYiOiIxMjM0NTY3ODkwIiwibmFtZndhZSI6IkpvaG4gRG9lIiwiaWZ3YWZhYXQiOjE1MTYyMzkwMjJ9.a_5icKBDo-8EjUlrfvz2k2k-FYaindQ0DEYNrlsnRG0==`, // gitleaks:allow tps := utils.GenerateSampleSecrets("jwt", secrets.NewSecret(`ey[a-zA-Z0-9]{17,}\.ey[a-zA-Z0-9\/\\_-]{17,}\.(?:[a-zA-Z0-9\/\\_-]{10,}={0,2})?`))
tps = append(tps,
`eyJhbGciOieeeiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwic3ViZSI6IjEyMzQ1Njc4OTAiLCJuYW1lZWEiOiJKb2huIERvZSIsInN1ZmV3YWZiIjoiMTIzNDU2Nzg5MCIsIm5hbWVmZWF3ZnciOiJKb2huIERvZSIsIm5hbWVhZmV3ZmEiOiJKb2huIERvZSIsInN1ZndhZndlYWIiOiIxMjM0NTY3ODkwIiwibmFtZWZ3YWYiOiJKb2huIERvZSIsInN1YmZ3YWYiOiIxMjM0NTY3ODkwIiwibmFtZndhZSI6IkpvaG4gRG9lIiwiaWZ3YWZhYXQiOjE1MTYyMzkwMjJ9.a_5icKBDo-8EjUlrfvz2k2k-FYaindQ0DEYNrlsnRG0==`, // gitleaks:allow
`JWT := eyJhbGciOieeeiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwic3ViZSI6IjEyMzQ1Njc4OTAiLCJuYW1lZWEiOiJKb2huIERvZSIsInN1ZmV3YWZiIjoiMTIzNDU2Nzg5MCIsIm5hbWVmZWF3ZnciOiJKb2huIERvZSIsIm5hbWVhZmV3ZmEiOiJKb2huIERvZSIsInN1ZndhZndlYWIiOiIxMjM0NTY3ODkwIiwibmFtZWZ3YWYiOiJKb2huIERvZSIsInN1YmZ3YWYiOiIxMjM0NTY3ODkwIiwibmFtZndhZSI6IkpvaG4gRG9lIiwiaWZ3YWZhYXQiOjE1MTYyMzkwMjJ9.a_5icKBDo-8EjUlrfvz2k2k-FYaindQ0DEYNrlsnRG0`, // gitleaks:allow `JWT := eyJhbGciOieeeiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwic3ViZSI6IjEyMzQ1Njc4OTAiLCJuYW1lZWEiOiJKb2huIERvZSIsInN1ZmV3YWZiIjoiMTIzNDU2Nzg5MCIsIm5hbWVmZWF3ZnciOiJKb2huIERvZSIsIm5hbWVhZmV3ZmEiOiJKb2huIERvZSIsInN1ZndhZndlYWIiOiIxMjM0NTY3ODkwIiwibmFtZWZ3YWYiOiJKb2huIERvZSIsInN1YmZ3YWYiOiIxMjM0NTY3ODkwIiwibmFtZndhZSI6IkpvaG4gRG9lIiwiaWZ3YWZhYXQiOjE1MTYyMzkwMjJ9.a_5icKBDo-8EjUlrfvz2k2k-FYaindQ0DEYNrlsnRG0`, // gitleaks:allow
`"access_token": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3NLZXkiOiJRMzFDVlMxUFNDSjRPVEsyWVZFTSIsImF0X2hhc2giOiI4amItZFE2OXRtZEVueUZaMUttNWhnIiwiYXVkIjoiZXhhbXBsZS1hcHAiLCJlbWFpbCI6ImFkbWluQGV4YW1wbGUuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImV4cCI6IjE1OTQ2MDAxODIiLCJpYXQiOjE1OTQ1ODkzODQsImlzcyI6Imh0dHA6Ly8xMjcuMC4wLjE6NTU1Ni9kZXgiLCJuYW1lIjoiYWRtaW4iLCJzdWIiOiJDaVF3T0dFNE5qZzBZaTFrWWpnNExUUmlOek10T1RCaE9TMHpZMlF4TmpZeFpqVTBOallTQld4dlkyRnMifQ.nrbzIJz99Om7TvJ04jnSTmhvlM7aR9hMM1Aqjp2ONJ1UKYCvegBLrTu6cYR968_OpmnAGJ8vkd7sIjUjtR4zbw"`, // gitleaks:allow `"access_token": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3NLZXkiOiJRMzFDVlMxUFNDSjRPVEsyWVZFTSIsImF0X2hhc2giOiI4amItZFE2OXRtZEVueUZaMUttNWhnIiwiYXVkIjoiZXhhbXBsZS1hcHAiLCJlbWFpbCI6ImFkbWluQGV4YW1wbGUuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImV4cCI6IjE1OTQ2MDAxODIiLCJpYXQiOjE1OTQ1ODkzODQsImlzcyI6Imh0dHA6Ly8xMjcuMC4wLjE6NTU1Ni9kZXgiLCJuYW1lIjoiYWRtaW4iLCJzdWIiOiJDaVF3T0dFNE5qZzBZaTFrWWpnNExUUmlOek10T1RCaE9TMHpZMlF4TmpZeFpqVTBOallTQld4dlkyRnMifQ.nrbzIJz99Om7TvJ04jnSTmhvlM7aR9hMM1Aqjp2ONJ1UKYCvegBLrTu6cYR968_OpmnAGJ8vkd7sIjUjtR4zbw"`, // gitleaks:allow
`https://dai2-playlistserver.aws.syncbak.com/cpl/20980038/dai2v5/1.0/7b2264657669636554797065223a387d/master.m3u8?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IkdyYXkyMDE2MDgyOSJ9.eyJtaWQiOiIyMDk4MDAzOCIsImNpZCI6MjE5MDMsInNpZCI6MTU4LCJtZDUiOiIwN2QxMmRjNjAwOTM2MGI0MmY3NjNkNTRiMWIwZjI1NCIsImlhdCI6MTY2MDkxMzU2MCwiZXhwIjoxNjkyNDQ5NTYwLCJpc3MiOiJTeW5jYmFrIChURykifQ.JrWVgwzIn_RcNuWhkzIjr1i4qjXU1v4n0KFrSzoTQvQ`, // gitleaks:allow ` `https://dai2-playlistserver.aws.syncbak.com/cpl/20980038/dai2v5/1.0/7b2264657669636554797065223a387d/master.m3u8?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IkdyYXkyMDE2MDgyOSJ9.eyJtaWQiOiIyMDk4MDAzOCIsImNpZCI6MjE5MDMsInNpZCI6MTU4LCJtZDUiOiIwN2QxMmRjNjAwOTM2MGI0MmY3NjNkNTRiMWIwZjI1NCIsImlhdCI6MTY2MDkxMzU2MCwiZXhwIjoxNjkyNDQ5NTYwLCJpc3MiOiJTeW5jYmFrIChURykifQ.JrWVgwzIn_RcNuWhkzIjr1i4qjXU1v4n0KFrSzoTQvQ`, // gitleaks:allow `
@@ -60,7 +64,7 @@ func JWT() *config.Rule {
// `eyJhbGciOiJFQ0RILUVTIiwiZW5jIjoiQTI1NkdDTSIsImVwayI6eyJrdHkiOiJFQyIsImNydiI6IlAtMzg0Iiwia2V5X29wcyI6W10sImV4dCI6dHJ1ZSwieCI6IllUcEY3bGtTc3JvZVVUVFdCb21LNzBTN0FhVTJyc0ptMURpZ1ZzbjRMY2F5eUxFNFBabldkYmFVcE9jQVV5a1ciLCJ5IjoiLU5pS3loUktjSk52Nm02Z0ZJUWc4cy1Xd1VXUW9uT3A5dkQ4cHpoa2tUU3U2RzFlU2FUTVlhZGltQ2Q4V0ExMSJ9LCJhcHUiOiIiLCJhcHYiOiIifQ`, // `eyJhbGciOiJFQ0RILUVTIiwiZW5jIjoiQTI1NkdDTSIsImVwayI6eyJrdHkiOiJFQyIsImNydiI6IlAtMzg0Iiwia2V5X29wcyI6W10sImV4dCI6dHJ1ZSwieCI6IllUcEY3bGtTc3JvZVVUVFdCb21LNzBTN0FhVTJyc0ptMURpZ1ZzbjRMY2F5eUxFNFBabldkYmFVcE9jQVV5a1ciLCJ5IjoiLU5pS3loUktjSk52Nm02Z0ZJUWc4cy1Xd1VXUW9uT3A5dkQ4cHpoa2tUU3U2RzFlU2FUTVlhZGltQ2Q4V0ExMSJ9LCJhcHUiOiIiLCJhcHYiOiIifQ`,
`String tokenWithNoneAlg = "eyJhbGciOiJub25lIn0.eyJzdWIiOiJ0ZXN0LXVzZXIifQ.";`, // gitleaks:allow `String tokenWithNoneAlg = "eyJhbGciOiJub25lIn0.eyJzdWIiOiJ0ZXN0LXVzZXIifQ.";`, // gitleaks:allow
`# Req: Invoke-RestMethod -Uri 'http://localhost:8085/users' -Headers @{ 'X-API-KEY' = 'eyJhbGciOiJub25lIn0.eyJ1c2VybmFtZSI6Im1vcnR5Iiwic3ViIjoiMTIzIn0.' }`, // gitleaks:allow `# Req: Invoke-RestMethod -Uri 'http://localhost:8085/users' -Headers @{ 'X-API-KEY' = 'eyJhbGciOiJub25lIn0.eyJ1c2VybmFtZSI6Im1vcnR5Iiwic3ViIjoiMTIzIn0.' }`, // gitleaks:allow
} )
fps := []string{} fps := []string{}
return utils.Validate(r, tps, fps) return utils.Validate(r, tps, fps)
} }
@@ -72,6 +76,7 @@ func JWTBase64() *config.Rule {
Description: "Detected a Base64-encoded JSON Web Token, posing a risk of exposing encoded authentication and data exchange information.", Description: "Detected a Base64-encoded JSON Web Token, posing a risk of exposing encoded authentication and data exchange information.",
Regex: regexp.MustCompile( Regex: regexp.MustCompile(
`\bZXlK(?:(?P<alg>aGJHY2lPaU)|(?P<apu>aGNIVWlPaU)|(?P<apv>aGNIWWlPaU)|(?P<aud>aGRXUWlPaU)|(?P<b64>aU5qUWlP)|(?P<crit>amNtbDBJanBi)|(?P<cty>amRIa2lPaU)|(?P<epk>bGNHc2lPbn)|(?P<enc>bGJtTWlPaU)|(?P<jku>cWEzVWlPaU)|(?P<jwk>cWQyc2lPb)|(?P<iss>cGMzTWlPaU)|(?P<iv>cGRpSTZJ)|(?P<kid>cmFXUWlP)|(?P<key_ops>clpYbGZiM0J6SWpwY)|(?P<kty>cmRIa2lPaUp)|(?P<nonce>dWIyNWpaU0k2)|(?P<p2c>d01tTWlP)|(?P<p2s>d01uTWlPaU)|(?P<ppt>d2NIUWlPaU)|(?P<sub>emRXSWlPaU)|(?P<svt>emRuUWlP)|(?P<tag>MFlXY2lPaU)|(?P<typ>MGVYQWlPaUp)|(?P<url>MWNtd2l)|(?P<use>MWMyVWlPaUp)|(?P<ver>MlpYSWlPaU)|(?P<version>MlpYSnphVzl1SWpv)|(?P<x>NElqb2)|(?P<x5c>NE5XTWlP)|(?P<x5t>NE5YUWlPaU)|(?P<x5ts256>NE5YUWpVekkxTmlJNkl)|(?P<x5u>NE5YVWlPaU)|(?P<zip>NmFYQWlPaU))[a-zA-Z0-9\/\\_+\-\r\n]{40,}={0,2}`), `\bZXlK(?:(?P<alg>aGJHY2lPaU)|(?P<apu>aGNIVWlPaU)|(?P<apv>aGNIWWlPaU)|(?P<aud>aGRXUWlPaU)|(?P<b64>aU5qUWlP)|(?P<crit>amNtbDBJanBi)|(?P<cty>amRIa2lPaU)|(?P<epk>bGNHc2lPbn)|(?P<enc>bGJtTWlPaU)|(?P<jku>cWEzVWlPaU)|(?P<jwk>cWQyc2lPb)|(?P<iss>cGMzTWlPaU)|(?P<iv>cGRpSTZJ)|(?P<kid>cmFXUWlP)|(?P<key_ops>clpYbGZiM0J6SWpwY)|(?P<kty>cmRIa2lPaUp)|(?P<nonce>dWIyNWpaU0k2)|(?P<p2c>d01tTWlP)|(?P<p2s>d01uTWlPaU)|(?P<ppt>d2NIUWlPaU)|(?P<sub>emRXSWlPaU)|(?P<svt>emRuUWlP)|(?P<tag>MFlXY2lPaU)|(?P<typ>MGVYQWlPaUp)|(?P<url>MWNtd2l)|(?P<use>MWMyVWlPaUp)|(?P<ver>MlpYSWlPaU)|(?P<version>MlpYSnphVzl1SWpv)|(?P<x>NElqb2)|(?P<x5c>NE5XTWlP)|(?P<x5t>NE5YUWlPaU)|(?P<x5ts256>NE5YUWpVekkxTmlJNkl)|(?P<x5u>NE5YVWlPaU)|(?P<zip>NmFYQWlPaU))[a-zA-Z0-9\/\\_+\-\r\n]{40,}={0,2}`),
Entropy: 2,
Keywords: []string{"zxlk"}, Keywords: []string{"zxlk"},
} }
+1 -4
View File
@@ -20,9 +20,6 @@ func KrakenAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("kraken", secrets.NewSecret(utils.AlphaNumericExtendedLong("80,90")))
utils.GenerateSampleSecret("kraken",
secrets.NewSecret(utils.AlphaNumericExtendedLong("80,90"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+63 -11
View File
@@ -2,22 +2,24 @@ package rules
import ( import (
"fmt" "fmt"
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
) )
// KubernetesSecret validates if we detected a kubernetes secret which contains data! // KubernetesSecret validates if we detected a kubernetes secret which contains data!
func KubernetesSecret() *config.Rule { func KubernetesSecret() *config.Rule {
// Only match basic variations of `kind: secret`, we don't want things like `kind: ExternalSecret`. // Only match basic variations of `kind: secret`, we don't want things like `kind: ExternalSecret`.
//language=regexp //language=regexp
kindPat := `\bkind:[ \t]*["']?secret["']?` kindPat := `\bkind:[ \t]*["']?\bsecret\b["']?`
// Only matches values (`key: value`) under `data:` that are: // Only matches values (`key: value`) under `data:` that are:
// - valid base64 characters // - valid base64 characters
// - longer than 10 characters (no "YmFyCg==") // - longer than 10 characters (no "YmFyCg==")
//language=regexp //language=regexp
dataPat := `\bdata:(?:.|\s){0,100}?\s+([\w.-]+:(?:[ \t]*(?:\||>[-+]?)\s+)?[ \t]*(?:["']?[a-z0-9]{10,}={0,3}["']?|\{\{[ \t\w"|$:=,.-]+}}|""|''))` dataPat := `\bdata:(?:.|\s){0,100}?\s+([\w.-]+:(?:[ \t]*(?:\||>[-+]?)\s+)?[ \t]*(?:["']?[a-z0-9+/]{10,}={0,3}["']?|\{\{[ \t\w"|$:=,.-]+}}|""|''))`
// define rule // define rule
r := config.Rule{ r := config.Rule{
@@ -31,19 +33,33 @@ func KubernetesSecret() *config.Rule {
}, },
// Kubernetes secrets are usually yaml files. // Kubernetes secrets are usually yaml files.
Path: regexp.MustCompile(`(?i)\.ya?ml$`), Path: regexp.MustCompile(`(?i)\.ya?ml$`),
Allowlist: config.Allowlist{ Allowlists: []config.Allowlist{
Regexes: []*regexp.Regexp{ {
// Ignore empty or placeholder values. Regexes: []*regexp.Regexp{
// variable: {{ .Values.Example }} (https://helm.sh/docs/chart_template_guide/variables/) // Ignore empty or placeholder values.
// variable: "" // variable: {{ .Values.Example }} (https://helm.sh/docs/chart_template_guide/variables/)
// variable: '' // variable: ""
regexp.MustCompile(`[\w.-]+:(?:[ \t]*(?:\||>[-+]?)\s+)?[ \t]*(?:\{\{[ \t\w"|$:=,.-]+}}|""|'')`), // variable: ''
regexp.MustCompile(`[\w.-]+:(?:[ \t]*(?:\||>[-+]?)\s+)?[ \t]*(?:\{\{[ \t\w"|$:=,.-]+}}|""|'')`),
},
},
{
// Avoid overreach between directives.
RegexTarget: "match",
Regexes: []*regexp.Regexp{
regexp.MustCompile(`(kind:(.|\s)+\n---\n(.|\s)+\bdata:|data:(.|\s)+\n---\n(.|\s)+\bkind:)`),
},
}, },
}, },
} }
// validate // validate
tps := map[string]string{ tps := map[string]string{
"base64-characters.yaml": `
apiVersion: v1
kind: Secret
data:
password: AAAAAAAAAAC7hjsA+H3owFygUv4w5B67lcSx14zff9FCPADiNbSwYWgE+O7Dhiy5tkRecs21ljjofvebe6xsYlA4cVmght0=`,
"comment.yaml": ` "comment.yaml": `
apiVersion: v1 apiVersion: v1
kind: Secret kind: Secret
@@ -232,6 +248,42 @@ metadata:
name: kubernetes-dashboard-key-holder name: kubernetes-dashboard-key-holder
namespace: kubernetes-dashboard namespace: kubernetes-dashboard
type: Opaque type: Opaque
`,
"overly-permissive3.yaml": ` kind: Secret
target:
name: mysecret
creationPolicy: Owner
---
kind: ConfigMap
data:
conversionStrategy: Default
decodingStrategy: None
key: secret/mysecret
property: foo
secretKey: foo`,
// https://github.com/gitleaks/gitleaks/issues/1644
"wrong-kind.yaml": `apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: example
namespace: example-ns
spec:
refreshInterval: 15s
secretStoreRef:
name: example
kind: SecretStore
target:
name: mysecret
creationPolicy: Owner
data:
- remoteRef:
conversionStrategy: Default
decodingStrategy: None
key: secret/mysecret
property: foo
secretKey: foo
`, `,
"sopssecret.yaml": `apiVersion: isindir.github.com/v1alpha3 "sopssecret.yaml": `apiVersion: isindir.github.com/v1alpha3
kind: SopsSecret kind: SopsSecret
+2 -6
View File
@@ -19,9 +19,7 @@ func KucoinAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("kucoin", secrets.NewSecret(utils.Hex("24")))
utils.GenerateSampleSecret("kucoin", secrets.NewSecret(utils.Hex("24"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -38,8 +36,6 @@ func KucoinSecretKey() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("kucoin", secrets.NewSecret(utils.Hex8_4_4_4_12()))
utils.GenerateSampleSecret("kucoin", secrets.NewSecret(utils.Hex8_4_4_4_12())),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+1 -3
View File
@@ -19,8 +19,6 @@ func LaunchDarklyAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("launchdarkly", secrets.NewSecret(utils.AlphaNumericExtended("40")))
utils.GenerateSampleSecret("launchdarkly", secrets.NewSecret(utils.AlphaNumericExtended("40"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+9 -10
View File
@@ -1,41 +1,40 @@
package rules package rules
import ( import (
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
) )
func LinearAPIToken() *config.Rule { func LinearAPIToken() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Detected a Linear API Token, posing a risk to project management tools and sensitive task data.",
RuleID: "linear-api-key", RuleID: "linear-api-key",
Description: "Detected a Linear API Token, posing a risk to project management tools and sensitive task data.",
Regex: regexp.MustCompile(`lin_api_(?i)[a-z0-9]{40}`), Regex: regexp.MustCompile(`lin_api_(?i)[a-z0-9]{40}`),
Entropy: 2,
Keywords: []string{"lin_api_"}, Keywords: []string{"lin_api_"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("linear", "lin_api_"+secrets.NewSecret(utils.AlphaNumeric("40")))
utils.GenerateSampleSecret("linear", "lin_api_"+secrets.NewSecret(utils.AlphaNumeric("40"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func LinearClientSecret() *config.Rule { func LinearClientSecret() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Identified a Linear Client Secret, which may compromise secure integrations and sensitive project management data.",
RuleID: "linear-client-secret", RuleID: "linear-client-secret",
Description: "Identified a Linear Client Secret, which may compromise secure integrations and sensitive project management data.",
Regex: utils.GenerateSemiGenericRegex([]string{"linear"}, utils.Hex("32"), true), Regex: utils.GenerateSemiGenericRegex([]string{"linear"}, utils.Hex("32"), true),
Entropy: 2,
Keywords: []string{"linear"}, Keywords: []string{"linear"},
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("linear", secrets.NewSecret(utils.Hex("32")))
utils.GenerateSampleSecret("linear", secrets.NewSecret(utils.Hex("32"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+23 -29
View File
@@ -6,48 +6,42 @@ import (
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
func LinkedinClientID() *config.Rule {
// define rule
r := config.Rule{
RuleID: "linkedin-client-id",
Description: "Found a LinkedIn Client ID, risking unauthorized access to LinkedIn integrations and professional data exposure.",
Regex: utils.GenerateSemiGenericRegex([]string{"linked[_-]?in"}, utils.AlphaNumeric("14"), true),
Entropy: 2,
Keywords: []string{
"linkedin",
"linked_in",
"linked-in",
},
}
// validate
tps := utils.GenerateSampleSecrets("linkedin", secrets.NewSecret(utils.AlphaNumeric("14")))
return utils.Validate(r, tps, nil)
}
func LinkedinClientSecret() *config.Rule { func LinkedinClientSecret() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
RuleID: "linkedin-client-secret", RuleID: "linkedin-client-secret",
Description: "Discovered a LinkedIn Client secret, potentially compromising LinkedIn application integrations and user data.", Description: "Discovered a LinkedIn Client secret, potentially compromising LinkedIn application integrations and user data.",
Regex: utils.GenerateSemiGenericRegex([]string{ Regex: utils.GenerateSemiGenericRegex([]string{
"linkedin", "linked[_-]?in",
"linked-in",
}, utils.AlphaNumeric("16"), true), }, utils.AlphaNumeric("16"), true),
Entropy: 2,
Keywords: []string{ Keywords: []string{
"linkedin", "linkedin",
"linked_in",
"linked-in", "linked-in",
}, },
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("linkedin", secrets.NewSecret(utils.AlphaNumeric("16")))
utils.GenerateSampleSecret("linkedin", secrets.NewSecret(utils.AlphaNumeric("16"))),
}
return utils.Validate(r, tps, nil)
}
func LinkedinClientID() *config.Rule {
// define rule
r := config.Rule{
RuleID: "linkedin-client-id",
Description: "Found a LinkedIn Client ID, risking unauthorized access to LinkedIn integrations and professional data exposure.",
Regex: utils.GenerateSemiGenericRegex([]string{
"linkedin",
"linked-in",
}, utils.AlphaNumeric("14"), true),
Keywords: []string{
"linkedin",
"linked-in",
},
}
// validate
tps := []string{
utils.GenerateSampleSecret("linkedin", secrets.NewSecret(utils.AlphaNumeric("14"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+2 -6
View File
@@ -21,9 +21,7 @@ func LobPubAPIToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("lob", "test_pub_"+secrets.NewSecret(utils.Hex("31")))
utils.GenerateSampleSecret("lob", "test_pub_"+secrets.NewSecret(utils.Hex("31"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -40,8 +38,6 @@ func LobAPIToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("lob", "test_"+secrets.NewSecret(utils.Hex("35")))
utils.GenerateSampleSecret("lob", "test_"+secrets.NewSecret(utils.Hex("35"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+3 -3
View File
@@ -19,11 +19,11 @@ func MailChimp() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("mailchimp", secrets.NewSecret(utils.Hex("32"))+"-us20")
utils.GenerateSampleSecret("mailchimp", secrets.NewSecret(utils.Hex("32"))+"-us20"), tps = append(tps,
`mailchimp_api_key: cefa780880ba5f5696192a34f6292c35-us18`, // gitleaks:allow `mailchimp_api_key: cefa780880ba5f5696192a34f6292c35-us18`, // gitleaks:allow
`MAILCHIMPE_KEY = "b5b9f8e50c640da28993e8b6a48e3e53-us18"`, // gitleaks:allow `MAILCHIMPE_KEY = "b5b9f8e50c640da28993e8b6a48e3e53-us18"`, // gitleaks:allow
} )
fps := []string{ fps := []string{
// False Negative // False Negative
`MailchimpSDK.initialize(token: 3012a5754bbd716926f99c028f7ea428-us18)`, // gitleaks:allow `MailchimpSDK.initialize(token: 3012a5754bbd716926f99c028f7ea428-us18)`, // gitleaks:allow
+3 -9
View File
@@ -19,9 +19,7 @@ func MailGunPrivateAPIToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("mailgun", "key-"+secrets.NewSecret(utils.Hex("32")))
utils.GenerateSampleSecret("mailgun", "key-"+secrets.NewSecret(utils.Hex("32"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -38,9 +36,7 @@ func MailGunPubAPIToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("mailgun", "pubkey-"+secrets.NewSecret(utils.Hex("32")))
utils.GenerateSampleSecret("mailgun", "pubkey-"+secrets.NewSecret(utils.Hex("32"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -57,8 +53,6 @@ func MailGunSigningKey() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("mailgun", secrets.NewSecret(utils.Hex("32"))+"-00001111-22223333")
utils.GenerateSampleSecret("mailgun", secrets.NewSecret(utils.Hex("32"))+"-00001111-22223333"),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+1 -3
View File
@@ -17,8 +17,6 @@ func MapBox() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("mapbox", "pk."+secrets.NewSecret(utils.AlphaNumeric("60"))+"."+secrets.NewSecret(utils.AlphaNumeric("22")))
utils.GenerateSampleSecret("mapbox", "pk."+secrets.NewSecret(utils.AlphaNumeric("60"))+"."+secrets.NewSecret(utils.AlphaNumeric("22"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+1 -3
View File
@@ -19,8 +19,6 @@ func MattermostAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("mattermost", secrets.NewSecret(utils.AlphaNumeric("26")))
utils.GenerateSampleSecret("mattermost", secrets.NewSecret(utils.AlphaNumeric("26"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+8 -17
View File
@@ -11,11 +11,7 @@ func MessageBirdAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Found a MessageBird API token, risking unauthorized access to communication platforms and message data.", Description: "Found a MessageBird API token, risking unauthorized access to communication platforms and message data.",
RuleID: "messagebird-api-token", RuleID: "messagebird-api-token",
Regex: utils.GenerateSemiGenericRegex([]string{ Regex: utils.GenerateSemiGenericRegex([]string{"message[_-]?bird"}, utils.AlphaNumeric("25"), true),
"messagebird",
"message-bird",
"message_bird",
}, utils.AlphaNumeric("25"), true),
Keywords: []string{ Keywords: []string{
"messagebird", "messagebird",
@@ -25,11 +21,9 @@ func MessageBirdAPIToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("messagebird", secrets.NewSecret(utils.AlphaNumeric("25")))
utils.GenerateSampleSecret("messagebird", secrets.NewSecret(utils.AlphaNumeric("25"))), tps = append(tps, utils.GenerateSampleSecrets("message-bird", secrets.NewSecret(utils.AlphaNumeric("25")))...)
utils.GenerateSampleSecret("message-bird", secrets.NewSecret(utils.AlphaNumeric("25"))), tps = append(tps, utils.GenerateSampleSecrets("message_bird", secrets.NewSecret(utils.AlphaNumeric("25")))...)
utils.GenerateSampleSecret("message_bird", secrets.NewSecret(utils.AlphaNumeric("25"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -38,11 +32,7 @@ func MessageBirdClientID() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Discovered a MessageBird client ID, potentially compromising API integrations and sensitive communication data.", Description: "Discovered a MessageBird client ID, potentially compromising API integrations and sensitive communication data.",
RuleID: "messagebird-client-id", RuleID: "messagebird-client-id",
Regex: utils.GenerateSemiGenericRegex([]string{ Regex: utils.GenerateSemiGenericRegex([]string{"message[_-]?bird"}, utils.Hex8_4_4_4_12(), true),
"messagebird",
"message-bird",
"message_bird",
}, utils.Hex8_4_4_4_12(), true),
Keywords: []string{ Keywords: []string{
"messagebird", "messagebird",
@@ -52,8 +42,9 @@ func MessageBirdClientID() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("MessageBird", "12345678-ABCD-ABCD-ABCD-1234567890AB") // gitleaks:allow
tps = append(tps,
`const MessageBirdClientID = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow `const MessageBirdClientID = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow
} )
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+1 -3
View File
@@ -20,8 +20,6 @@ func NetlifyAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("netlify", secrets.NewSecret(utils.AlphaNumericExtended("40,46")))
utils.GenerateSampleSecret("netlify", secrets.NewSecret(utils.AlphaNumericExtended("40,46"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -12
View File
@@ -23,9 +23,7 @@ func NewRelicUserID() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("new-relic", "NRAK-"+secrets.NewSecret(utils.AlphaNumeric("27")))
utils.GenerateSampleSecret("new-relic", "NRAK-"+secrets.NewSecret(utils.AlphaNumeric("27"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -48,9 +46,7 @@ func NewRelicUserKey() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("new-relic", secrets.NewSecret(utils.AlphaNumeric("64")))
utils.GenerateSampleSecret("new-relic", secrets.NewSecret(utils.AlphaNumeric("64"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -71,9 +67,7 @@ func NewRelicBrowserAPIKey() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("new-relic", "NRJS-"+secrets.NewSecret(utils.Hex("19")))
utils.GenerateSampleSecret("new-relic", "NRJS-"+secrets.NewSecret(utils.Hex("19"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -94,8 +88,6 @@ func NewRelicInsertKey() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("new-relic", "NRII-"+secrets.NewSecret(utils.Hex("32")))
utils.GenerateSampleSecret("new-relic", "NRII-"+secrets.NewSecret(utils.Hex("32"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+2 -4
View File
@@ -12,15 +12,13 @@ func NPM() *config.Rule {
RuleID: "npm-access-token", RuleID: "npm-access-token",
Description: "Uncovered an npm access token, potentially compromising package management and code repository access.", Description: "Uncovered an npm access token, potentially compromising package management and code repository access.",
Regex: utils.GenerateUniqueTokenRegex(`npm_[a-z0-9]{36}`, true), Regex: utils.GenerateUniqueTokenRegex(`npm_[a-z0-9]{36}`, true),
Entropy: 2,
Keywords: []string{ Keywords: []string{
"npm_", "npm_",
}, },
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("npmAccessToken", "npm_"+secrets.NewSecret(utils.AlphaNumeric("36")))
utils.GenerateSampleSecret("npmAccessToken", "npm_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+12 -10
View File
@@ -1,11 +1,11 @@
package rules package rules
import ( import (
"regexp" regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
) )
func NugetConfigPassword() *config.Rule { func NugetConfigPassword() *config.Rule {
@@ -16,13 +16,15 @@ func NugetConfigPassword() *config.Rule {
Path: regexp.MustCompile(`(?i)nuget\.config$`), Path: regexp.MustCompile(`(?i)nuget\.config$`),
Keywords: []string{"<add key="}, Keywords: []string{"<add key="},
Entropy: 1, Entropy: 1,
Allowlist: config.Allowlist{ Allowlists: []config.Allowlist{
Regexes: []*regexp.Regexp{ {
// samples from https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file Regexes: []*regexp.Regexp{
regexp.MustCompile(`33f!!lloppa`), // samples from https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file
regexp.MustCompile(`hal\+9ooo_da!sY`), regexp.MustCompile(`33f!!lloppa`),
// exclude environment variables regexp.MustCompile(`hal\+9ooo_da!sY`),
regexp.MustCompile(`^\%\S.*\%$`), // exclude environment variables
regexp.MustCompile(`^\%\S.*\%$`),
},
}, },
}, },
} }
+1 -3
View File
@@ -23,8 +23,6 @@ func NytimesAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("nytimes", secrets.NewSecret(utils.AlphaNumeric("32")))
utils.GenerateSampleSecret("nytimes", secrets.NewSecret(utils.AlphaNumeric("32"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -0,0 +1,32 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func OctopusDeployApiKey() *config.Rule {
// define rule
r := config.Rule{
RuleID: "octopus-deploy-api-key",
Description: "Discovered a potential Octopus Deploy API key, risking application deployments and operational security.",
Regex: utils.GenerateUniqueTokenRegex(`API-[A-Z0-9]{26}`, false),
Entropy: 3,
Keywords: []string{"api-"},
}
// validate
tps := []string{
utils.GenerateSampleSecret("octopus", secrets.NewSecret(`API-[A-Z0-9]{26}`)),
`set apikey="API-ZNRMR7SL6L3ATMOIK7GKJDKLPY"`, // gitleaks:allow
}
fps := []string{
// Invalid start
`msgstr "GSSAPI-VIRHEKAPSELOINTIMERKKIJONO."`,
`https://sonarcloud.io/api/project_badges/measure?project=Garden-Coin_API-CalculadoraDeInvestimentos&metric=alert_status`,
`https://fog-ringer-f42.notion.site/API-BD80F56CDC1441E6BF6011AB6D852875`, // Invalid end
`<iframe src="./archive/gifs/api-c99e353f761d318322c853c03e.gif"> </iframe>`, // Wrong case
}
return utils.Validate(r, tps, fps)
}
+13 -6
View File
@@ -11,17 +11,24 @@ func OktaAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "okta-access-token", RuleID: "okta-access-token",
Description: "Identified an Okta Access Token, which may compromise identity management services and user authentication data.", Description: "Identified an Okta Access Token, which may compromise identity management services and user authentication data.",
Regex: utils.GenerateSemiGenericRegex([]string{"okta"}, Regex: utils.GenerateSemiGenericRegex([]string{`(?-i:[Oo]kta|OKTA)`}, `00[\w=\-]{40}`, false),
utils.AlphaNumericExtended("42"), true), Entropy: 4,
Keywords: []string{ Keywords: []string{
"okta", "okta",
}, },
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("okta", secrets.NewSecret(`00[\w=\-]{40}`))
utils.GenerateSampleSecret("okta", secrets.NewSecret(utils.AlphaNumeric("42"))), tps = append(tps,
`"oktaApiToken": "00ebObu4zSNkyc6dimLvUwq4KpTEop-PCEnnfSTpD3",`, // gitleaks:allow
` var OktaApiToken = "00fWkOjwwL9xiFd-Vfgm_ePATIRxVj852Iblbb1DS_";`, // gitleaks:allow
)
fps := []string{
`oktaKey = 00000000000000000000000000000000000TUVWXYZ`, // low entropy
`rookTable = 0023452Lllk2KqjLBvaxANWEgTd7bqjsxjo8aZj0wd`, // wrong case
} }
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, fps)
} }
// TODO: Okta client secret?
+3 -5
View File
@@ -11,16 +11,14 @@ func OpenAI() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "openai-api-key", RuleID: "openai-api-key",
Description: "Found an OpenAI API Key, posing a risk of unauthorized access to AI services and data manipulation.", Description: "Found an OpenAI API Key, posing a risk of unauthorized access to AI services and data manipulation.",
Regex: utils.GenerateUniqueTokenRegex(`sk-[a-zA-Z0-9]{20}T3BlbkFJ[a-zA-Z0-9]{20}`, true), Regex: utils.GenerateUniqueTokenRegex(`sk-[a-zA-Z0-9]{20}T3BlbkFJ[a-zA-Z0-9]{20}`, false),
Entropy: 3,
Keywords: []string{ Keywords: []string{
"T3BlbkFJ", "T3BlbkFJ",
}, },
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("openaiApiKey", "sk-"+secrets.NewSecret(utils.AlphaNumeric("20"))+"T3BlbkFJ"+secrets.NewSecret(utils.AlphaNumeric("20")))
utils.GenerateSampleSecret("openaiApiKey", "sk-"+secrets.NewSecret(utils.AlphaNumeric("20"))+"T3BlbkFJ"+secrets.NewSecret(utils.AlphaNumeric("20"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+9 -8
View File
@@ -1,11 +1,12 @@
package rules package rules
import ( import (
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
) )
// OpenShift 4 user tokens are prefixed with `sha256~`. // OpenShift 4 user tokens are prefixed with `sha256~`.
@@ -15,20 +16,20 @@ func OpenshiftUserToken() *config.Rule {
RuleID: "openshift-user-token", RuleID: "openshift-user-token",
Description: "Found an OpenShift user token, potentially compromising an OpenShift/Kubernetes cluster.", Description: "Found an OpenShift user token, potentially compromising an OpenShift/Kubernetes cluster.",
// TODO: Do tokens vary in length or are they always 43? // TODO: Do tokens vary in length or are they always 43?
Regex: regexp.MustCompile(`\b(sha256~[\w-]{43})(?:[^\w-]|\z)`), Regex: regexp.MustCompile(`\b(sha256~[\w-]{43})(?:[^\w-]|\z)`),
Entropy: 3.5, Entropy: 3.5,
SecretGroup: 0,
Keywords: []string{ Keywords: []string{
"sha256~", "sha256~",
}, },
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("oc", secrets.NewSecret("sha256~[\\w-]{43}"))
tps = append(tps,
`Authorization: Bearer sha256~kV46hPnEYhCWFnB85r5NrprAxggzgb6GOeLbgcKNsH0`, // https://github.com/openshift/console/blob/edae2305e01c2e0e8c33727af720ef960088eee3/dynamic-demo-plugin/README.md?plain=1#L114 `Authorization: Bearer sha256~kV46hPnEYhCWFnB85r5NrprAxggzgb6GOeLbgcKNsH0`, // https://github.com/openshift/console/blob/edae2305e01c2e0e8c33727af720ef960088eee3/dynamic-demo-plugin/README.md?plain=1#L114
`oc login --token=sha256~ZBMKw9VAayhdnyANaHvjJeXDiGwA7Fsr5gtLKj3-eh- `, // https://github.com/IBM/tekton-tutorial-openshift/blob/2a97d22ba282accad50821bca069210ea89de706/docs/lab1/0_setup.md?plain=1#L85 `oc login --token=sha256~ZBMKw9VAayhdnyANaHvjJeXDiGwA7Fsr5gtLKj3-eh- `, // https://github.com/IBM/tekton-tutorial-openshift/blob/2a97d22ba282accad50821bca069210ea89de706/docs/lab1/0_setup.md?plain=1#L85
"sha256~" + secrets.NewSecret(`[\w-]{43}`), "sha256~"+secrets.NewSecret(`[\w-]{43}`),
} )
fps := []string{ fps := []string{
`--set kraken.kubeconfig.token.token="sha256~XXXXXXXXXX_PUT_YOUR_TOKEN_HERE_XXXXXXXXXXXX" \`, // https://github.com/krkn-chaos/krkn/blob/f3933f0e6239824eb9b5c46ff0e5d503b8465d6a/docs/index.md?plain=1#L307 `--set kraken.kubeconfig.token.token="sha256~XXXXXXXXXX_PUT_YOUR_TOKEN_HERE_XXXXXXXXXXXX" \`, // https://github.com/krkn-chaos/krkn/blob/f3933f0e6239824eb9b5c46ff0e5d503b8465d6a/docs/index.md?plain=1#L307
`oc login --token=sha256~_xxxxxx_xxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxx-X \ `oc login --token=sha256~_xxxxxx_xxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxx-X \
+4 -10
View File
@@ -2,8 +2,8 @@ package rules
import ( import (
"fmt" "fmt"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -22,9 +22,7 @@ func PlaidAccessID() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("plaid", secrets.NewSecret(`[a-zA-Z0-9]{24}`))
utils.GenerateSampleSecret("plaid", secrets.NewSecret(utils.AlphaNumeric("24"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -42,9 +40,7 @@ func PlaidSecretKey() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("plaid", secrets.NewSecret(utils.AlphaNumeric("30")))
utils.GenerateSampleSecret("plaid", secrets.NewSecret(utils.AlphaNumeric("30"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -62,8 +58,6 @@ func PlaidAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("plaid", secrets.NewSecret(fmt.Sprintf("access-(?:sandbox|development|production)-%s", utils.Hex8_4_4_4_12())))
utils.GenerateSampleSecret("plaid", secrets.NewSecret(fmt.Sprintf("access-(?:sandbox|development|production)-%s", utils.Hex8_4_4_4_12()))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+15 -21
View File
@@ -11,19 +11,17 @@ func PlanetScalePassword() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "planetscale-password", RuleID: "planetscale-password",
Description: "Discovered a PlanetScale password, which could lead to unauthorized database operations and data breaches.", Description: "Discovered a PlanetScale password, which could lead to unauthorized database operations and data breaches.",
Regex: utils.GenerateUniqueTokenRegex(`pscale_pw_(?i)[a-z0-9=\-_\.]{32,64}`, true), Regex: utils.GenerateUniqueTokenRegex(`pscale_pw_(?i)[\w=\.-]{32,64}`, true),
Entropy: 3,
Keywords: []string{ Keywords: []string{
"pscale_pw_", "pscale_pw_",
}, },
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("planetScale", "pscale_pw_"+secrets.NewSecret(utils.AlphaNumericExtended("32")))
utils.GenerateSampleSecret("planetScalePassword", "pscale_pw_"+secrets.NewSecret(utils.AlphaNumericExtended("32"))), tps = append(tps, utils.GenerateSampleSecrets("planetScale", "pscale_pw_"+secrets.NewSecret(utils.AlphaNumericExtended("43")))...)
utils.GenerateSampleSecret("planetScalePassword", "pscale_pw_"+secrets.NewSecret(utils.AlphaNumericExtended("43"))), tps = append(tps, utils.GenerateSampleSecrets("planetScale", "pscale_pw_"+secrets.NewSecret(utils.AlphaNumericExtended("64")))...)
utils.GenerateSampleSecret("planetScalePassword", "pscale_pw_"+secrets.NewSecret(utils.AlphaNumericExtended("64"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -32,19 +30,17 @@ func PlanetScaleAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "planetscale-api-token", RuleID: "planetscale-api-token",
Description: "Identified a PlanetScale API token, potentially compromising database management and operations.", Description: "Identified a PlanetScale API token, potentially compromising database management and operations.",
Regex: utils.GenerateUniqueTokenRegex(`pscale_tkn_(?i)[a-z0-9=\-_\.]{32,64}`, true), Regex: utils.GenerateUniqueTokenRegex(`pscale_tkn_(?i)[\w=\.-]{32,64}`, false),
Entropy: 3,
Keywords: []string{ Keywords: []string{
"pscale_tkn_", "pscale_tkn_",
}, },
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("planetScale", "pscale_tkn_"+secrets.NewSecret(utils.AlphaNumericExtended("32")))
utils.GenerateSampleSecret("planetScalePassword", "pscale_tkn_"+secrets.NewSecret(utils.AlphaNumericExtended("32"))), tps = append(tps, utils.GenerateSampleSecrets("planetScale", "pscale_tkn_"+secrets.NewSecret(utils.AlphaNumericExtended("43")))...)
utils.GenerateSampleSecret("planetScalePassword", "pscale_tkn_"+secrets.NewSecret(utils.AlphaNumericExtended("43"))), tps = append(tps, utils.GenerateSampleSecrets("planetScale", "pscale_tkn_"+secrets.NewSecret(utils.AlphaNumericExtended("64")))...)
utils.GenerateSampleSecret("planetScalePassword", "pscale_tkn_"+secrets.NewSecret(utils.AlphaNumericExtended("64"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -53,18 +49,16 @@ func PlanetScaleOAuthToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "planetscale-oauth-token", RuleID: "planetscale-oauth-token",
Description: "Found a PlanetScale OAuth token, posing a risk to database access control and sensitive data integrity.", Description: "Found a PlanetScale OAuth token, posing a risk to database access control and sensitive data integrity.",
Regex: utils.GenerateUniqueTokenRegex(`pscale_oauth_(?i)[a-z0-9=\-_\.]{32,64}`, true), Regex: utils.GenerateUniqueTokenRegex(`pscale_oauth_[\w=\.-]{32,64}`, false),
Entropy: 3,
Keywords: []string{ Keywords: []string{
"pscale_oauth_", "pscale_oauth_",
}, },
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("planetScale", "pscale_oauth_"+secrets.NewSecret(utils.AlphaNumericExtended("32")))
utils.GenerateSampleSecret("planetScalePassword", "pscale_oauth_"+secrets.NewSecret(utils.AlphaNumericExtended("32"))), tps = append(tps, utils.GenerateSampleSecrets("planetScale", "pscale_oauth_"+secrets.NewSecret(utils.AlphaNumericExtended("43")))...)
utils.GenerateSampleSecret("planetScalePassword", "pscale_oauth_"+secrets.NewSecret(utils.AlphaNumericExtended("43"))), tps = append(tps, utils.GenerateSampleSecrets("planetScale", "pscale_oauth_"+secrets.NewSecret(utils.AlphaNumericExtended("64")))...)
utils.GenerateSampleSecret("planetScalePassword", "pscale_oauth_"+secrets.NewSecret(utils.AlphaNumericExtended("64"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+3 -5
View File
@@ -11,16 +11,14 @@ func PostManAPI() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "postman-api-token", RuleID: "postman-api-token",
Description: "Uncovered a Postman API token, potentially compromising API testing and development workflows.", Description: "Uncovered a Postman API token, potentially compromising API testing and development workflows.",
Regex: utils.GenerateUniqueTokenRegex(`PMAK-(?i)[a-f0-9]{24}\-[a-f0-9]{34}`, true), Regex: utils.GenerateUniqueTokenRegex(`PMAK-(?i)[a-f0-9]{24}\-[a-f0-9]{34}`, false),
Entropy: 3,
Keywords: []string{ Keywords: []string{
"PMAK-", "PMAK-",
}, },
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("postmanAPItoken", "PMAK-"+secrets.NewSecret(utils.Hex("24"))+"-"+secrets.NewSecret(utils.Hex("34")))
utils.GenerateSampleSecret("postmanAPItoken", "PMAK-"+secrets.NewSecret(utils.Hex("24"))+"-"+secrets.NewSecret(utils.Hex("34"))),
}
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+6 -5
View File
@@ -11,16 +11,17 @@ func Prefect() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "prefect-api-token", RuleID: "prefect-api-token",
Description: "Detected a Prefect API token, risking unauthorized access to workflow management and automation services.", Description: "Detected a Prefect API token, risking unauthorized access to workflow management and automation services.",
Regex: utils.GenerateUniqueTokenRegex(`pnu_[a-z0-9]{36}`, true), Regex: utils.GenerateUniqueTokenRegex(`pnu_[a-zA-Z0-9]{36}`, false),
Entropy: 2,
Keywords: []string{ Keywords: []string{
"pnu_", "pnu_",
}, },
} }
// validate // validate
tps := []string{ tps := utils.GenerateSampleSecrets("api-token", "pnu_"+secrets.NewSecret(utils.AlphaNumeric("36")))
utils.GenerateSampleSecret("api-token", "pnu_"+secrets.NewSecret(utils.AlphaNumeric("36"))), fps := []string{
`PREFECT_API_KEY = "pnu_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"`,
} }
return utils.Validate(r, tps, nil) return utils.Validate(r, tps, fps)
} }
+2 -2
View File
@@ -1,9 +1,9 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" regexp "github.com/wasilibs/go-re2"
"regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
Loaded 100 of 201 files, more files were not shown because too many files have changed in this diff. Show more