Compare commits

..
44 Commits
Author SHA1 Message Date
Richard Gomez ed19c4e8b4 fix(config): extend allowlist & handle extend when validating (#1524) 2024-09-25 08:20:19 -05:00
Richard Gomez 989ef19fb0 refactor(kubernetes-secret): tweak variable chars (#1520) 2024-09-25 08:02:15 -05:00
Richard Gomez 191eb43841 Revert "remove validate config test temporarily" (#1529)
* Revert "remove validate config test temporarily"

This reverts commit 1a6d2b0a7a.

* style: fix lint error
2024-09-25 08:01:26 -05:00
Richard Gomez 78f7d3f5df feat: create fly.io rule (#1528) 2024-09-24 16:09:15 -05:00
Roger Meier 7098f6d958 fix: to many false-positive for gltf files, add gltf suffix to allowlist (#1527)
Closes #1526
2024-09-24 08:48:25 -05:00
97dbe1ef09 Add support in .gitleaksignore file comment strings (#1425) (#1502)
* Add support in .gitleaksignore file comment strings  (#1195)

* Apply suggestions from code review

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

---------

Co-authored-by: Zachary Rice <zricezrice@gmail.com>
Co-authored-by: Richard Gomez <32133502+rgmz@users.noreply.github.com>
2024-09-18 13:44:44 -05:00
Richard Gomez 9e06824372 Restrict Etsy keywords (#1491)
* feat(etsy): tweak keywords

* fix(etsy): make identifiers case sensitive
The prior commit didn't work because the identifiers are made intentionally case insensitive.
See: https://github.com/gitleaks/gitleaks/blob/4e43d1109303568509596ef5ef576fbdc0509891/cmd/generate/config/utils/generate.go#L35-L37
2024-09-18 10:24:41 -05:00
Richard Gomez db782603f7 feat(github): add entropy to rule (#1489) 2024-09-18 10:23:44 -05:00
Richard Gomez df126a7473 feat(gcp): update api key rule (#1481) 2024-09-18 10:23:18 -05:00
Richard Gomez 75dd70e59a fix(hashicorp): ignore common fps (#1498)
Based on discussion in https://github.com/gitleaks/gitleaks/issues/1490
2024-09-18 10:22:47 -05:00
Richard Gomez 8510d39ffe fix(square): make prefix case sensitive (#1469) 2024-09-18 10:22:25 -05:00
Richard Gomez 3698060a2b refactor(kubernetes-secret): collapse rules and update regex (#1462) 2024-09-18 10:22:10 -05:00
Richard Gomez 128cd22f7c fix(rule): comment out errant validation case (#1509)
This should be re-enabled once a more suitable fix is implemented.
2024-09-16 06:17:26 -05:00
Zachary Rice 1a6d2b0a7a remove validate config test temporarily 2024-09-14 05:49:13 -05:00
Zachary Rice 0874ebcc3f Update README.md 2024-09-14 05:46:28 -05:00
Zachary Rice 9463ffaa5e fix flag access (#1506) 2024-09-14 04:01:27 -05:00
Zachary Rice 44ad62e0b1 Deprecate detect and protect. Add git, dir, stdin (#1504)
* init backwards compatible cmd

* update readme, todos

* ...

* moar comments, sprucing up root

* readme change
2024-09-13 19:44:22 -05:00
Dewan Ishtiaque Ahmed e93a7c0d26 Update Harness rules to add _ and - in the account ID part. (#1503) 2024-09-11 19:48:12 -05:00
Richard Gomez 4e43d11093 chore: fix gl workflow error (#1487) 2024-08-26 17:47:02 -05:00
Richard Gomez bd81872eee Make config generation utils public (#1480)
* chore(generate): make utils public

* chore(generate): change validate log messages

* chore(generate): split functions into files

* chore(config): add warning for public funcs
2024-08-26 13:11:18 -05:00
Richard Gomez 3be7faa1ff Update Hashicorp Vault token pattern (#1483)
* feat(vault): add old pat, tweak new pat

* feat(hashicorp): add entropy to tf rule
2024-08-25 15:19:37 -05:00
Richard Gomez 1aae66d564 feat(config): update rule validation (#1466) 2024-08-22 09:55:44 -05:00
Zachary Rice 6dfcf5e949 Update .gitleaksignore 2024-08-20 06:57:30 -05:00
Richard Gomez f361c5ef71 fix(detect): handle EOF with bytes (#1472) 2024-08-19 14:00:47 -05:00
malmor 8a1ca9ecc9 Added poetry.lock to default allowlist paths (#1474) 2024-08-19 11:47:42 -05:00
Richard Gomez 525c4b4451 refactor(sarif): remove |name| and change |shortDescription| (#1473) 2024-08-19 09:11:31 -05:00
Richard Gomez c0fda4358e Use rule id for config validation error (#1463)
* chore(config): use rule id for error

* feat(config): ensure rule.id is not empty
2024-08-08 15:47:34 -05:00
Richard Gomez d3c4b9078e Use first non-empty group if secretGroup isn't set (#1459)
* feat(detect): secret is first non-empty group

* test: fix errors

- update capture groups
- update expected data
2024-08-07 12:10:05 -05:00
Richard Gomez b4009bfba4 chore: remove unnecessary capture groups (#1460) 2024-08-07 12:09:16 -05:00
Richard Gomez 80bd1779e3 Return non-0 exit code from DetectGit (#1461)
* fix(detect): exit code for git errors

* chore(detect): add consistent error msgs
2024-08-07 10:14:00 -05:00
niklas-w7andniklas.w 0334ec1076 add gradle verification-metadata.xml to global allowlist (#1446)
Co-authored-by: niklas.w <niklas.wissmueller@ext.ibmix.de>
2024-08-05 20:35:54 -05:00
Richard Gomez c1345e1b2b feat(openshift): add user token (#1449) 2024-08-05 20:22:31 -05:00
LeonandZach 7697b3e989 (feat): Adding secret detection rule for Kubernetes secrets (#1454)
* (feat): Adding secret detection rule for Kubernetes secrets

Signed-off-by: localleon <me@lrau.xyz>

* (fix): Limiting kubernetes secret detection only to .yaml/.yml files

Signed-off-by: localleon <me@lrau.xyz>

* (fix): Fixing path validation testing for kubernetes-secret

Signed-off-by: localleon <me@lrau.xyz>

* (fix): refactoring path validation regex for kubernetes secret

* (fix): fixing keyword for kubernetes secret

Signed-off-by: localleon <me@lrau.xyz>

* (fix): fixing config.toml for kubernetes-secret and reording rules/main.go

Signed-off-by: localleon <me@lrau.xyz>

* (feat): Implementing proxmitiy matching for data-key in kubernetes secrets

Signed-off-by: localleon <me@lrau.xyz>

* (fix): Adding regex sugestions for quoted strings and qouted test-cases

* (fix): Updating kubernetes-secret regex to allow '-character before secret e.g if theres quoting

* limit whitespace

---------

Signed-off-by: localleon <me@lrau.xyz>
Co-authored-by: Zach <zricer@protonmail.com>
2024-08-05 20:20:52 -05:00
Zachary Rice 26f34692fa add version to default 2024-06-14 16:48:12 -04:00
AislingHPE bc979deb0f Add go.work and go.work.sum to global allowlist (#1353) 2024-06-14 15:31:04 -04:00
Dewan Ishtiaque AhmedandZachary Rice b899915813 Add harness PAT and SAT rules (#1406)
* Add Harness PAT rule.

* Add support for Harness PAT and SAT.

* Update comment for Harness SAT.

* Consolidate PAT and SAT into Harness API Key

* add ignore and capture group to match

---------

Co-authored-by: Zachary Rice <zachary.rice@trufflesec.com>
2024-06-14 15:30:07 -04:00
Zachary Rice 4c5195b700 Update README.md 2024-06-14 15:22:23 -04:00
becojoandBecojo 02808f45d0 Limit hashicorp-tf-password to .tf/.hcl files (#1420)
* Limit hashicorp-tf-password to .tf/.hcl files

* fix tests

---------

Co-authored-by: Becojo <Becojo@users.noreply.github.com>
2024-06-13 11:23:26 -04:00
Zachary Rice 07e1c30592 rm print 2024-06-13 11:14:44 -04:00
Zachary Rice db63fc1bf4 reduce telegram... todo url and xml for later 2024-06-13 11:14:02 -04:00
Zachary Rice 9a4538c4d6 coderabbit.ai <3 2024-06-13 09:16:17 -04:00
danielap-ma fe94ef9ca3 Add NewRelic insert key detection (#1417) 2024-06-02 18:18:52 -05:00
Toxandtoxyl bb4424d454 Improved Telegram bot token rule regex and added more test cases (#1404)
Co-authored-by: toxyl <tox@novasonica.com>
2024-06-01 18:56:14 -05:00
Alexandre GUIOT--VALENTIN 575e923cf8 Add intra42 client secret (#1408)
intra42 is the intranet and API of "42 School", a CS school.
The API is open to all students in 57 campus around the world.
It is thus often subject to credentials leaks on GitHub
See https://42.fr and https://api.intra.42.fr/
2024-06-01 18:55:04 -05:00
146 changed files with 2331 additions and 1038 deletions

No files matched your search

+1
View File
@@ -765,4 +765,5 @@ acce01f2338434a78f6a4a06a097b0fd23280484:README.md:aws-access-token:220
adf617b3b4628e1160fa3d135b4c3dfd45c05e15:testdata/repos/nogit/api.go:aws-access-token:20 adf617b3b4628e1160fa3d135b4c3dfd45c05e15:testdata/repos/nogit/api.go:aws-access-token:20
adf617b3b4628e1160fa3d135b4c3dfd45c05e15:testdata/repos/small/api/ignoreGlobal.go:aws-access-token:20 adf617b3b4628e1160fa3d135b4c3dfd45c05e15:testdata/repos/small/api/ignoreGlobal.go:aws-access-token:20
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
+53 -99
View File
@@ -30,7 +30,7 @@
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 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.
``` ```
➜ ~/code(master) gitleaks detect --source . -v ➜ ~/code(master) gitleaks git -v
○ ○
│╲ │╲
@@ -64,13 +64,13 @@ brew install gitleaks
# Docker (DockerHub) # Docker (DockerHub)
docker pull zricethezav/gitleaks:latest docker pull zricethezav/gitleaks:latest
docker run -v ${path_to_host_folder_to_scan}:/path zricethezav/gitleaks:latest [COMMAND] --source="/path" [OPTIONS] docker run -v ${path_to_host_folder_to_scan}:/path zricethezav/gitleaks:latest [COMMAND] [OPTIONS] [SOURCE_PATH]
# Docker (ghcr.io) # Docker (ghcr.io)
docker pull ghcr.io/gitleaks/gitleaks:latest docker pull ghcr.io/gitleaks/gitleaks:latest
docker run -v ${path_to_host_folder_to_scan}:/path ghcr.io/gitleaks/gitleaks:latest [COMMAND] --source="/path" [OPTIONS] docker run -v ${path_to_host_folder_to_scan}:/path ghcr.io/gitleaks/gitleaks:latest [COMMAND] [OPTIONS] [SOURCE_PATH]
# From Source # From Source (make sure `go` is installed)
git clone https://github.com/gitleaks/gitleaks.git git clone https://github.com/gitleaks/gitleaks.git
cd gitleaks cd gitleaks
make build make build
@@ -105,7 +105,7 @@ jobs:
``` ```
repos: repos:
- repo: https://github.com/gitleaks/gitleaks - repo: https://github.com/gitleaks/gitleaks
rev: v8.16.1 rev: v8.19.0
hooks: hooks:
- id: gitleaks - id: gitleaks
``` ```
@@ -137,63 +137,59 @@ Usage:
Available Commands: Available Commands:
completion generate the autocompletion script for the specified shell completion generate the autocompletion script for the specified shell
detect detect secrets in code dir scan directories or files for secrets
git scan git repositories for secrets
help Help about any command help Help about any command
protect protect secrets in code stdin detect secrets from stdin
version display gitleaks version version display gitleaks version
Flags: Flags:
-b, --baseline-path string path to baseline with issues that can be ignored -b, --baseline-path string path to baseline with issues that can be ignored
-c, --config string config file path -c, --config string config file path
order of precedence: order of precedence:
1. --config/-c 1. --config/-c
2. env var GITLEAKS_CONFIG 2. env var GITLEAKS_CONFIG
3. (--source/-s)/.gitleaks.toml 3. (target path)/.gitleaks.toml
If none of the three options are used, then gitleaks will use the default config If none of the three options are used, then gitleaks will use the default config
--exit-code int exit code when leaks have been encountered (default 1) --enable-rule strings only enable specific rules by id
-h, --help help for gitleaks --exit-code int exit code when leaks have been encountered (default 1)
-l, --log-level string log level (trace, debug, info, warn, error, fatal) (default "info") -i, --gitleaks-ignore-path string path to .gitleaksignore file or folder containing one (default ".")
--max-target-megabytes int files larger than this will be skipped -h, --help help for gitleaks
--no-color turn off color for verbose output --ignore-gitleaks-allow ignore gitleaks:allow comments
--no-banner suppress banner -l, --log-level string log level (trace, debug, info, warn, error, fatal) (default "info")
--redact redact secrets from logs and stdout --max-target-megabytes int files larger than this will be skipped
-f, --report-format string output format (json, csv, junit, sarif) (default "json") --no-banner suppress banner
-r, --report-path string report file --no-color turn off color for verbose output
-s, --source string path to source (default ".") --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%)
-v, --verbose show verbose output from scan -f, --report-format string output format (json, csv, junit, sarif) (default "json")
-r, --report-path string report file
-v, --verbose show verbose output from scan
--version version for gitleaks
Use "gitleaks [command] --help" for more information about a command. Use "gitleaks [command] --help" for more information about a command.
``` ```
### Commands ### Commands
There are two commands you will use to detect secrets; `detect` and `protect`. ⚠️ v8.19.0 introduced a change that deprecated `detect` and `protect`. Those commands are still available but
are hidden in the `--help` menu. Take a look at this [gist](https://gist.github.com/zricethezav/b325bb93ebf41b9c0b0507acf12810d2) for easy command translations.
If you find v8.19.0 broke an existing command (`detect`/`protect`), please open an issue.
#### Detect There are three scanning modes: `git`, `dir`, and `stdin`.
The `detect` command is used to scan repos, directories, and files. This command can be used on developer machines and in CI environments. #### Git
The `git` command lets you scan local git repos. Under the hood, gitleaks uses the `git log -p` command to scan patches.
You can configure the behavior of `git log -p` with the `log-opts` option.
For example, if you wanted to run gitleaks on a range of commits you could use the following
command: `gitleaks git -v --log-opts="--all commitA..commitB" path_to_repo`. See the [git log](https://git-scm.com/docs/git-log) documentation for more information.
If there is no target specified as a positional argument, then gitleaks will attempt to scan the current working directory as a git repo.
When running `detect` on a git repository, gitleaks will parse the output of a `git log -p` command (you can see how this executed #### Dir
[here](https://github.com/zricethezav/gitleaks/blob/7240e16769b92d2a1b137c17d6bf9d55a8562899/git/git.go#L17-L25)). The `dir` (aliases include `files`, `directory`) command lets you scan directories and files. Example: `gitleaks dir -v path_to_directory_or_file`.
[`git log -p` generates patches](https://git-scm.com/docs/git-log#_generating_patch_text_with_p) which gitleaks will use to detect secrets. If there is no target specified as a positional argument, then gitleaks will scan the current working directory.
You can configure what commits `git log` will range over by using the `--log-opts` flag. `--log-opts` accepts any option for `git log -p`.
For example, if you wanted to run gitleaks on a range of commits you could use the following command: `gitleaks detect --source . --log-opts="--all commitA..commitB"`.
See the `git log` [documentation](https://git-scm.com/docs/git-log) for more information.
You can scan files and directories by using the `--no-git` option. #### Stdin
You can also stream data to gitleaks with the `stdin` command. Example: `cat some_file | gitleaks -v stdin`
If you want to run only specific rules you can do so by using the `--enable-rule` option (with a rule ID as a parameter), this flag can be used multiple times. For example: `--enable-rule=atlassian-api-token` will only apply that rule. You can find a list of rules [here](config/gitleaks.toml).
#### Protect
The `protect` command is used to scan uncommitted changes in a git repo. This command should be used on developer machines in accordance with
[shifting left on security](https://cloud.google.com/architecture/devops/devops-tech-shifting-left-on-security).
When running `protect` on a git repository, gitleaks will parse the output of a `git diff` command (you can see how this executed
[here](https://github.com/zricethezav/gitleaks/blob/7240e16769b92d2a1b137c17d6bf9d55a8562899/git/git.go#L48-L49)). You can set the
`--staged` flag to check for changes in commits that have been `git add`ed. The `--staged` flag should be used when running Gitleaks
as a pre-commit.
**NOTE**: the `protect` command can only be used on git repos, running `protect` on files or directories will result in an error message.
### Creating a baseline ### Creating a baseline
@@ -201,65 +197,17 @@ When scanning large repositories or repositories with a long history, it can be
gitleaks will ignore any old findings that are present in the baseline. A baseline can be any gitleaks report. To create a gitleaks report, run gitleaks with the `--report-path` parameter. gitleaks will ignore any old findings that are present in the baseline. A baseline can be any gitleaks report. To create a gitleaks report, run gitleaks with the `--report-path` parameter.
``` ```
gitleaks detect --report-path gitleaks-report.json # This will save the report in a file called gitleaks-report.json gitleaks git --report-path gitleaks-report.json # This will save the report in a file called gitleaks-report.json
``` ```
Once as baseline is created it can be applied when running the detect command again: Once as baseline is created it can be applied when running the detect command again:
``` ```
gitleaks detect --baseline-path gitleaks-report.json --report-path findings.json gitleaks git --baseline-path gitleaks-report.json --report-path findings.json
``` ```
After running the detect command with the --baseline-path parameter, report output (findings.json) will only contain new issues. After running the detect command with the --baseline-path parameter, report output (findings.json) will only contain new issues.
### Verify Findings
You can verify a finding found by gitleaks using a `git log` command.
Example output:
```
Finding: aws_secret="AKIAIMNOJVGFDXXXE4OA"
RuleID: aws-access-token
Secret AKIAIMNOJVGFDXXXE4OA
Entropy: 3.65
File: checks_test.go
Line: 37
Commit: ec2fc9d6cb0954fb3b57201cf6133c48d8ca0d29
Author: Zachary Rice
Email: z@email.com
Date: 2018-01-28T17:39:00Z
Fingerprint: ec2fc9d6cb0954fb3b57201cf6133c48d8ca0d29:checks_test.go:aws-access-token:37
```
We can use the following format to verify the leak:
```
git log -L {StartLine,EndLine}:{File} {Commit}
```
So in this example it would look like:
```
git log -L 37,37:checks_test.go ec2fc9d6cb0954fb3b57201cf6133c48d8ca0d29
```
Which gives us:
```
commit ec2fc9d6cb0954fb3b57201cf6133c48d8ca0d29
Author: zricethezav <thisispublicanyways@gmail.com>
Date: Sun Jan 28 17:39:00 2018 -0500
[update] entropy check
diff --git a/checks_test.go b/checks_test.go
--- a/checks_test.go
+++ b/checks_test.go
@@ -28,0 +37,1 @@
+ "aws_secret= \"AKIAIMNOJVGFDXXXE4OA\"": true,
```
## Pre-Commit hook ## Pre-Commit hook
You can run Gitleaks as a pre-commit hook by copying the example `pre-commit.py` script into You can run Gitleaks as a pre-commit hook by copying the example `pre-commit.py` script into
@@ -402,13 +350,19 @@ class CustomClass:
You can ignore specific findings by creating a `.gitleaksignore` file at the root of your repo. In release v8.10.0 Gitleaks added a `Fingerprint` value to the Gitleaks report. Each leak, or finding, has a Fingerprint that uniquely identifies a secret. Add this fingerprint to the `.gitleaksignore` file to ignore that specific secret. See Gitleaks' [.gitleaksignore](https://github.com/zricethezav/gitleaks/blob/master/.gitleaksignore) for an example. Note: this feature is experimental and is subject to change in the future. You can ignore specific findings by creating a `.gitleaksignore` file at the root of your repo. In release v8.10.0 Gitleaks added a `Fingerprint` value to the Gitleaks report. Each leak, or finding, has a Fingerprint that uniquely identifies a secret. Add this fingerprint to the `.gitleaksignore` file to ignore that specific secret. See Gitleaks' [.gitleaksignore](https://github.com/zricethezav/gitleaks/blob/master/.gitleaksignore) for an example. Note: this feature is experimental and is subject to change in the future.
## Sponsorships ## Sponsorships
<p align="left">
<h3><a href="https://coderabbit.ai/?utm_source=oss&utm_medium=sponsorship&utm_campaign=gitleaks">coderabbit.ai</h3>
<a href="https://coderabbit.ai/?utm_source=oss&utm_medium=sponsorship&utm_campaign=gitleaks">
<img alt="CodeRabbit.ai Sponsorship" src="https://github.com/gitleaks/gitleaks/assets/15034943/76c30a85-887b-47ca-9956-17a8e55c6c41" width=200>
</a>
</p>
<p align="left"> <p align="left">
<a href="https://www.tines.com/?utm_source=oss&utm_medium=sponsorship&utm_campaign=gitleaks"> <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> <img alt="Tines Sponsorship" src="https://user-images.githubusercontent.com/15034943/146411864-4878f936-b4f7-49a0-b625-f9f40c704bfa.png" width=200>
</a> </a>
</p> </p>
## Exit Codes ## Exit Codes
You can always set the exit code when leaks are encountered with the --exit-code flag. Default exit codes below: You can always set the exit code when leaks are encountered with the --exit-code flag. Default exit codes below:
+51 -22
View File
@@ -1,3 +1,21 @@
// The `detect` and `protect` command is now deprecated. Here are some equivalent commands
// to help guide you.
// OLD CMD: gitleaks detect --source={repo}
// NEW CMD: gitleaks git {repo}
// OLD CMD: gitleaks protect --source={repo}
// NEW CMD: gitleaks git --pre-commit {repo}
// OLD CMD: gitleaks protect --staged --source={repo}
// NEW CMD: gitleaks git --pre-commit --staged {repo}
// OLD CMD: gitleaks detect --no-git --source={repo}
// NEW CMD: gitleaks directory {directory/file}
// OLD CMD: gitleaks detect --no-git --pipe
// NEW CMD: gitleaks stdin
package cmd package cmd
import ( import (
@@ -15,20 +33,26 @@ func init() {
rootCmd.AddCommand(detectCmd) rootCmd.AddCommand(detectCmd)
detectCmd.Flags().Bool("no-git", false, "treat git repo as a regular directory and scan those files, --log-opts has no effect on the scan when --no-git is set") detectCmd.Flags().Bool("no-git", false, "treat git repo as a regular directory and scan those files, --log-opts has no effect on the scan when --no-git is set")
detectCmd.Flags().Bool("pipe", false, "scan input from stdin, ex: `cat some_file | gitleaks detect --pipe`") detectCmd.Flags().Bool("pipe", false, "scan input from stdin, ex: `cat some_file | gitleaks detect --pipe`")
detectCmd.Flags().Bool("follow-symlinks", false, "scan files that are symlinks to other files")
detectCmd.Flags().StringP("source", "s", ".", "path to source")
detectCmd.Flags().String("log-opts", "", "git log options")
} }
var detectCmd = &cobra.Command{ var detectCmd = &cobra.Command{
Use: "detect", Use: "detect",
Short: "detect secrets in code", Short: "detect secrets in code",
Run: runDetect, Run: runDetect,
Hidden: true,
} }
func runDetect(cmd *cobra.Command, args []string) { func runDetect(cmd *cobra.Command, args []string) {
initConfig() source, err := cmd.Flags().GetString("source")
var ( if err != nil {
findings []report.Finding log.Fatal().Err(err).Msg("could not get source")
err error }
) initConfig(source)
var findings []report.Finding
// setup config (aka, the thing that defines rules) // setup config (aka, the thing that defines rules)
cfg := Config(cmd) cfg := Config(cmd)
@@ -36,11 +60,6 @@ func runDetect(cmd *cobra.Command, args []string) {
// start timer // start timer
start := time.Now() start := time.Now()
// grab source
source, err := cmd.Flags().GetString("source")
if err != nil {
log.Fatal().Err(err).Msg("")
}
detector := Detector(cmd, cfg, source) detector := Detector(cmd, cfg, source)
// set exit code // set exit code
@@ -58,43 +77,53 @@ func runDetect(cmd *cobra.Command, args []string) {
} }
fromPipe, err := cmd.Flags().GetBool("pipe") fromPipe, err := cmd.Flags().GetBool("pipe")
if err != nil { if err != nil {
log.Fatal().Err(err) log.Fatal().Err(err).Msg("could not call GetBool() for pipe")
} }
// start the detector scan // start the detector scan
if noGit { if noGit {
paths, err := sources.DirectoryTargets(source, detector.Sema, detector.FollowSymlinks) var paths <-chan sources.ScanTarget
paths, err = sources.DirectoryTargets(source, detector.Sema, detector.FollowSymlinks)
if err != nil { if err != nil {
log.Fatal().Err(err) log.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("") log.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("") log.Fatal().Err(err).Msg("failed scan input from stdin")
} }
} else { } else {
var logOpts string var (
gitCmd *sources.GitCmd
logOpts 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("") log.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("") log.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("") log.Error().Err(err).Msg("failed to scan Git repository")
} }
} }
// set follow symlinks flag
if detector.FollowSymlinks, err = cmd.Flags().GetBool("follow-symlinks"); err != nil {
log.Fatal().Err(err).Msg("")
}
findingSummaryAndExit(findings, cmd, cfg, exitCode, start, err) findingSummaryAndExit(findings, cmd, cfg, exitCode, start, err)
} }
+67
View File
@@ -0,0 +1,67 @@
package cmd
import (
"time"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/zricethezav/gitleaks/v8/report"
"github.com/zricethezav/gitleaks/v8/sources"
)
func init() {
rootCmd.AddCommand(directoryCmd)
directoryCmd.Flags().Bool("follow-symlinks", false, "scan files that are symlinks to other files")
}
var directoryCmd = &cobra.Command{
Use: "dir [flags] [path]",
Aliases: []string{"file", "directory"},
Short: "scan directories or files for secrets",
Run: runDirectory,
}
func runDirectory(cmd *cobra.Command, args []string) {
// grab source
source := "."
if len(args) == 1 {
source = args[0]
if source == "" {
source = "."
}
}
initConfig(source)
var (
findings []report.Finding
err error
)
// setup config (aka, the thing that defines rules)
cfg := Config(cmd)
// start timer
start := time.Now()
detector := Detector(cmd, cfg, source)
// set exit code
exitCode, err := cmd.Flags().GetInt("exit-code")
if err != nil {
log.Fatal().Err(err).Msg("could not get exit code")
}
var paths <-chan sources.ScanTarget
paths, err = sources.DirectoryTargets(source, detector.Sema, detector.FollowSymlinks)
if err != nil {
log.Fatal().Err(err)
}
findings, err = detector.DetectFiles(paths)
if err != nil {
// don't exit on error, just log it
log.Error().Err(err).Msg("failed scan directory")
}
findingSummaryAndExit(findings, cmd, cfg, exitCode, start, err)
}
+7 -1
View File
@@ -81,6 +81,7 @@ func main() {
rules.FlutterwavePublicKey(), rules.FlutterwavePublicKey(),
rules.FlutterwaveSecretKey(), rules.FlutterwaveSecretKey(),
rules.FlutterwaveEncKey(), rules.FlutterwaveEncKey(),
rules.FlyIOAccessToken(),
rules.FrameIO(), rules.FrameIO(),
rules.FreshbooksAccessToken(), rules.FreshbooksAccessToken(),
rules.GoCardless(), rules.GoCardless(),
@@ -99,18 +100,21 @@ func main() {
rules.GrafanaApiKey(), rules.GrafanaApiKey(),
rules.GrafanaCloudApiToken(), rules.GrafanaCloudApiToken(),
rules.GrafanaServiceAccountToken(), rules.GrafanaServiceAccountToken(),
rules.Hashicorp(), rules.HarnessApiKey(),
rules.HashiCorpTerraform(),
rules.HashicorpField(), rules.HashicorpField(),
rules.Heroku(), rules.Heroku(),
rules.HubSpot(), rules.HubSpot(),
rules.HuggingFaceAccessToken(), rules.HuggingFaceAccessToken(),
rules.HuggingFaceOrganizationApiToken(), rules.HuggingFaceOrganizationApiToken(),
rules.Intercom(), rules.Intercom(),
rules.Intra42ClientSecret(),
rules.JFrogAPIKey(), rules.JFrogAPIKey(),
rules.JFrogIdentityToken(), rules.JFrogIdentityToken(),
rules.JWT(), rules.JWT(),
rules.JWTBase64(), rules.JWTBase64(),
rules.KrakenAccessToken(), rules.KrakenAccessToken(),
rules.KubernetesSecret(),
rules.KucoinAccessToken(), rules.KucoinAccessToken(),
rules.KucoinSecretKey(), rules.KucoinSecretKey(),
rules.LaunchDarklyAccessToken(), rules.LaunchDarklyAccessToken(),
@@ -132,10 +136,12 @@ func main() {
rules.NewRelicUserID(), rules.NewRelicUserID(),
rules.NewRelicUserKey(), rules.NewRelicUserKey(),
rules.NewRelicBrowserAPIKey(), rules.NewRelicBrowserAPIKey(),
rules.NewRelicInsertKey(),
rules.NPM(), rules.NPM(),
rules.NytimesAccessToken(), rules.NytimesAccessToken(),
rules.OktaAccessToken(), rules.OktaAccessToken(),
rules.OpenAI(), rules.OpenAI(),
rules.OpenshiftUserToken(),
rules.PlaidAccessID(), rules.PlaidAccessID(),
rules.PlaidSecretKey(), rules.PlaidSecretKey(),
rules.PlaidAccessToken(), rules.PlaidAccessToken(),
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,13 +11,13 @@ func AdafruitAPIKey() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Identified a potential Adafruit API Key, which could lead to unauthorized access to Adafruit services and sensitive data exposure.", Description: "Identified a potential Adafruit API Key, which could lead to unauthorized access to Adafruit services and sensitive data exposure.",
RuleID: "adafruit-api-key", RuleID: "adafruit-api-key",
Regex: generateSemiGenericRegex([]string{"adafruit"}, alphaNumericExtendedShort("32"), true), Regex: utils.GenerateSemiGenericRegex([]string{"adafruit"}, utils.AlphaNumericExtendedShort("32"), true),
Keywords: []string{"adafruit"}, Keywords: []string{"adafruit"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("adafruit", secrets.NewSecret(alphaNumericExtendedShort("32"))), utils.GenerateSampleSecret("adafruit", secrets.NewSecret(utils.AlphaNumericExtendedShort("32"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+7 -6
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,15 +11,15 @@ func AdobeClientID() *config.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.", 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",
Regex: generateSemiGenericRegex([]string{"adobe"}, hex("32"), true), Regex: utils.GenerateSemiGenericRegex([]string{"adobe"}, utils.Hex("32"), true),
Keywords: []string{"adobe"}, Keywords: []string{"adobe"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("adobe", secrets.NewSecret(hex("32"))), utils.GenerateSampleSecret("adobe", secrets.NewSecret(utils.Hex("32"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func AdobeClientSecret() *config.Rule { func AdobeClientSecret() *config.Rule {
@@ -26,13 +27,13 @@ func AdobeClientSecret() *config.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.", 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: generateUniqueTokenRegex(`(p8e-)(?i)[a-z0-9]{32}`, true), Regex: utils.GenerateUniqueTokenRegex(`(p8e-)(?i)[a-z0-9]{32}`, true),
Keywords: []string{"p8e-"}, Keywords: []string{"p8e-"},
} }
// validate // validate
tps := []string{ tps := []string{
"adobeClient := \"p8e-" + secrets.NewSecret(hex("32")) + "\"", "adobeClient := \"p8e-" + secrets.NewSecret(utils.Hex("32")) + "\"",
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+2 -1
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
@@ -19,5 +20,5 @@ func AgeSecretKey() *config.Rule {
tps := []string{ tps := []string{
`apiKey := "AGE-SECRET-KEY-1QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ`, // gitleaks:allow `apiKey := "AGE-SECRET-KEY-1QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ`, // gitleaks:allow
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,13 +11,13 @@ func Airtable() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Uncovered a possible Airtable API Key, potentially compromising database access and leading to data leakage or alteration.", Description: "Uncovered a possible Airtable API Key, potentially compromising database access and leading to data leakage or alteration.",
RuleID: "airtable-api-key", RuleID: "airtable-api-key",
Regex: generateSemiGenericRegex([]string{"airtable"}, alphaNumeric("17"), true), Regex: utils.GenerateSemiGenericRegex([]string{"airtable"}, utils.AlphaNumeric("17"), true),
Keywords: []string{"airtable"}, Keywords: []string{"airtable"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("airtable", secrets.NewSecret(alphaNumeric("17"))), utils.GenerateSampleSecret("airtable", secrets.NewSecret(utils.AlphaNumeric("17"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,13 +11,13 @@ func AlgoliaApiKey() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Identified an Algolia API Key, which could result in unauthorized search operations and data exposure on Algolia-managed platforms.", Description: "Identified an Algolia API Key, which could result in unauthorized search operations and data exposure on Algolia-managed platforms.",
RuleID: "algolia-api-key", RuleID: "algolia-api-key",
Regex: generateSemiGenericRegex([]string{"algolia"}, `[a-z0-9]{32}`, true), Regex: utils.GenerateSemiGenericRegex([]string{"algolia"}, `[a-z0-9]{32}`, true),
Keywords: []string{"algolia"}, Keywords: []string{"algolia"},
} }
// validate // validate
tps := []string{ tps := []string{
"algolia_key := " + secrets.NewSecret(hex("32")), "algolia_key := " + secrets.NewSecret(utils.Hex("32")),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+8 -7
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,15 +11,15 @@ func AlibabaAccessKey() *config.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.", 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: generateUniqueTokenRegex(`(LTAI)(?i)[a-z0-9]{20}`, true), Regex: utils.GenerateUniqueTokenRegex(`(LTAI)(?i)[a-z0-9]{20}`, true),
Keywords: []string{"LTAI"}, Keywords: []string{"LTAI"},
} }
// validate // validate
tps := []string{ tps := []string{
"alibabaKey := \"LTAI" + secrets.NewSecret(hex("20")) + "\"", "alibabaKey := \"LTAI" + secrets.NewSecret(utils.Hex("20")) + "\"",
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
// TODO // TODO
@@ -27,15 +28,15 @@ func AlibabaSecretKey() *config.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.", 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: generateSemiGenericRegex([]string{"alibaba"}, Regex: utils.GenerateSemiGenericRegex([]string{"alibaba"},
alphaNumeric("30"), true), utils.AlphaNumeric("30"), true),
Keywords: []string{"alibaba"}, Keywords: []string{"alibaba"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("alibaba", secrets.NewSecret(alphaNumeric("30"))), utils.GenerateSampleSecret("alibaba", secrets.NewSecret(utils.AlphaNumeric("30"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+7 -6
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,15 +11,15 @@ func AsanaClientID() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Discovered a potential Asana Client ID, risking unauthorized access to Asana projects and sensitive task information.", Description: "Discovered a potential Asana Client ID, risking unauthorized access to Asana projects and sensitive task information.",
RuleID: "asana-client-id", RuleID: "asana-client-id",
Regex: generateSemiGenericRegex([]string{"asana"}, numeric("16"), true), Regex: utils.GenerateSemiGenericRegex([]string{"asana"}, utils.Numeric("16"), true),
Keywords: []string{"asana"}, Keywords: []string{"asana"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("asana", secrets.NewSecret(numeric("16"))), utils.GenerateSampleSecret("asana", secrets.NewSecret(utils.Numeric("16"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func AsanaClientSecret() *config.Rule { func AsanaClientSecret() *config.Rule {
@@ -26,14 +27,14 @@ func AsanaClientSecret() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Identified an Asana Client Secret, which could lead to compromised project management integrity and unauthorized access.", Description: "Identified an Asana Client Secret, which could lead to compromised project management integrity and unauthorized access.",
RuleID: "asana-client-secret", RuleID: "asana-client-secret",
Regex: generateSemiGenericRegex([]string{"asana"}, alphaNumeric("32"), true), Regex: utils.GenerateSemiGenericRegex([]string{"asana"}, utils.AlphaNumeric("32"), true),
Keywords: []string{"asana"}, Keywords: []string{"asana"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("asana", secrets.NewSecret(alphaNumeric("32"))), utils.GenerateSampleSecret("asana", secrets.NewSecret(utils.AlphaNumeric("32"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+6 -5
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,15 +11,15 @@ 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: generateSemiGenericRegex([]string{ Regex: utils.GenerateSemiGenericRegex([]string{
"atlassian", "confluence", "jira"}, alphaNumeric("24"), true), "atlassian", "confluence", "jira"}, utils.AlphaNumeric("24"), true),
Keywords: []string{"atlassian", "confluence", "jira"}, Keywords: []string{"atlassian", "confluence", "jira"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("atlassian", secrets.NewSecret(alphaNumeric("24"))), utils.GenerateSampleSecret("atlassian", secrets.NewSecret(utils.AlphaNumeric("24"))),
generateSampleSecret("confluence", secrets.NewSecret(alphaNumeric("24"))), utils.GenerateSampleSecret("confluence", secrets.NewSecret(utils.AlphaNumeric("24"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+8 -7
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/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
@@ -13,19 +14,19 @@ func Authress() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Uncovered a possible Authress Service Client Access Key, which may compromise access control services and sensitive data.", 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: 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), 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),
Keywords: []string{"sc_", "ext_", "scauth_", "authress_"}, Keywords: []string{"sc_", "ext_", "scauth_", "authress_"},
} }
// validate // validate
// https://authress.io/knowledge-base/docs/authorization/service-clients/secrets-scanning/#1-detection // https://authress.io/knowledge-base/docs/authorization/service-clients/secrets-scanning/#1-detection
service_client_id := "sc_" + alphaNumeric("10") service_client_id := "sc_" + utils.AlphaNumeric("10")
access_key_id := alphaNumeric("4") access_key_id := utils.AlphaNumeric("4")
account_id := "acc_" + alphaNumeric("10") account_id := "acc_" + utils.AlphaNumeric("10")
signature_key := alphaNumericExtendedShort("40") signature_key := utils.AlphaNumericExtendedShort("40")
tps := []string{ tps := []string{
generateSampleSecret("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 validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+3 -2
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
@@ -22,6 +23,6 @@ func AWS() *config.Rule {
} }
// validate // validate
tps := []string{generateSampleSecret("AWS", "AKIALALEMEL33243OLIB")} // gitleaks:allow tps := []string{utils.GenerateSampleSecret("AWS", "AKIALALEMEL33243OLIB")} // gitleaks:allow
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,14 +11,14 @@ func Beamer() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Detected a Beamer API token, potentially compromising content management and exposing sensitive notifications and updates.", Description: "Detected a Beamer API token, potentially compromising content management and exposing sensitive notifications and updates.",
RuleID: "beamer-api-token", RuleID: "beamer-api-token",
Regex: generateSemiGenericRegex([]string{"beamer"}, Regex: utils.GenerateSemiGenericRegex([]string{"beamer"},
`b_[a-z0-9=_\-]{44}`, true), `b_[a-z0-9=_\-]{44}`, true),
Keywords: []string{"beamer"}, Keywords: []string{"beamer"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("beamer", "b_"+secrets.NewSecret(alphaNumericExtended("44"))), utils.GenerateSampleSecret("beamer", "b_"+secrets.NewSecret(utils.AlphaNumericExtended("44"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+7 -6
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,15 +11,15 @@ func BitBucketClientID() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Discovered a potential Bitbucket Client ID, risking unauthorized repository access and potential codebase exposure.", Description: "Discovered a potential Bitbucket Client ID, risking unauthorized repository access and potential codebase exposure.",
RuleID: "bitbucket-client-id", RuleID: "bitbucket-client-id",
Regex: generateSemiGenericRegex([]string{"bitbucket"}, alphaNumeric("32"), true), Regex: utils.GenerateSemiGenericRegex([]string{"bitbucket"}, utils.AlphaNumeric("32"), true),
Keywords: []string{"bitbucket"}, Keywords: []string{"bitbucket"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("bitbucket", secrets.NewSecret(alphaNumeric("32"))), utils.GenerateSampleSecret("bitbucket", secrets.NewSecret(utils.AlphaNumeric("32"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func BitBucketClientSecret() *config.Rule { func BitBucketClientSecret() *config.Rule {
@@ -26,14 +27,14 @@ func BitBucketClientSecret() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Discovered a potential Bitbucket Client Secret, posing a risk of compromised code repositories and unauthorized access.", Description: "Discovered a potential Bitbucket Client Secret, posing a risk of compromised code repositories and unauthorized access.",
RuleID: "bitbucket-client-secret", RuleID: "bitbucket-client-secret",
Regex: generateSemiGenericRegex([]string{"bitbucket"}, alphaNumericExtended("64"), true), Regex: utils.GenerateSemiGenericRegex([]string{"bitbucket"}, utils.AlphaNumericExtended("64"), true),
Keywords: []string{"bitbucket"}, Keywords: []string{"bitbucket"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("bitbucket", secrets.NewSecret(alphaNumeric("64"))), utils.GenerateSampleSecret("bitbucket", secrets.NewSecret(utils.AlphaNumeric("64"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+7 -6
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,15 +11,15 @@ func BittrexAccessKey() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Identified a Bittrex Access Key, which could lead to unauthorized access to cryptocurrency trading accounts and financial loss.", Description: "Identified a Bittrex Access Key, which could lead to unauthorized access to cryptocurrency trading accounts and financial loss.",
RuleID: "bittrex-access-key", RuleID: "bittrex-access-key",
Regex: generateSemiGenericRegex([]string{"bittrex"}, alphaNumeric("32"), true), Regex: utils.GenerateSemiGenericRegex([]string{"bittrex"}, utils.AlphaNumeric("32"), true),
Keywords: []string{"bittrex"}, Keywords: []string{"bittrex"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("bittrex", secrets.NewSecret(alphaNumeric("32"))), utils.GenerateSampleSecret("bittrex", secrets.NewSecret(utils.AlphaNumeric("32"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func BittrexSecretKey() *config.Rule { func BittrexSecretKey() *config.Rule {
@@ -26,14 +27,14 @@ func BittrexSecretKey() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Detected a Bittrex Secret Key, potentially compromising cryptocurrency transactions and financial security.", Description: "Detected a Bittrex Secret Key, potentially compromising cryptocurrency transactions and financial security.",
RuleID: "bittrex-secret-key", RuleID: "bittrex-secret-key",
Regex: generateSemiGenericRegex([]string{"bittrex"}, alphaNumeric("32"), true), Regex: utils.GenerateSemiGenericRegex([]string{"bittrex"}, utils.AlphaNumeric("32"), true),
Keywords: []string{"bittrex"}, Keywords: []string{"bittrex"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("bittrex", secrets.NewSecret(alphaNumeric("32"))), utils.GenerateSampleSecret("bittrex", secrets.NewSecret(utils.AlphaNumeric("32"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
@@ -12,13 +13,13 @@ func Clojars() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Uncovered a possible Clojars API token, risking unauthorized access to Clojure libraries and potential code manipulation.", 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",
Regex: regexp.MustCompile(`(?i)(CLOJARS_)[a-z0-9]{60}`), Regex: regexp.MustCompile(`(?i)CLOJARS_[a-z0-9]{60}`),
Keywords: []string{"clojars"}, Keywords: []string{"clojars"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("clojars", "CLOJARS_"+secrets.NewSecret(alphaNumeric("60"))), utils.GenerateSampleSecret("clojars", "CLOJARS_"+secrets.NewSecret(utils.AlphaNumeric("60"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+7 -6
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -28,7 +29,7 @@ func CloudflareGlobalAPIKey() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Detected a Cloudflare Global API Key, potentially compromising cloud application deployments and operational security.", 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",
Regex: generateSemiGenericRegex(identifiers, hex("37"), true), Regex: utils.GenerateSemiGenericRegex(identifiers, utils.Hex("37"), true),
Keywords: identifiers, Keywords: identifiers,
} }
@@ -37,7 +38,7 @@ func CloudflareGlobalAPIKey() *config.Rule {
tps := global_keys tps := global_keys
fps := append(api_keys, origin_ca_keys...) fps := append(api_keys, origin_ca_keys...)
return validate(r, tps, fps) return utils.Validate(r, tps, fps)
} }
func CloudflareAPIKey() *config.Rule { func CloudflareAPIKey() *config.Rule {
@@ -45,7 +46,7 @@ func CloudflareAPIKey() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Detected a Cloudflare API Key, potentially compromising cloud application deployments and operational security.", Description: "Detected a Cloudflare API Key, potentially compromising cloud application deployments and operational security.",
RuleID: "cloudflare-api-key", RuleID: "cloudflare-api-key",
Regex: generateSemiGenericRegex(identifiers, alphaNumericExtendedShort("40"), true), Regex: utils.GenerateSemiGenericRegex(identifiers, utils.AlphaNumericExtendedShort("40"), true),
Keywords: identifiers, Keywords: identifiers,
} }
@@ -54,7 +55,7 @@ func CloudflareAPIKey() *config.Rule {
tps := api_keys tps := api_keys
fps := append(global_keys, origin_ca_keys...) fps := append(global_keys, origin_ca_keys...)
return validate(r, tps, fps) return utils.Validate(r, tps, fps)
} }
func CloudflareOriginCAKey() *config.Rule { func CloudflareOriginCAKey() *config.Rule {
@@ -63,7 +64,7 @@ func CloudflareOriginCAKey() *config.Rule {
r := config.Rule{ r := 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: generateUniqueTokenRegex(`v1\.0-`+hex("24")+"-"+hex("146"), false), Regex: utils.GenerateUniqueTokenRegex(`v1\.0-`+utils.Hex("24")+"-"+utils.Hex("146"), false),
Keywords: ca_identifiers, Keywords: ca_identifiers,
} }
@@ -72,5 +73,5 @@ func CloudflareOriginCAKey() *config.Rule {
tps := origin_ca_keys tps := origin_ca_keys
fps := append(global_keys, api_keys...) fps := append(global_keys, api_keys...)
return validate(r, tps, fps) return utils.Validate(r, tps, fps)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func CodecovAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "codecov-access-token", RuleID: "codecov-access-token",
Description: "Found a pattern resembling a Codecov Access Token, posing a risk of unauthorized access to code coverage reports and sensitive data.", Description: "Found a pattern resembling a Codecov Access Token, posing a risk of unauthorized access to code coverage reports and sensitive data.",
Regex: generateSemiGenericRegex([]string{"codecov"}, alphaNumeric("32"), true), Regex: utils.GenerateSemiGenericRegex([]string{"codecov"}, utils.AlphaNumeric("32"), true),
Keywords: []string{ Keywords: []string{
"codecov", "codecov",
}, },
@@ -18,7 +19,7 @@ func CodecovAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("codecov", secrets.NewSecret(alphaNumeric("32"))), utils.GenerateSampleSecret("codecov", secrets.NewSecret(utils.AlphaNumeric("32"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+6 -5
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,8 +11,8 @@ func CoinbaseAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "coinbase-access-token", RuleID: "coinbase-access-token",
Description: "Detected a Coinbase Access Token, posing a risk of unauthorized access to cryptocurrency accounts and financial transactions.", Description: "Detected a Coinbase Access Token, posing a risk of unauthorized access to cryptocurrency accounts and financial transactions.",
Regex: generateSemiGenericRegex([]string{"coinbase"}, Regex: utils.GenerateSemiGenericRegex([]string{"coinbase"},
alphaNumericExtendedShort("64"), true), utils.AlphaNumericExtendedShort("64"), true),
Keywords: []string{ Keywords: []string{
"coinbase", "coinbase",
}, },
@@ -19,8 +20,8 @@ func CoinbaseAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("coinbase", utils.GenerateSampleSecret("coinbase",
secrets.NewSecret(alphaNumericExtendedShort("64"))), secrets.NewSecret(utils.AlphaNumericExtendedShort("64"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+6 -4
View File
@@ -1,5 +1,5 @@
# This file has been auto-generated. Do not edit manually. # This file has been auto-generated. Do not edit manually.
# If you would like to contribute new rules, please use # If you would like to contribute new rules, please use
# cmd/generate/config/main.go and follow the contributing guidelines # cmd/generate/config/main.go and follow the contributing guidelines
# at https://github.com/zricethezav/gitleaks/blob/master/CONTRIBUTING.md # at https://github.com/zricethezav/gitleaks/blob/master/CONTRIBUTING.md
@@ -14,13 +14,15 @@ title = "gitleaks config"
description = "global allow lists" description = "global allow lists"
paths = [ paths = [
'''gitleaks.toml''', '''gitleaks.toml''',
'''(.*?)(jpg|gif|doc|docx|zip|xls|pdf|bin|svg|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe)$''', '''(.*?)(jpg|gif|doc|docx|zip|xls|pdf|bin|svg|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe|gltf)$''',
'''(go.mod|go.sum)$''', '''(go.mod|go.sum|go.work|go.work.sum)$''',
'''gradle.lockfile''', '''gradle.lockfile''',
'''verification-metadata.xml''',
'''node_modules''', '''node_modules''',
'''package-lock.json''', '''package-lock.json''',
'''yarn.lock''', '''yarn.lock''',
'''pnpm-lock.yaml''', '''pnpm-lock.yaml''',
'''poetry.lock''',
'''Database.refactorlog''', '''Database.refactorlog''',
'''vendor''', '''vendor''',
] ]
@@ -49,7 +51,7 @@ tags = [
regexTarget = "{{ . }}"{{ end -}} regexTarget = "{{ . }}"{{ end -}}
{{- with $rule.Allowlist.Regexes }} {{- with $rule.Allowlist.Regexes }}
regexes = [ regexes = [
{{ range $j, $regex := . }}"{{ $regex }}",{{ end }} {{ range $j, $regex := . }}'''{{ $regex }}''',{{ end }}
]{{ end }} ]{{ end }}
{{- with $rule.Allowlist.Paths }}paths = [ {{- with $rule.Allowlist.Paths }}paths = [
{{ range $j, $path := . }}"{{ $path }}",{{ end }} {{ range $j, $path := . }}"{{ $path }}",{{ end }}
+7 -6
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func ConfluentSecretKey() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "confluent-secret-key", RuleID: "confluent-secret-key",
Description: "Found a Confluent Secret Key, potentially risking unauthorized operations and data access within Confluent services.", Description: "Found a Confluent Secret Key, potentially risking unauthorized operations and data access within Confluent services.",
Regex: generateSemiGenericRegex([]string{"confluent"}, alphaNumeric("64"), true), Regex: utils.GenerateSemiGenericRegex([]string{"confluent"}, utils.AlphaNumeric("64"), true),
Keywords: []string{ Keywords: []string{
"confluent", "confluent",
}, },
@@ -18,9 +19,9 @@ func ConfluentSecretKey() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("confluent", secrets.NewSecret(alphaNumeric("64"))), utils.GenerateSampleSecret("confluent", secrets.NewSecret(utils.AlphaNumeric("64"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func ConfluentAccessToken() *config.Rule { func ConfluentAccessToken() *config.Rule {
@@ -28,7 +29,7 @@ func ConfluentAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "confluent-access-token", RuleID: "confluent-access-token",
Description: "Identified a Confluent Access Token, which could compromise access to streaming data platforms and sensitive data flow.", Description: "Identified a Confluent Access Token, which could compromise access to streaming data platforms and sensitive data flow.",
Regex: generateSemiGenericRegex([]string{"confluent"}, alphaNumeric("16"), true), Regex: utils.GenerateSemiGenericRegex([]string{"confluent"}, utils.AlphaNumeric("16"), true),
Keywords: []string{ Keywords: []string{
"confluent", "confluent",
@@ -37,7 +38,7 @@ func ConfluentAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("confluent", secrets.NewSecret(alphaNumeric("16"))), utils.GenerateSampleSecret("confluent", secrets.NewSecret(utils.AlphaNumeric("16"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+5 -4
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,14 +11,14 @@ func Contentful() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Discovered a Contentful delivery API token, posing a risk to content management systems and data integrity.", Description: "Discovered a Contentful delivery API token, posing a risk to content management systems and data integrity.",
RuleID: "contentful-delivery-api-token", RuleID: "contentful-delivery-api-token",
Regex: generateSemiGenericRegex([]string{"contentful"}, Regex: utils.GenerateSemiGenericRegex([]string{"contentful"},
alphaNumericExtended("43"), true), utils.AlphaNumericExtended("43"), true),
Keywords: []string{"contentful"}, Keywords: []string{"contentful"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("contentful", secrets.NewSecret(alphaNumeric("43"))), utils.GenerateSampleSecret("contentful", secrets.NewSecret(utils.AlphaNumeric("43"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,13 +11,13 @@ func Databricks() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Uncovered a Databricks API token, which may compromise big data analytics platforms and sensitive data processing.", 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: generateUniqueTokenRegex(`dapi[a-h0-9]{32}`, true), Regex: utils.GenerateUniqueTokenRegex(`dapi[a-h0-9]{32}`, true),
Keywords: []string{"dapi"}, Keywords: []string{"dapi"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("databricks", "dapi"+secrets.NewSecret(hex("32"))), utils.GenerateSampleSecret("databricks", "dapi"+secrets.NewSecret(utils.Hex("32"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+5 -4
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,8 +11,8 @@ func DatadogtokenAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "datadog-access-token", RuleID: "datadog-access-token",
Description: "Detected a Datadog Access Token, potentially risking monitoring and analytics data exposure and manipulation.", Description: "Detected a Datadog Access Token, potentially risking monitoring and analytics data exposure and manipulation.",
Regex: generateSemiGenericRegex([]string{"datadog"}, Regex: utils.GenerateSemiGenericRegex([]string{"datadog"},
alphaNumeric("40"), true), utils.AlphaNumeric("40"), true),
Keywords: []string{ Keywords: []string{
"datadog", "datadog",
}, },
@@ -19,7 +20,7 @@ func DatadogtokenAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("datadog", secrets.NewSecret(alphaNumeric("40"))), utils.GenerateSampleSecret("datadog", secrets.NewSecret(utils.AlphaNumeric("40"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -15,7 +16,7 @@ func DefinedNetworkingAPIToken() *config.Rule {
RuleID: "defined-networking-api-token", RuleID: "defined-networking-api-token",
// Regex used for detecting secrets. See regex section below for more details // Regex used for detecting secrets. See regex section below for more details
Regex: generateSemiGenericRegex([]string{"dnkey"}, `dnkey-[a-z0-9=_\-]{26}-[a-z0-9=_\-]{52}`, true), Regex: utils.GenerateSemiGenericRegex([]string{"dnkey"}, `dnkey-[a-z0-9=_\-]{26}-[a-z0-9=_\-]{52}`, true),
// Keywords used for string matching on fragments (think of this as a prefilter) // Keywords used for string matching on fragments (think of this as a prefilter)
Keywords: []string{"dnkey"}, Keywords: []string{"dnkey"},
@@ -23,7 +24,7 @@ func DefinedNetworkingAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("dnkey", "dnkey-"+secrets.NewSecret(alphaNumericExtended("26"))+"-"+secrets.NewSecret(alphaNumericExtended("52"))), utils.GenerateSampleSecret("dnkey", "dnkey-"+secrets.NewSecret(utils.AlphaNumericExtended("26"))+"-"+secrets.NewSecret(utils.AlphaNumericExtended("52"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+10 -9
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -9,14 +10,14 @@ 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.", Description: "Discovered a DigitalOcean Personal Access Token, posing a threat to cloud infrastructure security and data privacy.",
RuleID: "digitalocean-pat", RuleID: "digitalocean-pat",
Regex: generateUniqueTokenRegex(`dop_v1_[a-f0-9]{64}`, true), Regex: utils.GenerateUniqueTokenRegex(`dop_v1_[a-f0-9]{64}`, true),
Keywords: []string{"dop_v1_"}, Keywords: []string{"dop_v1_"},
} }
tps := []string{ tps := []string{
generateSampleSecret("do", "dop_v1_"+secrets.NewSecret(hex("64"))), utils.GenerateSampleSecret("do", "dop_v1_"+secrets.NewSecret(utils.Hex("64"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func DigitalOceanOAuthToken() *config.Rule { func DigitalOceanOAuthToken() *config.Rule {
@@ -24,14 +25,14 @@ func DigitalOceanOAuthToken() *config.Rule {
Description: "Found a DigitalOcean OAuth Access Token, risking unauthorized cloud resource access and data compromise.", Description: "Found a DigitalOcean OAuth Access Token, risking unauthorized cloud resource access and data compromise.",
RuleID: "digitalocean-access-token", RuleID: "digitalocean-access-token",
Regex: generateUniqueTokenRegex(`doo_v1_[a-f0-9]{64}`, true), Regex: utils.GenerateUniqueTokenRegex(`doo_v1_[a-f0-9]{64}`, true),
Keywords: []string{"doo_v1_"}, Keywords: []string{"doo_v1_"},
} }
tps := []string{ tps := []string{
generateSampleSecret("do", "doo_v1_"+secrets.NewSecret(hex("64"))), utils.GenerateSampleSecret("do", "doo_v1_"+secrets.NewSecret(utils.Hex("64"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func DigitalOceanRefreshToken() *config.Rule { func DigitalOceanRefreshToken() *config.Rule {
@@ -39,12 +40,12 @@ func DigitalOceanRefreshToken() *config.Rule {
Description: "Uncovered a DigitalOcean OAuth Refresh Token, which could allow prolonged unauthorized access and resource manipulation.", Description: "Uncovered a DigitalOcean OAuth Refresh Token, which could allow prolonged unauthorized access and resource manipulation.",
RuleID: "digitalocean-refresh-token", RuleID: "digitalocean-refresh-token",
Regex: generateUniqueTokenRegex(`dor_v1_[a-f0-9]{64}`, true), Regex: utils.GenerateUniqueTokenRegex(`dor_v1_[a-f0-9]{64}`, true),
Keywords: []string{"dor_v1_"}, Keywords: []string{"dor_v1_"},
} }
tps := []string{ tps := []string{
generateSampleSecret("do", "dor_v1_"+secrets.NewSecret(hex("64"))), utils.GenerateSampleSecret("do", "dor_v1_"+secrets.NewSecret(utils.Hex("64"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+10 -9
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,15 +11,15 @@ func DiscordAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Detected a Discord API key, potentially compromising communication channels and user data privacy on Discord.", Description: "Detected a Discord API key, potentially compromising communication channels and user data privacy on Discord.",
RuleID: "discord-api-token", RuleID: "discord-api-token",
Regex: generateSemiGenericRegex([]string{"discord"}, hex("64"), true), Regex: utils.GenerateSemiGenericRegex([]string{"discord"}, utils.Hex("64"), true),
Keywords: []string{"discord"}, Keywords: []string{"discord"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("discord", secrets.NewSecret(hex("64"))), utils.GenerateSampleSecret("discord", secrets.NewSecret(utils.Hex("64"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func DiscordClientID() *config.Rule { func DiscordClientID() *config.Rule {
@@ -26,15 +27,15 @@ func DiscordClientID() *config.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.", 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",
Regex: generateSemiGenericRegex([]string{"discord"}, numeric("18"), true), Regex: utils.GenerateSemiGenericRegex([]string{"discord"}, utils.Numeric("18"), true),
Keywords: []string{"discord"}, Keywords: []string{"discord"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("discord", secrets.NewSecret(numeric("18"))), utils.GenerateSampleSecret("discord", secrets.NewSecret(utils.Numeric("18"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func DiscordClientSecret() *config.Rule { func DiscordClientSecret() *config.Rule {
@@ -42,13 +43,13 @@ func DiscordClientSecret() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Discovered a potential Discord client secret, risking compromised Discord bot integrations and data leaks.", Description: "Discovered a potential Discord client secret, risking compromised Discord bot integrations and data leaks.",
RuleID: "discord-client-secret", RuleID: "discord-client-secret",
Regex: generateSemiGenericRegex([]string{"discord"}, alphaNumericExtended("32"), true), Regex: utils.GenerateSemiGenericRegex([]string{"discord"}, utils.AlphaNumericExtended("32"), true),
Keywords: []string{"discord"}, Keywords: []string{"discord"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("discord", secrets.NewSecret(numeric("32"))), utils.GenerateSampleSecret("discord", secrets.NewSecret(utils.Numeric("32"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
@@ -12,15 +13,15 @@ func Doppler() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Discovered a Doppler API token, posing a risk to environment and secrets management security.", Description: "Discovered a Doppler API token, posing a risk to environment and secrets management security.",
RuleID: "doppler-api-token", RuleID: "doppler-api-token",
Regex: regexp.MustCompile(`(dp\.pt\.)(?i)[a-z0-9]{43}`), Regex: regexp.MustCompile(`dp\.pt\.(?i)[a-z0-9]{43}`),
Keywords: []string{"doppler"}, Keywords: []string{"doppler"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("doppler", "dp.pt."+secrets.NewSecret(alphaNumeric("43"))), utils.GenerateSampleSecret("doppler", "dp.pt."+secrets.NewSecret(utils.AlphaNumeric("43"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
// TODO add additional doppler formats: // TODO add additional doppler formats:
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func DroneciAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "droneci-access-token", RuleID: "droneci-access-token",
Description: "Detected a Droneci Access Token, potentially compromising continuous integration and deployment workflows.", Description: "Detected a Droneci Access Token, potentially compromising continuous integration and deployment workflows.",
Regex: generateSemiGenericRegex([]string{"droneci"}, alphaNumeric("32"), true), Regex: utils.GenerateSemiGenericRegex([]string{"droneci"}, utils.AlphaNumeric("32"), true),
Keywords: []string{ Keywords: []string{
"droneci", "droneci",
@@ -19,7 +20,7 @@ func DroneciAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("droneci", secrets.NewSecret(alphaNumeric("32"))), utils.GenerateSampleSecret("droneci", secrets.NewSecret(utils.AlphaNumeric("32"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+6 -5
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,16 +11,16 @@ func DropBoxAPISecret() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Identified a Dropbox API secret, which could lead to unauthorized file access and data breaches in Dropbox storage.", Description: "Identified a Dropbox API secret, which could lead to unauthorized file access and data breaches in Dropbox storage.",
RuleID: "dropbox-api-token", RuleID: "dropbox-api-token",
Regex: generateSemiGenericRegex([]string{"dropbox"}, alphaNumeric("15"), true), Regex: utils.GenerateSemiGenericRegex([]string{"dropbox"}, utils.AlphaNumeric("15"), true),
Keywords: []string{"dropbox"}, Keywords: []string{"dropbox"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("dropbox", secrets.NewSecret(alphaNumeric("15"))), utils.GenerateSampleSecret("dropbox", secrets.NewSecret(utils.AlphaNumeric("15"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func DropBoxShortLivedAPIToken() *config.Rule { func DropBoxShortLivedAPIToken() *config.Rule {
@@ -27,7 +28,7 @@ func DropBoxShortLivedAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "dropbox-short-lived-api-token", RuleID: "dropbox-short-lived-api-token",
Description: "Discovered a Dropbox short-lived API token, posing a risk of temporary but potentially harmful data access and manipulation.", Description: "Discovered a Dropbox short-lived API token, posing a risk of temporary but potentially harmful data access and manipulation.",
Regex: generateSemiGenericRegex([]string{"dropbox"}, `sl\.[a-z0-9\-=_]{135}`, true), Regex: utils.GenerateSemiGenericRegex([]string{"dropbox"}, `sl\.[a-z0-9\-=_]{135}`, true),
Keywords: []string{"dropbox"}, Keywords: []string{"dropbox"},
} }
@@ -40,7 +41,7 @@ func DropBoxLongLivedAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "dropbox-long-lived-api-token", RuleID: "dropbox-long-lived-api-token",
Description: "Found a Dropbox long-lived API token, risking prolonged unauthorized access to cloud storage and sensitive data.", Description: "Found a Dropbox long-lived API token, risking prolonged unauthorized access to cloud storage and sensitive data.",
Regex: generateSemiGenericRegex([]string{"dropbox"}, `[a-z0-9]{11}(AAAAAAAAAA)[a-z0-9\-_=]{43}`, true), Regex: utils.GenerateSemiGenericRegex([]string{"dropbox"}, `[a-z0-9]{11}(AAAAAAAAAA)[a-z0-9\-_=]{43}`, true),
Keywords: []string{"dropbox"}, Keywords: []string{"dropbox"},
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
@@ -12,13 +13,13 @@ func Duffel() *config.Rule {
r := config.Rule{ r := 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"}, Keywords: []string{"duffel"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("duffel", "duffel_test_"+secrets.NewSecret(alphaNumericExtended("43"))), utils.GenerateSampleSecret("duffel", "duffel_test_"+secrets.NewSecret(utils.AlphaNumericExtended("43"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+3 -2
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
@@ -18,7 +19,7 @@ func Dynatrace() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("dynatrace", "dt0c01."+secrets.NewSecret(alphaNumeric("24"))+"."+secrets.NewSecret(alphaNumeric("64"))), utils.GenerateSampleSecret("dynatrace", "dt0c01."+secrets.NewSecret(utils.AlphaNumeric("24"))+"."+secrets.NewSecret(utils.AlphaNumeric("64"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+5 -4
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
@@ -18,9 +19,9 @@ func EasyPost() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("EZAK", "EZAK"+secrets.NewSecret(alphaNumeric("54"))), utils.GenerateSampleSecret("EZAK", "EZAK"+secrets.NewSecret(utils.AlphaNumeric("54"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func EasyPostTestAPI() *config.Rule { func EasyPostTestAPI() *config.Rule {
@@ -34,7 +35,7 @@ func EasyPostTestAPI() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("EZTK", "EZTK"+secrets.NewSecret(alphaNumeric("54"))), utils.GenerateSampleSecret("EZTK", "EZTK"+secrets.NewSecret(utils.AlphaNumeric("54"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+14 -4
View File
@@ -1,6 +1,8 @@
package rules package rules
import ( import (
"fmt"
"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"
) )
@@ -10,8 +12,8 @@ func EtsyAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "etsy-access-token", RuleID: "etsy-access-token",
Description: "Found an Etsy Access Token, potentially compromising Etsy shop management and customer data.", Description: "Found an Etsy Access Token, potentially compromising Etsy shop management and customer data.",
Regex: generateSemiGenericRegex([]string{"etsy"}, alphaNumeric("24"), true), Regex: utils.GenerateSemiGenericRegex([]string{"(?-i:ETSY|[Ee]tsy)"}, utils.AlphaNumeric("24"), true),
Entropy: 3,
Keywords: []string{ Keywords: []string{
"etsy", "etsy",
}, },
@@ -19,7 +21,15 @@ func EtsyAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("etsy", secrets.NewSecret(alphaNumeric("24"))), utils.GenerateSampleSecret("ETSY", secrets.NewSecret(utils.AlphaNumeric("24"))),
utils.GenerateSampleSecret("etsy", secrets.NewSecret(utils.AlphaNumeric("24"))),
utils.GenerateSampleSecret("Etsy", secrets.NewSecret(utils.AlphaNumeric("24"))),
} }
return validate(r, tps, nil) fps := []string{
fmt.Sprintf(`SetSysctl = "%s"`, secrets.NewSecret(utils.AlphaNumeric("24"))),
` if err := sysctl.SetSysctl(sysctlBridgeCallIPTables); err != nil {`,
`g6Rib2R5hqhkZXRhY2hlZMOpaGFzaF90eXBlCqNrZXnEIwEgETSYcPQGcaAxl8vuQDLahSfhxkEEHu2flbF9ErAooEoKp3BheWxvYWTFAwB7ImJvZHkiOnsia2V5Ijp7ImVsZGVzdF9raWQiOiIwMTIwMTEzNDk4NzBmNDA2NzFhMDMxOTdjYmVlNDAzMmRhODUyN2UxYzY0MTA0MWVlZDlmOTViMTdkMTJiMDI4YTA0YTBhIiwiaG9zdCI6ImtleWJhc2UuaW8iLCJraWQiOiIwMTIwMTEzNDk4NzBmNDA2NzFhMDMxOTdjYmVlNDAzMmRhODUyN2UxYzY0MTA0MWVlZDlmOTViMTdkMTJiMDI4YTA0YTBhIiwidWlkIjoiYzUyZjc2M2MxNzYyNWZiMTI5YWU1ZDZmZThhMGUzMTkiLCJ1c2VybmFtZSI6ImttYXJla3NwYXJ0eiJ9LCJzZXJ2aWNlIjp7Imhvc3RuYW1lIjoia3lsZS5tYXJlay1zcGFydHoub3JnIiwicHJvdG9jb2wiOiJodHRwOiJ9LCJ0eXBlIjoid2ViX3NlcnZpY2VfYmluZGluZyIsInZlcnNpb24iOjF9LCJjbGllbnQiOnsibmFtZSI6ImtleWJhc2UuaW8gZ28gY2xpZW50IiwidmVyc2lvbiI6IjEuMC4xNCJ9LCJjdGltZSI6MTQ1ODU5MDYyMSwiZXhwaXJlX2luIjo1MDQ1NzYwMDAsIm1lcmtsZV9yb290Ijp7ImN0aW1lIjoxNDU4NTkwNTgzLCJoYXNoIjoiODQ0ZWRkNGU0OTQ3MWUzNWQxZTFkOTM5YTc0ZjUwMDc5Nzg3NzljMTAwYzY1NGE2OGI1NDNhYzY2Y2NlYTQ1MGFjNTllNmY3Yjc4ZGZiN2MyYzdjMmYwMzJiYTA2MzdjMzVjZDk1ZGYyZmRiNjFlNjgxMjVmNDkxNjVlZDkwNzMiLCJzZXFubyI6NDE3Mjk5fSwicHJldiI6IjdmNWFkMGZlZmQxNjM4ZjBlOTc1MTk3NzA5YTk2OTVkZmQ1NzU0MTA4NTYxZGUzMDM0ODc2NDcxODdhMDkyYzUiLCJzZXFubyI6OSwidGFnIjoic2lnbmF0dXJlIn2jc2lnxEDDVCB/SdOzo+BznIUCCa5DgISbH+0noUjyAJ4r0sH/tj8lYNpHw3WR93SBCufeElsl7KrxVdg5qU5ADYj26wgOqHNpZ190eXBlIKN0YWfNAgKndmVyc2lvbgE=`,
`in XCBuild.XCBBuildServiceSession.setSystemInfo(operatingSystemVersion: __C.NSOperatingSystemVersion, productBuildVersion: Swift.String, nativeArchitecture: Swift.String, completion: (Swift.Bool) -> ()) -> ()`,
}
return utils.Validate(r, tps, fps)
} }
+8 -7
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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,18 +13,18 @@ func FacebookSecret() *config.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.", 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",
Regex: generateSemiGenericRegex([]string{"facebook"}, hex("32"), true), Regex: utils.GenerateSemiGenericRegex([]string{"facebook"}, utils.Hex("32"), true),
Keywords: []string{"facebook"}, Keywords: []string{"facebook"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("facebook", secrets.NewSecret(hex("32"))), utils.GenerateSampleSecret("facebook", secrets.NewSecret(utils.Hex("32"))),
`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 validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
// https://developers.facebook.com/docs/facebook-login/guides/access-tokens/#apptokens // https://developers.facebook.com/docs/facebook-login/guides/access-tokens/#apptokens
@@ -32,7 +33,7 @@ func FacebookAccessToken() *config.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.", 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",
Regex: generateUniqueTokenRegex(`\d{15,16}(\||%)[0-9a-z\-_]{27,40}`, true), Regex: utils.GenerateUniqueTokenRegex(`\d{15,16}(\||%)[0-9a-z\-_]{27,40}`, true),
} }
// validate // validate
@@ -41,7 +42,7 @@ func FacebookAccessToken() *config.Rule {
`1308742762612587|rhoK1cbv0DOU_RTX_87O4MkX7AI`, // gitleaks:allow `1308742762612587|rhoK1cbv0DOU_RTX_87O4MkX7AI`, // gitleaks:allow
`1477036645700765|wRPf2v3mt2JfMqCLK8n7oltrEmc`, // gitleaks:allow `1477036645700765|wRPf2v3mt2JfMqCLK8n7oltrEmc`, // gitleaks:allow
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
// https://developers.facebook.com/docs/facebook-login/guides/access-tokens/#pagetokens // https://developers.facebook.com/docs/facebook-login/guides/access-tokens/#pagetokens
@@ -50,7 +51,7 @@ func FacebookPageAccessToken() *config.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.", 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: generateUniqueTokenRegex("EAA[MC]"+alphaNumeric("20,"), true), Regex: utils.GenerateUniqueTokenRegex("EAA[MC]"+utils.AlphaNumeric("20,"), true),
Keywords: []string{"EAAM", "EAAC"}, Keywords: []string{"EAAM", "EAAC"},
} }
@@ -61,5 +62,5 @@ func FacebookPageAccessToken() *config.Rule {
`- name: FACEBOOK_TOKEN `- name: FACEBOOK_TOKEN
value: "EAACEdEose0cBA1bad3afsf2aew"`, // gitleaks:allow value: "EAACEdEose0cBA1bad3afsf2aew"`, // gitleaks:allow
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,14 +11,14 @@ func FastlyAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Uncovered a Fastly API key, which may compromise CDN and edge cloud services, leading to content delivery and security issues.", Description: "Uncovered a Fastly API key, which may compromise CDN and edge cloud services, leading to content delivery and security issues.",
RuleID: "fastly-api-token", RuleID: "fastly-api-token",
Regex: generateSemiGenericRegex([]string{"fastly"}, alphaNumericExtended("32"), true), Regex: utils.GenerateSemiGenericRegex([]string{"fastly"}, utils.AlphaNumericExtended("32"), true),
Keywords: []string{"fastly"}, Keywords: []string{"fastly"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("fastly", secrets.NewSecret(alphaNumericExtended("32"))), utils.GenerateSampleSecret("fastly", secrets.NewSecret(utils.AlphaNumericExtended("32"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+7 -6
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,16 +11,16 @@ func FinicityClientSecret() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Identified a Finicity Client Secret, which could lead to compromised financial service integrations and data breaches.", Description: "Identified a Finicity Client Secret, which could lead to compromised financial service integrations and data breaches.",
RuleID: "finicity-client-secret", RuleID: "finicity-client-secret",
Regex: generateSemiGenericRegex([]string{"finicity"}, alphaNumeric("20"), true), Regex: utils.GenerateSemiGenericRegex([]string{"finicity"}, utils.AlphaNumeric("20"), true),
Keywords: []string{"finicity"}, Keywords: []string{"finicity"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("finicity", secrets.NewSecret(alphaNumeric("20"))), utils.GenerateSampleSecret("finicity", secrets.NewSecret(utils.AlphaNumeric("20"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func FinicityAPIToken() *config.Rule { func FinicityAPIToken() *config.Rule {
@@ -27,14 +28,14 @@ func FinicityAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Detected a Finicity API token, potentially risking financial data access and unauthorized financial operations.", Description: "Detected a Finicity API token, potentially risking financial data access and unauthorized financial operations.",
RuleID: "finicity-api-token", RuleID: "finicity-api-token",
Regex: generateSemiGenericRegex([]string{"finicity"}, hex("32"), true), Regex: utils.GenerateSemiGenericRegex([]string{"finicity"}, utils.Hex("32"), true),
Keywords: []string{"finicity"}, Keywords: []string{"finicity"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("finicity", secrets.NewSecret(hex("32"))), utils.GenerateSampleSecret("finicity", secrets.NewSecret(utils.Hex("32"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func FinnhubAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "finnhub-access-token", RuleID: "finnhub-access-token",
Description: "Found a Finnhub Access Token, risking unauthorized access to financial market data and analytics.", Description: "Found a Finnhub Access Token, risking unauthorized access to financial market data and analytics.",
Regex: generateSemiGenericRegex([]string{"finnhub"}, alphaNumeric("20"), true), Regex: utils.GenerateSemiGenericRegex([]string{"finnhub"}, utils.AlphaNumeric("20"), true),
Keywords: []string{ Keywords: []string{
"finnhub", "finnhub",
@@ -19,7 +20,7 @@ func FinnhubAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("finnhub", secrets.NewSecret(alphaNumeric("20"))), utils.GenerateSampleSecret("finnhub", secrets.NewSecret(utils.AlphaNumeric("20"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func FlickrAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "flickr-access-token", RuleID: "flickr-access-token",
Description: "Discovered a Flickr Access Token, posing a risk of unauthorized photo management and potential data leakage.", Description: "Discovered a Flickr Access Token, posing a risk of unauthorized photo management and potential data leakage.",
Regex: generateSemiGenericRegex([]string{"flickr"}, alphaNumeric("32"), true), Regex: utils.GenerateSemiGenericRegex([]string{"flickr"}, utils.AlphaNumeric("32"), true),
Keywords: []string{ Keywords: []string{
"flickr", "flickr",
@@ -19,7 +20,7 @@ func FlickrAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("flickr", secrets.NewSecret(alphaNumeric("32"))), utils.GenerateSampleSecret("flickr", secrets.NewSecret(utils.AlphaNumeric("32"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+7 -6
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
@@ -18,9 +19,9 @@ func FlutterwavePublicKey() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("flutterwavePubKey", "FLWPUBK_TEST-"+secrets.NewSecret(hex("32"))+"-X"), utils.GenerateSampleSecret("flutterwavePubKey", "FLWPUBK_TEST-"+secrets.NewSecret(utils.Hex("32"))+"-X"),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func FlutterwaveSecretKey() *config.Rule { func FlutterwaveSecretKey() *config.Rule {
@@ -34,9 +35,9 @@ func FlutterwaveSecretKey() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("flutterwavePubKey", "FLWSECK_TEST-"+secrets.NewSecret(hex("32"))+"-X"), utils.GenerateSampleSecret("flutterwavePubKey", "FLWSECK_TEST-"+secrets.NewSecret(utils.Hex("32"))+"-X"),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func FlutterwaveEncKey() *config.Rule { func FlutterwaveEncKey() *config.Rule {
@@ -50,7 +51,7 @@ func FlutterwaveEncKey() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("flutterwavePubKey", "FLWSECK_TEST-"+secrets.NewSecret(hex("12"))), utils.GenerateSampleSecret("flutterwavePubKey", "FLWSECK_TEST-"+secrets.NewSecret(utils.Hex("12"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+54
View File
@@ -0,0 +1,54 @@
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"
)
// https://fly.io/docs/security/tokens/
// https://github.com/trufflesecurity/trufflehog/pull/2381/files#r1565860579
// https://github.com/superfly/macaroon-elixir/blob/8b42043b0a24aada5c8b8eb8505dbf1590557f1b/test/vectors.json#L7
func FlyIOAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "flyio-access-token",
Description: "Uncovered a Fly.io API key", // TODO
Regex: utils.GenerateUniqueTokenRegex(`(?:fo1_[\w-]{43}|fm1[ar]_[a-zA-Z0-9+\/]{100,}={0,3}|fm2_[a-zA-Z0-9+\/]{100,}={0,3})`, false),
Entropy: 4,
Keywords: []string{"fo1_", "fm1", "fm2_"},
}
// validate
tps := []string{
// fo1_
utils.GenerateSampleSecret("fly", secrets.NewSecret(`fo1_[\w-]{43}`)),
`Fly access token: fo1_8rz-j7r2eqJ2U7affEOO3HJN0j63DInyog3eV-glQSc
`,
`=============================================================================================================
fo1_BtKlzvfztw0M2hlLgTdsfPgDFiwM2jJjQXXy6I2pjuQ
fly deploy`,
// fm1
utils.GenerateSampleSecret("fly", secrets.NewSecret(`fm1[ar]_[a-zA-Z0-9+\/]{100,}={0,3}`)),
`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}`)),
`# 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",`,
}
fps := []string{
// fo1_
`resource "doppler_integration_flyio" "prod" {
name = "TF Fly.io"
api_key = "fo1_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}`, // https://github.com/DopplerHQ/terraform-provider-doppler/blob/a012e1a7903cce391be511b391850b29ebfdeb68/docs/resources/integration_flyio.md?plain=1#L17
`pub const MINIDUMP_SYSMEMINFO1_PERF_CCTOTALDIRTYPAGES_CCDIRTYPAGETHRESHOLD: u32 = 4u32;`, // https://github.com/microsoft/windows-rs/blob/0f7466c34e774e547d21c579b58b60168c4ee6bc/crates/libs/sys/src/Windows/Win32/System/Diagnostics/Debug/mod.rs#L1258
`<input type="hidden" name="authenticity_token" value="7SWa-Fo1_hsC6oovfBsJFLGPUl2EhkSWPbJhWANwgaJWBDl1vxd9VNqXTNAefsJqzIRYaZEfYZLffa31rw8zJA" autocomplete="off" />`,
// fm1
`signature":"I7l2ZXhw9ajjIE2w9tjHNvYjcHg7E2qldMMhoQKjborcWIj8c40rMj83venoy6gXsg6V6B7dlBWxUmzYJR3lJKGECtCSM5BqBvWhL6wX2CN2lZlvwNCyPjG4PCt5MAK1yV1Xv4fqfz8EfT_U49vOzfM1a_nfhXOzrvdg9XgLkAotWBI31vPKjMBrvPqiLcZ12MDNTSK7ubRpVaehSNxiGYHpLhWTkun9qm_APYYXJBjhJYkej50Qcp7Ou8fs3kH02prYIJt4JbWelr5vUDkgMH3AwEx1eYu5NI_8sESlqosl1nhSDx7zq3X1FV1iJlAYCNwGWzW1tjo8PCaJrIHVZZnhBPMN-6ahmOpKb8GViqd4fCQuNe4VUSOeJg8i97kMuk-4r7hwIubR0XfCGzxr7uGDQBdFANi3c4dLlzBAJNifa6b_hT4Xzqja6RCFSv6Cnalyx3hbSkjbyThnXFavJIiR7cvgTcdECg9VxkaxqqRhfAkLAS3hpXQAIYL_bw61M3LN37WHwdgxN_6yZhbSbOsYPmTxiWvdlDaCP_iaCgXgJNfdQ6kep_I89slynE9gdDZ6NSjFJH2Soml4pR6HnQKPjA3OpoTwPSmZjxXY5I78xvrRqRkjdnVzeufqG8LyA-sAEtC0G_312JOxV4GZINquPGk1qFx8WN59Rxw28Tg",`,
// fm2
`<p><span class="emoji">🗣️</span> Adobe illustrator软件基础精讲课程<br><br><span class="emoji">🏷️</span> <a href="https://t.me/abskoop/8565?q=%23%E8%AE%BE%E8%AE%A1%E5%B8%88">#设计师</a> <a href="https://t.me/abskoop/8565?q=%23%E8%B5%84%E6%BA%90">#资源</a> <a href="https://t.me/abskoop/8565?q=%23%E5%A4%B8%E5%85%8B%E7%BD%91%E7%9B%98">#夸克网盘</a><br><br><span class="emoji">👉</span> <a href="https://www.ahhhhfs.com/62409/" target="_blank" rel="noopener">https://www.ahhhhfs.com/62409/</a></p><img src="https://cdn5.cdn-telegram.org/file/uGoDMy0VXMbL1nki9OT0VbJYtfURvDNLurptsQVuhuzF45tNfm2_z5wgR7CnL7lTZ4bbotjXZtiLWvolNQqWBRFWkcidtzSyhWvta9yPB3E2uyvfJvGpditkaLVIiCCXt9BhFBEdgkXa8ODaM7geHK3pW0tmO_IViHBnG8VZqVfDpaQW0W9IRAUwGv2mPZWVRysPJyDSIuY9b-_3ElUml-Xlpm1r8EDcm9Q2WCTCOYur7Gmef4imQ5D-DLTviqmoONgQDLA10WVS3CApXBK4ADSjoIUeMck62owtjElSXnEYMaSGI_OE3B21QplsspPbPlXVUBScLfLOFb9tn-34tw.jpg" width="800" height="533" referrerpolicy="no-referrer">`,
}
return utils.Validate(r, tps, fps)
}
+3 -2
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
@@ -18,7 +19,7 @@ func FrameIO() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("frameio", "fio-u-"+secrets.NewSecret(alphaNumericExtended("64"))), utils.GenerateSampleSecret("frameio", "fio-u-"+secrets.NewSecret(utils.AlphaNumericExtended("64"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func FreshbooksAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "freshbooks-access-token", RuleID: "freshbooks-access-token",
Description: "Discovered a Freshbooks Access Token, posing a risk to accounting software access and sensitive financial data exposure.", Description: "Discovered a Freshbooks Access Token, posing a risk to accounting software access and sensitive financial data exposure.",
Regex: generateSemiGenericRegex([]string{"freshbooks"}, alphaNumeric("64"), true), Regex: utils.GenerateSemiGenericRegex([]string{"freshbooks"}, utils.AlphaNumeric("64"), true),
Keywords: []string{ Keywords: []string{
"freshbooks", "freshbooks",
@@ -19,7 +20,7 @@ func FreshbooksAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("freshbooks", secrets.NewSecret(alphaNumeric("64"))), utils.GenerateSampleSecret("freshbooks", secrets.NewSecret(utils.AlphaNumeric("64"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+14 -5
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
@@ -21,7 +22,7 @@ func GCPServiceAccount() *config.Rule {
tps := []string{ tps := []string{
`"type": "service_account"`, `"type": "service_account"`,
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func GCPAPIKey() *config.Rule { func GCPAPIKey() *config.Rule {
@@ -29,8 +30,8 @@ func GCPAPIKey() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "gcp-api-key", RuleID: "gcp-api-key",
Description: "Uncovered a GCP API key, which could lead to unauthorized access to Google Cloud services and data breaches.", Description: "Uncovered a GCP API key, which could lead to unauthorized access to Google Cloud services and data breaches.",
Regex: generateUniqueTokenRegex(`AIza[0-9A-Za-z\\-_]{35}`, true), Regex: utils.GenerateUniqueTokenRegex(`AIza[\w-]{35}`, false),
Entropy: 3.0,
Keywords: []string{ Keywords: []string{
"AIza", "AIza",
}, },
@@ -38,7 +39,15 @@ func GCPAPIKey() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("gcp", secrets.NewSecret(`AIza[0-9A-Za-z\\-_]{35}`)), utils.GenerateSampleSecret("gcp", secrets.NewSecret(`AIza[\w-]{35}`)),
// non-word character at end
`AIzaSyNHxIf32IQ1a1yjl3ZJIqKZqzLAK1XhDk-`, // gitleaks:allow
} }
return validate(r, tps, nil) fps := []string{
`GWw4hjABFzZCGiRpmlDyDdo87Jn9BN9THUA47muVRNunLxsa82tMAdvmrhOqNkRKiYMEAFbTJAIzaTesb6Tscfcni8vIpWZqNCXFDFslJtVSvFDq`, // text boundary start
`AIzaTesb6Tscfcni8vIpWZqNCXFDFslJtVSvFDqabcd123`, // text boundary end
`apiKey: "AIzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"`, // not enough entropy
`AIZASYCO2CXRMC9ELSKLHLHRMBSWDEVEDZTLO2O`, // incorrect case
}
return utils.Validate(r, tps, fps)
} }
+5 -4
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -9,7 +10,7 @@ func GenericCredential() *config.Rule {
r := config.Rule{ r := 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: generateSemiGenericRegex([]string{ Regex: utils.GenerateSemiGenericRegex([]string{
"key", "key",
"api", "api",
"token", "token",
@@ -39,8 +40,8 @@ func GenericCredential() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("generic", "CLOJARS_34bf0e88955ff5a1c328d6a7491acc4f48e865a7b8dd4d70a70749037443"), utils.GenerateSampleSecret("generic", "CLOJARS_34bf0e88955ff5a1c328d6a7491acc4f48e865a7b8dd4d70a70749037443"), //gitleaks:allow
generateSampleSecret("generic", "Zf3D0LXCM3EIMbgJpUNnkRtOfOueHznB"), utils.GenerateSampleSecret("generic", "Zf3D0LXCM3EIMbgJpUNnkRtOfOueHznB"),
`"client_id" : "0afae57f3ccfd9d7f5767067bc48b30f719e271ba470488056e37ab35d4b6506"`, `"client_id" : "0afae57f3ccfd9d7f5767067bc48b30f719e271ba470488056e37ab35d4b6506"`,
`"client_secret" : "6da89121079f83b2eb6acccf8219ea982c3d79bccc3e9c6a85856480661f8fde",`, `"client_secret" : "6da89121079f83b2eb6acccf8219ea982c3d79bccc3e9c6a85856480661f8fde",`,
} }
@@ -50,5 +51,5 @@ func GenericCredential() *config.Rule {
R5: Regulatory--21`, R5: Regulatory--21`,
} }
return validate(r, tps, fps) return utils.Validate(r, tps, fps)
} }
+35 -13
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
@@ -13,14 +14,18 @@ func GitHubPat() *config.Rule {
Description: "Uncovered a GitHub Personal Access Token, potentially leading to unauthorized repository access and sensitive content exposure.", Description: "Uncovered a GitHub Personal Access Token, potentially leading to unauthorized repository access and sensitive content exposure.",
RuleID: "github-pat", RuleID: "github-pat",
Regex: regexp.MustCompile(`ghp_[0-9a-zA-Z]{36}`), Regex: regexp.MustCompile(`ghp_[0-9a-zA-Z]{36}`),
Entropy: 3,
Keywords: []string{"ghp_"}, Keywords: []string{"ghp_"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("github", "ghp_"+secrets.NewSecret(alphaNumeric("36"))), utils.GenerateSampleSecret("github", "ghp_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
} }
return validate(r, tps, nil) fps := []string{
"ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
}
return utils.Validate(r, tps, fps)
} }
func GitHubFineGrainedPat() *config.Rule { func GitHubFineGrainedPat() *config.Rule {
@@ -28,15 +33,19 @@ func GitHubFineGrainedPat() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Found a GitHub Fine-Grained Personal Access Token, risking unauthorized repository access and code manipulation.", 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",
Regex: regexp.MustCompile(`github_pat_[0-9a-zA-Z_]{82}`), Regex: regexp.MustCompile(`github_pat_\w{82}`),
Entropy: 3,
Keywords: []string{"github_pat_"}, Keywords: []string{"github_pat_"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("github", "github_pat_"+secrets.NewSecret(alphaNumeric("82"))), utils.GenerateSampleSecret("github", "github_pat_"+secrets.NewSecret(utils.AlphaNumeric("82"))),
} }
return validate(r, tps, nil) fps := []string{
"github_pat_xxxxxxxxxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
}
return utils.Validate(r, tps, fps)
} }
func GitHubOauth() *config.Rule { func GitHubOauth() *config.Rule {
@@ -45,14 +54,18 @@ func GitHubOauth() *config.Rule {
Description: "Discovered a GitHub OAuth Access Token, posing a risk of compromised GitHub account integrations and data leaks.", Description: "Discovered a GitHub OAuth Access Token, posing a risk of compromised GitHub account integrations and data leaks.",
RuleID: "github-oauth", RuleID: "github-oauth",
Regex: regexp.MustCompile(`gho_[0-9a-zA-Z]{36}`), Regex: regexp.MustCompile(`gho_[0-9a-zA-Z]{36}`),
Entropy: 3,
Keywords: []string{"gho_"}, Keywords: []string{"gho_"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("github", "gho_"+secrets.NewSecret(alphaNumeric("36"))), utils.GenerateSampleSecret("github", "gho_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
} }
return validate(r, tps, nil) fps := []string{
"gho_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
}
return utils.Validate(r, tps, fps)
} }
func GitHubApp() *config.Rule { func GitHubApp() *config.Rule {
@@ -60,16 +73,21 @@ func GitHubApp() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Identified a GitHub App Token, which may compromise GitHub application integrations and source code security.", Description: "Identified a GitHub App Token, which may compromise GitHub application integrations and source code security.",
RuleID: "github-app-token", RuleID: "github-app-token",
Regex: regexp.MustCompile(`(ghu|ghs)_[0-9a-zA-Z]{36}`), Regex: regexp.MustCompile(`(?:ghu|ghs)_[0-9a-zA-Z]{36}`),
Entropy: 3,
Keywords: []string{"ghu_", "ghs_"}, Keywords: []string{"ghu_", "ghs_"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("github", "ghu_"+secrets.NewSecret(alphaNumeric("36"))), utils.GenerateSampleSecret("github", "ghu_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
generateSampleSecret("github", "ghs_"+secrets.NewSecret(alphaNumeric("36"))), utils.GenerateSampleSecret("github", "ghs_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
} }
return validate(r, tps, nil) fps := []string{
"ghu_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"ghs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
}
return utils.Validate(r, tps, fps)
} }
func GitHubRefresh() *config.Rule { func GitHubRefresh() *config.Rule {
@@ -78,12 +96,16 @@ func GitHubRefresh() *config.Rule {
Description: "Detected a GitHub Refresh Token, which could allow prolonged unauthorized access to GitHub services.", Description: "Detected a GitHub Refresh Token, which could allow prolonged unauthorized access to GitHub services.",
RuleID: "github-refresh-token", RuleID: "github-refresh-token",
Regex: regexp.MustCompile(`ghr_[0-9a-zA-Z]{36}`), Regex: regexp.MustCompile(`ghr_[0-9a-zA-Z]{36}`),
Entropy: 3,
Keywords: []string{"ghr_"}, Keywords: []string{"ghr_"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("github", "ghr_"+secrets.NewSecret(alphaNumeric("36"))), utils.GenerateSampleSecret("github", "ghr_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
} }
return validate(r, tps, nil) fps := []string{
"ghr_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
}
return utils.Validate(r, tps, fps)
} }
+7 -6
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
@@ -18,9 +19,9 @@ func GitlabPat() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("gitlab", "glpat-"+secrets.NewSecret(alphaNumeric("20"))), utils.GenerateSampleSecret("gitlab", "glpat-"+secrets.NewSecret(utils.AlphaNumeric("20"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func GitlabPipelineTriggerToken() *config.Rule { func GitlabPipelineTriggerToken() *config.Rule {
@@ -34,9 +35,9 @@ func GitlabPipelineTriggerToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("gitlab", "glptt-"+secrets.NewSecret(hex("40"))), utils.GenerateSampleSecret("gitlab", "glptt-"+secrets.NewSecret(utils.Hex("40"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func GitlabRunnerRegistrationToken() *config.Rule { func GitlabRunnerRegistrationToken() *config.Rule {
@@ -50,7 +51,7 @@ func GitlabRunnerRegistrationToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("gitlab", "GR1348941"+secrets.NewSecret(alphaNumeric("20"))), utils.GenerateSampleSecret("gitlab", "GR1348941"+secrets.NewSecret(utils.AlphaNumeric("20"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+6 -5
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,8 +11,8 @@ func GitterAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "gitter-access-token", RuleID: "gitter-access-token",
Description: "Uncovered a Gitter Access Token, which may lead to unauthorized access to chat and communication services.", Description: "Uncovered a Gitter Access Token, which may lead to unauthorized access to chat and communication services.",
Regex: generateSemiGenericRegex([]string{"gitter"}, Regex: utils.GenerateSemiGenericRegex([]string{"gitter"},
alphaNumericExtendedShort("40"), true), utils.AlphaNumericExtendedShort("40"), true),
Keywords: []string{ Keywords: []string{
"gitter", "gitter",
@@ -20,8 +21,8 @@ func GitterAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("gitter", utils.GenerateSampleSecret("gitter",
secrets.NewSecret(alphaNumericExtendedShort("40"))), secrets.NewSecret(utils.AlphaNumericExtendedShort("40"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func GoCardless() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "gocardless-api-token", RuleID: "gocardless-api-token",
Description: "Detected a GoCardless API token, potentially risking unauthorized direct debit payment operations and financial data exposure.", Description: "Detected a GoCardless API token, potentially risking unauthorized direct debit payment operations and financial data exposure.",
Regex: generateSemiGenericRegex([]string{"gocardless"}, `live_(?i)[a-z0-9\-_=]{40}`, true), Regex: utils.GenerateSemiGenericRegex([]string{"gocardless"}, `live_(?i)[a-z0-9\-_=]{40}`, true),
Keywords: []string{ Keywords: []string{
"live_", "live_",
@@ -20,7 +21,7 @@ func GoCardless() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("gocardless", "live_"+secrets.NewSecret(alphaNumericExtended("40"))), utils.GenerateSampleSecret("gocardless", "live_"+secrets.NewSecret(utils.AlphaNumericExtended("40"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+14 -13
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -11,17 +12,17 @@ func GrafanaApiKey() *config.Rule {
Description: "Identified a Grafana API key, which could compromise monitoring dashboards and sensitive data analytics.", Description: "Identified a Grafana API key, which could compromise monitoring dashboards and sensitive data analytics.",
RuleID: "grafana-api-key", RuleID: "grafana-api-key",
Regex: generateUniqueTokenRegex(`eyJrIjoi[A-Za-z0-9]{70,400}={0,2}`, true), Regex: utils.GenerateUniqueTokenRegex(`eyJrIjoi[A-Za-z0-9]{70,400}={0,2}`, true),
Keywords: []string{"eyJrIjoi"}, Keywords: []string{"eyJrIjoi"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("grafana-api-key", utils.GenerateSampleSecret("grafana-api-key",
"eyJrIjoi"+ "eyJrIjoi"+
secrets.NewSecret(alphaNumeric("70"))), secrets.NewSecret(utils.AlphaNumeric("70"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func GrafanaCloudApiToken() *config.Rule { func GrafanaCloudApiToken() *config.Rule {
@@ -30,17 +31,17 @@ func GrafanaCloudApiToken() *config.Rule {
Description: "Found a Grafana cloud API token, risking unauthorized access to cloud-based monitoring services and data exposure.", 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",
Regex: generateUniqueTokenRegex(`glc_[A-Za-z0-9+/]{32,400}={0,2}`, true), Regex: utils.GenerateUniqueTokenRegex(`glc_[A-Za-z0-9+/]{32,400}={0,2}`, true),
Keywords: []string{"glc_"}, Keywords: []string{"glc_"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("grafana-cloud-api-token", utils.GenerateSampleSecret("grafana-cloud-api-token",
"glc_"+ "glc_"+
secrets.NewSecret(alphaNumeric("32"))), secrets.NewSecret(utils.AlphaNumeric("32"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func GrafanaServiceAccountToken() *config.Rule { func GrafanaServiceAccountToken() *config.Rule {
@@ -49,17 +50,17 @@ func GrafanaServiceAccountToken() *config.Rule {
Description: "Discovered a Grafana service account token, posing a risk of compromised monitoring services and data integrity.", 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",
Regex: 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_"}, Keywords: []string{"glsa_"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("grafana-service-account-token", utils.GenerateSampleSecret("grafana-service-account-token",
"glsa_"+ "glsa_"+
secrets.NewSecret(alphaNumeric("32"))+ secrets.NewSecret(utils.AlphaNumeric("32"))+
"_"+ "_"+
secrets.NewSecret((hex("8")))), secrets.NewSecret((utils.Hex("8")))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+29
View File
@@ -0,0 +1,29 @@
package rules
import (
"regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func HarnessApiKey() *config.Rule {
// Define rule for Harness Personal Access Token (PAT) and Service Account Token (SAT)
r := config.Rule{
Description: "Identified a Harness Access Token (PAT or SAT), risking unauthorized access to a Harness account.",
RuleID: "harness-api-key",
Regex: regexp.MustCompile(`(?:pat|sat)\.[a-zA-Z0-9_-]{22}\.[a-zA-Z0-9]{24}\.[a-zA-Z0-9]{20}`),
Keywords: []string{"pat.", "sat."},
}
// Generate a sample secret for validation
tps := []string{
utils.GenerateSampleSecret("harness", "pat."+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
return utils.Validate(r, tps, nil)
}
+21 -12
View File
@@ -2,26 +2,32 @@ package rules
import ( import (
"fmt" "fmt"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "regexp"
"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"
) )
func Hashicorp() *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.", 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",
Regex: regexp.MustCompile(`(?i)[a-z0-9]{14}\.atlasv1\.[a-z0-9\-_=]{60,70}`), Regex: regexp.MustCompile(`(?i)[a-z0-9]{14}\.(?-i:atlasv1)\.[a-z0-9\-_=]{60,70}`),
Entropy: 3.5,
Keywords: []string{"atlasv1"}, Keywords: []string{"atlasv1"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("hashicorpToken", secrets.NewSecret(hex("14"))+".atlasv1."+secrets.NewSecret(alphaNumericExtended("60,70"))), utils.GenerateSampleSecret("hashicorpToken", secrets.NewSecret(utils.Hex("14"))+".atlasv1."+secrets.NewSecret(utils.AlphaNumericExtended("60,70"))),
`#token = "hE1hlYILrSqpqh.atlasv1.ARjZuyzl33F71WR55s6ln5GQ1HWIwTDDH3MiRjz7OnpCfaCb1RCF5zGaSncCWmJdcYA"`,
} }
return validate(r, tps, nil) fps := []string{
`token = "xxxxxxxxxxxxxx.atlasv1.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"`, // low entropy
}
return utils.Validate(r, tps, fps)
} }
func HashicorpField() *config.Rule { func HashicorpField() *config.Rule {
@@ -30,19 +36,22 @@ func HashicorpField() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Identified a HashiCorp Terraform password field, risking unauthorized infrastructure configuration and security breaches.", Description: "Identified a HashiCorp Terraform password field, risking unauthorized infrastructure configuration and security breaches.",
RuleID: "hashicorp-tf-password", RuleID: "hashicorp-tf-password",
Regex: generateSemiGenericRegex(keywords, fmt.Sprintf(`"%s"`, alphaNumericExtended("8,20")), true), Regex: utils.GenerateSemiGenericRegex(keywords, fmt.Sprintf(`"%s"`, utils.AlphaNumericExtended("8,20")), true),
Keywords: keywords, Keywords: keywords,
Path: regexp.MustCompile(`(?i)\.(?:tf|hcl)$`),
} }
tps := []string{ tps := map[string]string{
// Example from: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/sql_server.html // Example from: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/sql_server.html
"administrator_login_password = " + `"thisIsDog11"`, "file.tf": "administrator_login_password = " + `"thisIsDog11"`,
// https://registry.terraform.io/providers/petoju/mysql/latest/docs // https://registry.terraform.io/providers/petoju/mysql/latest/docs
"password = " + `"rootpasswd"`, "file.hcl": "password = " + `"rootpasswd"`,
} }
fps := []string{ fps := map[string]string{
"administrator_login_password = var.db_password", "file.tf": "administrator_login_password = var.db_password",
`password = "${aws_db_instance.default.password}"`, "file.hcl": `password = "${aws_db_instance.default.password}"`,
"unrelated.js": "password = " + `"rootpasswd"`,
} }
return validate(r, tps, fps)
return utils.ValidateWithPaths(r, tps, fps)
} }
@@ -0,0 +1,64 @@
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"
"regexp"
)
func VaultServiceToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "vault-service-token",
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),
Entropy: 3.5,
Keywords: []string{"hvs", "s."},
Allowlist: config.Allowlist{
Regexes: []*regexp.Regexp{
// https://github.com/gitleaks/gitleaks/issues/1490#issuecomment-2334166357
regexp.MustCompile(`s\.[A-Za-z]{24}`),
},
},
}
// validate
tps := []string{
// Old
utils.GenerateSampleSecret("vault", "s."+secrets.NewSecret(utils.AlphaNumeric("24"))),
`token: s.ZC9Ecf4M5g9o34Q6RkzGsj0z`,
// New
utils.GenerateSampleSecret("vault", "hvs."+secrets.NewSecret(utils.AlphaNumericExtendedShort("90"))),
`-vaultToken hvs.CAESIP2jTxc9S2K7Z6CtcFWQv7-044m_oSsxnPE1H3nF89l3GiYKHGh2cy5sQmlIZVNyTWJNcDRsYWJpQjlhYjVlb1cQh6PL8wEYAg"`, // longer than 100 chars
}
fps := []string{
// Old
` credentials: new AWS.SharedIniFileCredentials({ profile: '<YOUR_PROFILE>' })`, // word boundary start
`INFO 4 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean`, // word boundary end
`s.xxxxxxxxxxxxxxxxxxxxxxxx`, // low entropy
`s.THISSTRINGISALLUPPERCASE`, // uppercase
`s.thisstringisalllowercase`, // lowercase
`s.AcceptanceTimeoutSeconds `, // pascal-case
`s.makeKubeConfigController = args`, // camel-case
// New
`hvs.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`, // low entropy
}
return utils.Validate(r, tps, fps)
}
func VaultBatchToken() *config.Rule {
// define rule
r := config.Rule{
Description: "Detected a Vault Batch Token, risking unauthorized access to secret management services and sensitive data.",
RuleID: "vault-batch-token",
Regex: utils.GenerateUniqueTokenRegex(`hvb\.[a-z0-9_-]{138,212}`, true),
Keywords: []string{"hvb"},
}
// validate
tps := []string{
utils.GenerateSampleSecret("vault", "hvb."+secrets.NewSecret(utils.AlphaNumericExtendedShort("138"))),
}
return utils.Validate(r, tps, nil)
}
+3 -2
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -9,7 +10,7 @@ func Heroku() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Detected a Heroku API Key, potentially compromising cloud application deployments and operational security.", Description: "Detected a Heroku API Key, potentially compromising cloud application deployments and operational security.",
RuleID: "heroku-api-key", RuleID: "heroku-api-key",
Regex: generateSemiGenericRegex([]string{"heroku"}, hex8_4_4_4_12(), true), Regex: utils.GenerateSemiGenericRegex([]string{"heroku"}, utils.Hex8_4_4_4_12(), true),
Keywords: []string{"heroku"}, Keywords: []string{"heroku"},
} }
@@ -19,5 +20,5 @@ func Heroku() *config.Rule {
`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 validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+3 -2
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -9,7 +10,7 @@ func HubSpot() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Found a HubSpot API Token, posing a risk to CRM data integrity and unauthorized marketing operations.", Description: "Found a HubSpot API Token, posing a risk to CRM data integrity and unauthorized marketing operations.",
RuleID: "hubspot-api-key", RuleID: "hubspot-api-key",
Regex: generateSemiGenericRegex([]string{"hubspot"}, Regex: utils.GenerateSemiGenericRegex([]string{"hubspot"},
`[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}`, true), `[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}`, true),
Keywords: []string{"hubspot"}, Keywords: []string{"hubspot"},
@@ -19,5 +20,5 @@ func HubSpot() *config.Rule {
tps := []string{ tps := []string{
`const hubspotKey = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow `const hubspotKey = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+3 -2
View File
@@ -2,6 +2,7 @@ package rules
import ( import (
"fmt" "fmt"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
@@ -63,7 +64,7 @@ func HuggingFaceAccessToken() *config.Rule {
`# HuggingFace API Token https://huggingface.co/settings/tokens `# HuggingFace API Token https://huggingface.co/settings/tokens
HUGGINGFACE_API_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,`, HUGGINGFACE_API_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,`,
} }
return validate(r, tps, fps) return utils.Validate(r, tps, fps)
} }
// Will be deprecated Aug 1st, 2023. // Will be deprecated Aug 1st, 2023.
@@ -111,5 +112,5 @@ func HuggingFaceOrganizationApiToken() *config.Rule {
You should see a token hf_xxxxx (old tokens are api_XXXXXXXX or api_org_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx). You should see a token hf_xxxxx (old tokens are api_XXXXXXXX or api_org_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx).
If you do not submit your API token when sending requests to the API, you will not be able to run inference on your private models.`, If you do not submit your API token when sending requests to the API, you will not be able to run inference on your private models.`,
} }
return validate(r, tps, fps) return utils.Validate(r, tps, fps)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -17,7 +18,7 @@ func InfracostAPIToken() *config.Rule {
// Regex capture group for the actual secret // Regex capture group for the actual secret
// Regex used for detecting secrets. See regex section below for more details // Regex used for detecting secrets. See regex section below for more details
Regex: generateUniqueTokenRegex(`ico-[a-zA-Z0-9]{32}`, true), Regex: utils.GenerateUniqueTokenRegex(`ico-[a-zA-Z0-9]{32}`, true),
// Keywords used for string matching on fragments (think of this as a prefilter) // Keywords used for string matching on fragments (think of this as a prefilter)
Keywords: []string{"ico-"}, Keywords: []string{"ico-"},
@@ -25,7 +26,7 @@ func InfracostAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("ico", "ico-"+secrets.NewSecret("[A-Za-z0-9]{32}")), utils.GenerateSampleSecret("ico", "ico-"+secrets.NewSecret("[A-Za-z0-9]{32}")),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,14 +11,14 @@ func Intercom() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Identified an Intercom API Token, which could compromise customer communication channels and data privacy.", Description: "Identified an Intercom API Token, which could compromise customer communication channels and data privacy.",
RuleID: "intercom-api-key", RuleID: "intercom-api-key",
Regex: generateSemiGenericRegex([]string{"intercom"}, alphaNumericExtended("60"), true), Regex: utils.GenerateSemiGenericRegex([]string{"intercom"}, utils.AlphaNumericExtended("60"), true),
Keywords: []string{"intercom"}, Keywords: []string{"intercom"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("intercom", secrets.NewSecret(alphaNumericExtended("60"))), utils.GenerateSampleSecret("intercom", secrets.NewSecret(utils.AlphaNumericExtended("60"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+30
View File
@@ -0,0 +1,30 @@
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 Intra42ClientSecret() *config.Rule {
// define rule
r := config.Rule{
Description: "Found a Intra42 client secret, which could lead to unauthorized access to the 42School API and sensitive data.",
RuleID: "intra42-client-secret",
Regex: utils.GenerateUniqueTokenRegex(`s-s4t2(?:ud|af)-[abcdef0123456789]{64}`, true),
Keywords: []string{
"intra",
"s-s4t2ud-",
"s-s4t2af-",
},
}
// validate
tps := []string{
"clientSecret := \"s-s4t2ud-" + secrets.NewSecret(utils.Hex("64")) + "\"",
"clientSecret := \"s-s4t2af-" + secrets.NewSecret(utils.Hex("64")) + "\"",
"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", // gitleaks:allow
"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", // gitleaks:allow
}
return utils.Validate(r, tps, nil)
}
+10 -9
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/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
@@ -21,16 +22,16 @@ func JFrogAPIKey() *config.Rule {
// Regex capture group for the actual secret // Regex capture group for the actual secret
// Regex used for detecting secrets. See regex section below for more details // Regex used for detecting secrets. See regex section below for more details
Regex: generateSemiGenericRegex(keywords, alphaNumeric("73"), true), Regex: utils.GenerateSemiGenericRegex(keywords, utils.AlphaNumeric("73"), true),
// Keywords used for string matching on fragments (think of this as a prefilter) // Keywords used for string matching on fragments (think of this as a prefilter)
Keywords: keywords, Keywords: keywords,
} }
// validate // validate
tps := []string{ tps := []string{
fmt.Sprintf("--set imagePullSecretJfrog.password=%s", secrets.NewSecret(alphaNumeric("73"))), fmt.Sprintf("--set imagePullSecretJfrog.password=%s", secrets.NewSecret(utils.AlphaNumeric("73"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func JFrogIdentityToken() *config.Rule { func JFrogIdentityToken() *config.Rule {
@@ -47,7 +48,7 @@ func JFrogIdentityToken() *config.Rule {
// Regex capture group for the actual secret // Regex capture group for the actual secret
// Regex used for detecting secrets. See regex section below for more details // Regex used for detecting secrets. See regex section below for more details
Regex: generateSemiGenericRegex(keywords, alphaNumeric("64"), true), Regex: utils.GenerateSemiGenericRegex(keywords, utils.AlphaNumeric("64"), true),
// Keywords used for string matching on fragments (think of this as a prefilter) // Keywords used for string matching on fragments (think of this as a prefilter)
Keywords: keywords, Keywords: keywords,
@@ -55,10 +56,10 @@ func JFrogIdentityToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("jfrog", secrets.NewSecret(alphaNumeric("64"))), utils.GenerateSampleSecret("jfrog", secrets.NewSecret(utils.AlphaNumeric("64"))),
generateSampleSecret("artifactory", secrets.NewSecret(alphaNumeric("64"))), utils.GenerateSampleSecret("artifactory", secrets.NewSecret(utils.AlphaNumeric("64"))),
generateSampleSecret("bintray", secrets.NewSecret(alphaNumeric("64"))), utils.GenerateSampleSecret("bintray", secrets.NewSecret(utils.AlphaNumeric("64"))),
generateSampleSecret("xray", secrets.NewSecret(alphaNumeric("64"))), utils.GenerateSampleSecret("xray", secrets.NewSecret(utils.AlphaNumeric("64"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -3,6 +3,7 @@ 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/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
@@ -13,7 +14,7 @@ func JWT() *config.Rule {
r := config.Rule{ r := 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: 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),
Keywords: []string{"ey"}, Keywords: []string{"ey"},
} }
@@ -61,7 +62,7 @@ func JWT() *config.Rule {
`# 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 validate(r, tps, fps) return utils.Validate(r, tps, fps)
} }
func JWTBase64() *config.Rule { func JWTBase64() *config.Rule {
@@ -109,7 +110,7 @@ vHVobJ8A
=mIC1 =mIC1
-----END PGP PUBLIC KEY BLOCK-----`, -----END PGP PUBLIC KEY BLOCK-----`,
} }
return validate(r, tps, fps) return utils.Validate(r, tps, fps)
} }
func generateTestValues() []string { func generateTestValues() []string {
+6 -5
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,8 +11,8 @@ func KrakenAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "kraken-access-token", RuleID: "kraken-access-token",
Description: "Identified a Kraken Access Token, potentially compromising cryptocurrency trading accounts and financial security.", Description: "Identified a Kraken Access Token, potentially compromising cryptocurrency trading accounts and financial security.",
Regex: generateSemiGenericRegex([]string{"kraken"}, Regex: utils.GenerateSemiGenericRegex([]string{"kraken"},
alphaNumericExtendedLong("80,90"), true), utils.AlphaNumericExtendedLong("80,90"), true),
Keywords: []string{ Keywords: []string{
"kraken", "kraken",
@@ -20,8 +21,8 @@ func KrakenAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("kraken", utils.GenerateSampleSecret("kraken",
secrets.NewSecret(alphaNumericExtendedLong("80,90"))), secrets.NewSecret(utils.AlphaNumericExtendedLong("80,90"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+413
View File
@@ -0,0 +1,413 @@
package rules
import (
"fmt"
"regexp"
"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!
func KubernetesSecret() *config.Rule {
// Only match basic variations of `kind: secret`, we don't want things like `kind: ExternalSecret`.
//language=regexp
kindPat := `\bkind:[ \t]*["']?secret["']?`
// Only matches values (`key: value`) under `data:` that are:
// - valid base64 characters
// - longer than 10 characters (no "YmFyCg==")
//language=regexp
dataPat := `\bdata:(?:.|\s){0,100}?\s+([\w.-]+:(?:[ \t]*(?:\||>[-+]?)\s+)?[ \t]*(?:["']?[a-z0-9]{10,}={0,3}["']?|\{\{[ \t\w"|$:=,.-]+}}|""|''))`
// define rule
r := config.Rule{
RuleID: "kubernetes-secret-yaml",
Description: "Possible Kubernetes Secret detected, posing a risk of leaking credentials/tokens from your deployments",
Regex: regexp.MustCompile(fmt.Sprintf(
//language=regexp
`(?i)(?:%s(?:.|\s){0,200}?%s|%s(?:.|\s){0,200}?%s)`, kindPat, dataPat, dataPat, kindPat)),
Keywords: []string{
"secret",
},
// Kubernetes secrets are usually yaml files.
Path: regexp.MustCompile(`(?i)\.ya?ml$`),
Allowlist: config.Allowlist{
Regexes: []*regexp.Regexp{
// Ignore empty or placeholder values.
// variable: {{ .Values.Example }} (https://helm.sh/docs/chart_template_guide/variables/)
// variable: ""
// variable: ''
regexp.MustCompile(`[\w.-]+:(?:[ \t]*(?:\||>[-+]?)\s+)?[ \t]*(?:\{\{[ \t\w"|$:=,.-]+}}|""|'')`),
},
},
}
// validate
tps := map[string]string{
"comment.yaml": `
apiVersion: v1
kind: Secret
metadata:
name: heketi-secret
namespace: default
data:
# base64 encoded password. E.g.: echo -n "mypassword" | base64
key: bXlwYXNzd29yZA==`,
// The "data"-key is before the identifier "kind: Secret"
"before-kubernetes.yaml": `apiVersion: v1
data:
extra: YWRtaW46cGFzc3dvcmQ=
kind: secret
metadata:
name: secret-sa-sample
annotations:
kubernetes.io/service-account.name: 'sa-name'`,
"before-kubernetes.yml": `apiVersion: v1
data:
password: UyFCXCpkJHpEc2I9
username: YWRtaW4=
kind: Secret
metadata:
creationTimestamp: '2022-06-28T17:44:13Z'
name: db-user-pass
namespace: default
type: Opaque`,
"before-comment.yml": `apiVersion: v1
data:
# the data is abbreviated in this example
password: UyFCXCpkJHpEc2I9
username: YWRtaW4=
kind: Secret
metadata:
creationTimestamp: '2022-06-28T17:44:13Z'
name: db-user-pass
namespace: default
type: Opaque`,
"before-quoted-1.yaml": `apiVersion: 'v1'
data:
extra: 'YWRtaW46cGFzc3dvcmQ='
kind: 'Secret'
metadata:
name: 'secret-sa-sample'
annotations:
kubernetes.io/service-account.name: 'sa-name'`,
"before-quoted-2.yaml": `apiVersion: "v1"
data:
extra: "YWRtaW46cGFzc3dvcmQ="
kind: "secret"
metadata:
name: "secret-sa-sample"
annotations:
kubernetes.io/service-account.name: "sa-name"`,
"before-multiline-literal.yaml": `apiVersion: v1
data:
.dockercfg: |
eyJhdXRocyI6eyJodHRwczovL2V4YW1wbGUvdjEvIjp7ImF1dGgiOiJvcGVuc2VzYW1lIn19fQo=
metadata:
name: secret-dockercfg
type: kubernetes.io/dockercfg
kind: Secret
`,
"before-multiline-folded.yaml": `apiVersion: v1
data:
.dockercfg: >
eyJhdXRocyI6eyJodHRwczovL2V4YW1wbGUvdjEvIjp7ImF1dGgiOiJvcGVuc2VzYW1lIn19fQo=
metadata:
name: secret-dockercfg
type: kubernetes.io/dockercfg
kind: Secret`,
// Sample Kubernetes Secret from https://kubernetes.io/docs/concepts/configuration/secret/
// The "data"-key is after the identifier "kind: Secret"
"after-kubernetes.yaml": `apiVersion: v1
kind: secret
data:
extra: YWRtaW46cGFzc3dvcmQ=
metadata:
name: secret-sa-sample
annotations:
kubernetes.io/service-account.name: 'sa-name'`,
"after-kubernetes.yml": `apiVersion: v1
kind: Secret
metadata:
name: ca-secret
type: Opaque
data:
ca.pem: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUR4RENDQXF5Z0F3SUJBZ0lVV3pqUDl5RUk0eHlRSnBzVHVERU4yV2ROaUFzd0RRWUpLb1pJaHZjTkFRRUwKQlFBd2FERUxNQWtHQTFVRUJoTUNWVk14RHpBTkJnTlZCQWdUQms5eVpXZHZiakVSTUE4R0ExVUVCeE1JVUc5eQpkR3hoYm1ReEV6QVJCZ05WQkFvVENrdDFZbVZ5Ym1WMFpYTXhDekFKQmdOVkJBc1RBa05CTVJNd0VRWURWUVFECkV3cExkV0psY201bGRHVnpNQjRYRFRFMk1EZ3hNVEUyTkRnd01Gb1hEVEl4TURneE1ERTJORGd3TUZvd2FERUwKTUFrR0ExVUVCaE1DVlZNeER6QU5CZ05WQkFnVEJrOXlaV2R2YmpFUk1BOEdBMVVFQnhNSVVHOXlkR3hoYm1ReApFekFSQmdOVkJBb1RDa3QxWW1WeWJtVjBaWE14Q3pBSkJnTlZCQXNUQWtOQk1STXdFUVlEVlFRREV3cExkV0psCmNtNWxkR1Z6TUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUF3QkhNOGN6anc0Q1cKK05wbklhV012RzZlcVhtelNZT20vbHdaNUhOMnVLck9xaTNHYUUyTjFKd2tzcGRmMXNOUGFZMHdPR2xkbURIZgoxSnlyTW8rUFdLVUVjWko1WGE4Vm02d2I0MlpjczN3MEp5dlEzWFJjaDQyMFJRWGRKayszcmMybWRvSVRkL0lmCnZjWms0N0RzQTMrQU5QSUlSTzdWRmZpS1JNRFpTUDR1OThnVjI2eW1zbjc0TzFVKzNVUHR1TEFTVTFLck9FTk4KR01FWG0ydTJpdmVvbTJrbjFlZTZuM1hCR1o2bU52cUNPdWUxRXdza0gvWkhoUVh1UDgyV1U5dVk0aGVORnoyQwpBNmR0Q0Q0c3Z6eHc3ZFQ2cVhsV0ZIWUYrc3VLVDhXNkczd3NkOWxzV0ZVY0ZWL0lwaTVobEVaTWprNFNoY3RqCjdpYnlrRURKM1FJREFRQUJvMll3WkRBT0JnTlZIUThCQWY4RUJBTUNBUVl3RWdZRFZSMFRBUUgvQkFnd0JnRUIKL3dJQkFqQWRCZ05WSFE0RUZnUVVOdnhRZ3o5ZTNXS2VscU1KTmZXNE1KUHYzc0V3SHdZRFZSMGpCQmd3Rm9BVQpOdnhRZ3o5ZTNXS2VscU1KTmZXNE1KUHYzc0V3RFFZSktvWklodmNOQVFFTEJRQURnZ0VCQUp1TUhYUms1TEVyCmxET1p4Mm9aRUNQZ29reXMzSGJsM05oempXd2pncXdxNVN6a011V3QrUnVkdnRTK0FUQjFtTjRjYTN0eSt2bWcKT09heTkvaDZoditmSE5jZHpYdWR5dFZYZW1KN3F4ZFoxd25DUUcwdnpqOWRZY0xFSGpJWi94dU1jNlY3dnJ4YwpSc0preGp5aE01UXBmRHd0eVZKeGpkUmVBZ0huSyswTkNieHdtQ3cyRGIvOXpudm9LWGk4TEQwbkQzOFQxY3R3CmhmdGxwTmRoZXFNRlpEZXBuTUYwY2g2cHo5TFV5Mkh1cnhrV2dkWVNjY2VNU0hPTzBMcG4xeVVBMWczOTJhUjUKWk81Zm5KMW95Vm1LVWFCeDJCMndsSVlUSXlES1ZiMnY1UXNHbnYvRHVTMDZhcmVLTmsvTGpHRTRlMXlHOHJkcwpacnZHMzNvUmtEbz0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
`,
"after-comment.yml": `apiVersion: v1
kind: Secret
metadata:
creationTimestamp: '2022-06-28T17:44:13Z'
name: db-user-pass
namespace: default
type: Opaque
data:
# the data is abbreviated in this example
password: UyFCXCpkJHpEc2I9
username: YWRtaW4=
`,
"after-quoted-1.yaml": `apiVersion: 'v1'
kind: 'Secret'
data:
password: 'UyFCXCpkJHpEc2I9'
username: 'YWRtaW4='
metadata:
name: 'db-user-pass'
namespace: 'default'
type: 'Opaque'`,
"after-quoted-2.yaml": `apiVersion: "v1"
kind: "Secret"
data:
password: "UyFCXCpkJHpEc2I9"
username: "YWRtaW4="
metadata:
name: "db-user-pass"
namespace: "default"
type: "Opaque"`,
"after-multiline-literal.yaml": `apiVersion: v1
kind: Secret
metadata:
name: secret-dockercfg
type: kubernetes.io/dockercfg
data:
.dockercfg: |
eyJhdXRocyI6eyJodHRwczovL2V4YW1wbGUvdjEvIjp7ImF1dGgiOiJvcGVuc2VzYW1lIn19fQo=
`,
"after-multiline-folded.yaml": `apiVersion: v1
kind: Secret
metadata:
name: secret-dockercfg
type: kubernetes.io/dockercfg
data:
.dockercfg: >
eyJhdXRocyI6eyJodHRwczovL2V4YW1wbGUvdjEvIjp7ImF1dGgiOiJvcGVuc2VzYW1lIn19fQo=`,
}
fps := map[string]string{
"empty-quotes1.yml": `apiVersion: v1
kind: Secret
metadata:
name: registry-auth-data
type: Opaque
data:
htpasswd: ''
`,
"empty-quotes2.yml": `apiVersion: v1
kind: Secret
metadata:
name: registry-auth-data
type: Opaque
data:
htpasswd: ""
`,
"overly-permissive1.yaml": `apiVersion: v1
kind: Secret
metadata:
name: registry-auth-data
type: Opaque
data:
htpasswd: {{ htpasswd }}
---
apiVersion: v1
kind: ReplicationController`,
"overly-permissive2.yaml": `apiVersion: v1
kind: Secret
metadata:
labels:
k8s-app: kubernetes-dashboard
addonmanager.kubernetes.io/mode: EnsureExists
name: kubernetes-dashboard-csrf
namespace: kubernetes-dashboard
type: Opaque
data:
csrf: ""
---
apiVersion: v1
kind: Secret
metadata:
labels:
k8s-app: kubernetes-dashboard
addonmanager.kubernetes.io/mode: EnsureExists
name: kubernetes-dashboard-key-holder
namespace: kubernetes-dashboard
type: Opaque
`,
"sopssecret.yaml": `apiVersion: isindir.github.com/v1alpha3
kind: SopsSecret
metadata:
name: app1-sopssecret
namespace: test
spec:
suspend: false
secretTemplates:
- name: ENC[AES256_GCM,data:W3PiZ6lD6bpfAdI=,iv:2qF98ZkchgfWF4tZo8fok6zY0ZLNRV3wFpl8n2iyC7I=,tag:FzoL+CZHkLEqfWKniRApBA==,type:str]
labels:
app: ENC[AES256_GCM,data:t9ujIQ==,iv:slZBpmKF+DOg/wVBWmq5iTqkRBZUMao0a3MdoxzJs3s=,tag:xJyhdJ4rn/cB/4mxHzmGig==,type:str]
stringData:
db-password: ENC[AES256_GCM,data:O+5l4g==,iv:c/dS4BCBMbnKsXYuzBuCuVQt8RV9bOv5HgdpL+iwmns=,tag:KkQfh6OymvCt4uC13p318g==,type:str]
sops:
kms: []
gcp_kms: []
azure_kv: []
hc_vault: []
lastmodified: '2021-10-21T10:56:37Z'
mac: ENC[AES256_GCM,data:Tl1V1PuI5tZ0Hu3qxxzpDNeKQkuW0g/x/Mlp1yM6HaBqDr+r2FukLdYSYqjjJ3A8g+YkpvMib50M7j0V7zoX9sgCvMKEg86pRsWtThv8n/L+bsjClVTqnhJ9nfYlaPOMlvggbiMOE5hXPIuVz8WXYoVYJ2cVNCd/GfwOraUmj7I=,iv:n7HVI13okfbW3FS/ZsJ2GNmibudxc/TlkLa3umQQ+vc=,tag:R4ikep1wlxlDWlODJqFHHw==,type:str]
pgp:
- created_at: '2021-10-21T10:56:37Z'
enc: |
-----BEGIN PGP MESSAGE-----
hQGMA3muqimBu2IIAQwAkhR19/6roLq06oaD12vqDMes3/8FweAHxa6TLKg+LRjp
2/ntiRJHPBP9DYYFZbkTo8lAmIdVF7KfGIqWgPm5JiNhqfVRhyGPCRgBE7+I8qH6
EML9Vo/76kJLHtIjs5rOg7OXgwwitaibs1q6uyVY8TuaGXYIOO1iwL9xVtbayIry
NMQd1tFcNb6Vb86Plqm+T1VnSOJMUvryxrLelx89UNM0ctepyVu6YY9jpBjV0QLJ
NqNkKAGIMv3RNa9bZHTwveo9T0oXtFnk5H33BxH0ky/DGpD+5Ch1YgbzbqVnr+Bm
RX0R/GRhS9IDInd+eiyVX6y3LR5di0fc8TuK43+96wTG+2+ck+lbMrkHYsL2UJNv
bAjlOWmIcL4UwGlEOj4EzwcEx+xP3dq57pJ+DasfNwVqps2Kk+ofodR7d6gx7ELH
UQmLypCtkRic9v8fVSA2vEL8hAlg9bT8tpHLhHMOwe228cL5dTzFD60RoP+ovRar
jIU59Pnu1bnM4pXWEVA20l4BzJ8Fd6gj3TfAg/7Mat+dnTaUwnPgRSybFn0ZZHMW
RJDBPkMGFfSGRDfLeD37d61mI31360/w/61LaVp1sdDYodBJCRZFA1YzbqZcxnDl
YRjRmpcVRnO+o72CnU/P
=V4l4
-----END PGP MESSAGE-----
fp: 73019E949C1D3C3D1BE8B718C7CD51A565AB592C
encrypted_suffix: Templates
version: 3.6.1`, // https://github.com/luca-iachini/argocd-test/blob/af0c8eaba270bc918108c8bc3b909f26a4fe995d/kustomize/base/app1/secrets.enc.yaml#L4
// The "data"-key is before the identifier "kind: Secret"
"before-min-length.yaml": `apiVersion: v1
data:
extra: YmFyCg==
kind: secret
metadata:
name: secret-sa-sample
annotations:
kubernetes.io/service-account.name: 'sa-name'`,
"before-template.yaml": `apiVersion: v1
data:
password: {{ .Values.Password }}
kind: secret
metadata:
name: secret-sa-sample
annotations:
kubernetes.io/service-account.name: 'sa-name'`,
"before-externalsecret1.yml": `apiVersion: 'kubernetes-client.io/v1'
metadata:
name: actions-exporter
namespace: github-actions-exporter
spec:
backendType: secretsManager
data:
- key: MySecretManagerKey
name: github_token
property: github_token
kind: ExternalSecret
`,
"before-externalsecret2.yml": `apiVersion: external-secrets.io/v1beta1
spec:
secretStoreRef:
kind: ClusterSecretStore
name: aws-secretsmanager
refreshInterval: 1h
target:
creationPolicy: Owner
data:
- secretKey: api-key
remoteRef:
key: my-secrets-manager-secret
metadata:
name: api-key
namespace: my-namespace
kind: ExternalSecret
`,
"before-sopssecret.yml": `apiVersion: isindir.github.com/v1alpha3
spec:
secretTemplates:
- name: my-secret-name-1
labels:
label1: value1
annotations:
key1: value1
data:
data-name1: ZGF0YS12YWx1ZTE=
data-nameM: ZGF0YS12YWx1ZU0=
kind: SopsSecret
metadata:
name: sopssecret-sample
`, // https://github.com/isindir/sops-secrets-operator/blob/8aaf8bb368dc841a2d57f251bd839f08216a9328/config/samples/isindir_v1alpha3_sopssecret.yaml#L4
// The "data"-key is after the identifier "kind: Secret"
"after-min-length.yaml": `apiVersion: v1
kind: secret
data:
extra: YmFyCg==
metadata:
name: secret-sa-sample
annotations:
kubernetes.io/service-account.name: 'sa-name'`,
"after-externalsecret1.yml": `apiVersion: 'kubernetes-client.io/v1'
kind: ExternalSecret
metadata:
name: actions-exporter
namespace: github-actions-exporter
spec:
backendType: secretsManager
data:
- key: MySecretManagerKey
name: github_token
property: github_token
- key: MySecretManagerKey`,
"after-externalsecret2.yml": `apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: api-key
namespace: my-namespace
spec:
secretStoreRef:
kind: ClusterSecretStore
name: aws-secretsmanager
refreshInterval: 1h
target:
creationPolicy: Owner
data:
- secretKey: api-key
remoteRef:
key: my-secrets-manager-secret`,
"after-sopssecret.yml": `apiVersion: isindir.github.com/v1alpha3
kind: SopsSecret
metadata:
name: sopssecret-sample
spec:
secretTemplates:
- name: my-secret-name-0
labels:
label0: value0
labelK: valueK
annotations:
key0: value0
keyN: valueN
stringData:
data-name0: data-value0
data-nameL: data-valueL
- name: my-secret-name-1
labels:
label1: value1
annotations:
key1: value1
data:
data-name1: ZGF0YS12YWx1ZTE=
data-nameM: ZGF0YS12YWx1ZU0=`,
"after-empty-data.yaml": `apiVersion: v1
kind: Secret
metadata:
labels:
k8s-app: kubernetes-dashboard
addonmanager.kubernetes.io/mode: EnsureExists
name: kubernetes-dashboard-csrf
namespace: kubernetes-dashboard
type: Opaque
data:
csrf: ""
`,
}
return utils.ValidateWithPaths(r, tps, fps)
}
+7 -6
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func KucoinAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "kucoin-access-token", RuleID: "kucoin-access-token",
Description: "Found a Kucoin Access Token, risking unauthorized access to cryptocurrency exchange services and transactions.", Description: "Found a Kucoin Access Token, risking unauthorized access to cryptocurrency exchange services and transactions.",
Regex: generateSemiGenericRegex([]string{"kucoin"}, hex("24"), true), Regex: utils.GenerateSemiGenericRegex([]string{"kucoin"}, utils.Hex("24"), true),
Keywords: []string{ Keywords: []string{
"kucoin", "kucoin",
@@ -19,9 +20,9 @@ func KucoinAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("kucoin", secrets.NewSecret(hex("24"))), utils.GenerateSampleSecret("kucoin", secrets.NewSecret(utils.Hex("24"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func KucoinSecretKey() *config.Rule { func KucoinSecretKey() *config.Rule {
@@ -29,7 +30,7 @@ func KucoinSecretKey() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "kucoin-secret-key", RuleID: "kucoin-secret-key",
Description: "Discovered a Kucoin Secret Key, which could lead to compromised cryptocurrency operations and financial data breaches.", Description: "Discovered a Kucoin Secret Key, which could lead to compromised cryptocurrency operations and financial data breaches.",
Regex: generateSemiGenericRegex([]string{"kucoin"}, hex8_4_4_4_12(), true), Regex: utils.GenerateSemiGenericRegex([]string{"kucoin"}, utils.Hex8_4_4_4_12(), true),
Keywords: []string{ Keywords: []string{
"kucoin", "kucoin",
@@ -38,7 +39,7 @@ func KucoinSecretKey() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("kucoin", secrets.NewSecret(hex8_4_4_4_12())), utils.GenerateSampleSecret("kucoin", secrets.NewSecret(utils.Hex8_4_4_4_12())),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func LaunchDarklyAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "launchdarkly-access-token", RuleID: "launchdarkly-access-token",
Description: "Uncovered a Launchdarkly Access Token, potentially compromising feature flag management and application functionality.", Description: "Uncovered a Launchdarkly Access Token, potentially compromising feature flag management and application functionality.",
Regex: generateSemiGenericRegex([]string{"launchdarkly"}, alphaNumericExtended("40"), true), Regex: utils.GenerateSemiGenericRegex([]string{"launchdarkly"}, utils.AlphaNumericExtended("40"), true),
Keywords: []string{ Keywords: []string{
"launchdarkly", "launchdarkly",
@@ -19,7 +20,7 @@ func LaunchDarklyAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("launchdarkly", secrets.NewSecret(alphaNumericExtended("40"))), utils.GenerateSampleSecret("launchdarkly", secrets.NewSecret(utils.AlphaNumericExtended("40"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+6 -5
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
@@ -18,9 +19,9 @@ func LinearAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("linear", "lin_api_"+secrets.NewSecret(alphaNumeric("40"))), utils.GenerateSampleSecret("linear", "lin_api_"+secrets.NewSecret(utils.AlphaNumeric("40"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func LinearClientSecret() *config.Rule { func LinearClientSecret() *config.Rule {
@@ -28,13 +29,13 @@ func LinearClientSecret() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Identified a Linear Client Secret, which may compromise secure integrations and sensitive project management data.", Description: "Identified a Linear Client Secret, which may compromise secure integrations and sensitive project management data.",
RuleID: "linear-client-secret", RuleID: "linear-client-secret",
Regex: generateSemiGenericRegex([]string{"linear"}, hex("32"), true), Regex: utils.GenerateSemiGenericRegex([]string{"linear"}, utils.Hex("32"), true),
Keywords: []string{"linear"}, Keywords: []string{"linear"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("linear", secrets.NewSecret(hex("32"))), utils.GenerateSampleSecret("linear", secrets.NewSecret(utils.Hex("32"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+9 -8
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,10 +11,10 @@ func LinkedinClientSecret() *config.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: generateSemiGenericRegex([]string{ Regex: utils.GenerateSemiGenericRegex([]string{
"linkedin", "linkedin",
"linked-in", "linked-in",
}, alphaNumeric("16"), true), }, utils.AlphaNumeric("16"), true),
Keywords: []string{ Keywords: []string{
"linkedin", "linkedin",
@@ -23,9 +24,9 @@ func LinkedinClientSecret() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("linkedin", secrets.NewSecret(alphaNumeric("16"))), utils.GenerateSampleSecret("linkedin", secrets.NewSecret(utils.AlphaNumeric("16"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func LinkedinClientID() *config.Rule { func LinkedinClientID() *config.Rule {
@@ -33,10 +34,10 @@ func LinkedinClientID() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "linkedin-client-id", RuleID: "linkedin-client-id",
Description: "Found a LinkedIn Client ID, risking unauthorized access to LinkedIn integrations and professional data exposure.", Description: "Found a LinkedIn Client ID, risking unauthorized access to LinkedIn integrations and professional data exposure.",
Regex: generateSemiGenericRegex([]string{ Regex: utils.GenerateSemiGenericRegex([]string{
"linkedin", "linkedin",
"linked-in", "linked-in",
}, alphaNumeric("14"), true), }, utils.AlphaNumeric("14"), true),
Keywords: []string{ Keywords: []string{
"linkedin", "linkedin",
@@ -46,7 +47,7 @@ func LinkedinClientID() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("linkedin", secrets.NewSecret(alphaNumeric("14"))), utils.GenerateSampleSecret("linkedin", secrets.NewSecret(utils.AlphaNumeric("14"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+7 -6
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func LobPubAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Detected a Lob Publishable API Key, posing a risk of exposing mail and print service integrations.", Description: "Detected a Lob Publishable API Key, posing a risk of exposing mail and print service integrations.",
RuleID: "lob-pub-api-key", RuleID: "lob-pub-api-key",
Regex: generateSemiGenericRegex([]string{"lob"}, `(test|live)_pub_[a-f0-9]{31}`, true), Regex: utils.GenerateSemiGenericRegex([]string{"lob"}, `(test|live)_pub_[a-f0-9]{31}`, true),
Keywords: []string{ Keywords: []string{
"test_pub", "test_pub",
@@ -21,9 +22,9 @@ func LobPubAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("lob", "test_pub_"+secrets.NewSecret(hex("31"))), utils.GenerateSampleSecret("lob", "test_pub_"+secrets.NewSecret(utils.Hex("31"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func LobAPIToken() *config.Rule { func LobAPIToken() *config.Rule {
@@ -31,7 +32,7 @@ func LobAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Uncovered a Lob API Key, which could lead to unauthorized access to mailing and address verification services.", Description: "Uncovered a Lob API Key, which could lead to unauthorized access to mailing and address verification services.",
RuleID: "lob-api-key", RuleID: "lob-api-key",
Regex: generateSemiGenericRegex([]string{"lob"}, `(live|test)_[a-f0-9]{35}`, true), Regex: utils.GenerateSemiGenericRegex([]string{"lob"}, `(live|test)_[a-f0-9]{35}`, true),
Keywords: []string{ Keywords: []string{
"test_", "test_",
"live_", "live_",
@@ -40,7 +41,7 @@ func LobAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("lob", "test_"+secrets.NewSecret(hex("35"))), utils.GenerateSampleSecret("lob", "test_"+secrets.NewSecret(utils.Hex("35"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func MailChimp() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "mailchimp-api-key", RuleID: "mailchimp-api-key",
Description: "Identified a Mailchimp API key, potentially compromising email marketing campaigns and subscriber data.", Description: "Identified a Mailchimp API key, potentially compromising email marketing campaigns and subscriber data.",
Regex: generateSemiGenericRegex([]string{"MailchimpSDK.initialize", "mailchimp"}, hex("32")+`-us\d\d`, true), Regex: utils.GenerateSemiGenericRegex([]string{"MailchimpSDK.initialize", "mailchimp"}, utils.Hex("32")+`-us\d\d`, true),
Keywords: []string{ Keywords: []string{
"mailchimp", "mailchimp",
@@ -19,7 +20,7 @@ func MailChimp() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("mailchimp", secrets.NewSecret(hex("32"))+"-us20"), utils.GenerateSampleSecret("mailchimp", secrets.NewSecret(utils.Hex("32"))+"-us20"),
`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
} }
@@ -27,5 +28,5 @@ func MailChimp() *config.Rule {
// False Negative // False Negative
`MailchimpSDK.initialize(token: 3012a5754bbd716926f99c028f7ea428-us18)`, // gitleaks:allow `MailchimpSDK.initialize(token: 3012a5754bbd716926f99c028f7ea428-us18)`, // gitleaks:allow
} }
return validate(r, tps, fps) return utils.Validate(r, tps, fps)
} }
+10 -9
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func MailGunPrivateAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "mailgun-private-api-token", RuleID: "mailgun-private-api-token",
Description: "Found a Mailgun private API token, risking unauthorized email service operations and data breaches.", Description: "Found a Mailgun private API token, risking unauthorized email service operations and data breaches.",
Regex: generateSemiGenericRegex([]string{"mailgun"}, `key-[a-f0-9]{32}`, true), Regex: utils.GenerateSemiGenericRegex([]string{"mailgun"}, `key-[a-f0-9]{32}`, true),
Keywords: []string{ Keywords: []string{
"mailgun", "mailgun",
@@ -19,9 +20,9 @@ func MailGunPrivateAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("mailgun", "key-"+secrets.NewSecret(hex("32"))), utils.GenerateSampleSecret("mailgun", "key-"+secrets.NewSecret(utils.Hex("32"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func MailGunPubAPIToken() *config.Rule { func MailGunPubAPIToken() *config.Rule {
@@ -29,7 +30,7 @@ func MailGunPubAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "mailgun-pub-key", RuleID: "mailgun-pub-key",
Description: "Discovered a Mailgun public validation key, which could expose email verification processes and associated data.", Description: "Discovered a Mailgun public validation key, which could expose email verification processes and associated data.",
Regex: generateSemiGenericRegex([]string{"mailgun"}, `pubkey-[a-f0-9]{32}`, true), Regex: utils.GenerateSemiGenericRegex([]string{"mailgun"}, `pubkey-[a-f0-9]{32}`, true),
Keywords: []string{ Keywords: []string{
"mailgun", "mailgun",
@@ -38,9 +39,9 @@ func MailGunPubAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("mailgun", "pubkey-"+secrets.NewSecret(hex("32"))), utils.GenerateSampleSecret("mailgun", "pubkey-"+secrets.NewSecret(utils.Hex("32"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func MailGunSigningKey() *config.Rule { func MailGunSigningKey() *config.Rule {
@@ -48,7 +49,7 @@ func MailGunSigningKey() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "mailgun-signing-key", RuleID: "mailgun-signing-key",
Description: "Uncovered a Mailgun webhook signing key, potentially compromising email automation and data integrity.", Description: "Uncovered a Mailgun webhook signing key, potentially compromising email automation and data integrity.",
Regex: generateSemiGenericRegex([]string{"mailgun"}, `[a-h0-9]{32}-[a-h0-9]{8}-[a-h0-9]{8}`, true), Regex: utils.GenerateSemiGenericRegex([]string{"mailgun"}, `[a-h0-9]{32}-[a-h0-9]{8}-[a-h0-9]{8}`, true),
Keywords: []string{ Keywords: []string{
"mailgun", "mailgun",
@@ -57,7 +58,7 @@ func MailGunSigningKey() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("mailgun", secrets.NewSecret(hex("32"))+"-00001111-22223333"), utils.GenerateSampleSecret("mailgun", secrets.NewSecret(utils.Hex("32"))+"-00001111-22223333"),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,14 +11,14 @@ func MapBox() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Detected a MapBox API token, posing a risk to geospatial services and sensitive location data exposure.", Description: "Detected a MapBox API token, posing a risk to geospatial services and sensitive location data exposure.",
RuleID: "mapbox-api-token", RuleID: "mapbox-api-token",
Regex: generateSemiGenericRegex([]string{"mapbox"}, `pk\.[a-z0-9]{60}\.[a-z0-9]{22}`, true), Regex: utils.GenerateSemiGenericRegex([]string{"mapbox"}, `pk\.[a-z0-9]{60}\.[a-z0-9]{22}`, true),
Keywords: []string{"mapbox"}, Keywords: []string{"mapbox"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("mapbox", "pk."+secrets.NewSecret(alphaNumeric("60"))+"."+secrets.NewSecret(alphaNumeric("22"))), utils.GenerateSampleSecret("mapbox", "pk."+secrets.NewSecret(utils.AlphaNumeric("60"))+"."+secrets.NewSecret(utils.AlphaNumeric("22"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func MattermostAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "mattermost-access-token", RuleID: "mattermost-access-token",
Description: "Identified a Mattermost Access Token, which may compromise team communication channels and data privacy.", Description: "Identified a Mattermost Access Token, which may compromise team communication channels and data privacy.",
Regex: generateSemiGenericRegex([]string{"mattermost"}, alphaNumeric("26"), true), Regex: utils.GenerateSemiGenericRegex([]string{"mattermost"}, utils.AlphaNumeric("26"), true),
Keywords: []string{ Keywords: []string{
"mattermost", "mattermost",
@@ -19,7 +20,7 @@ func MattermostAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("mattermost", secrets.NewSecret(alphaNumeric("26"))), utils.GenerateSampleSecret("mattermost", secrets.NewSecret(utils.AlphaNumeric("26"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+10 -9
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,11 +11,11 @@ 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: generateSemiGenericRegex([]string{ Regex: utils.GenerateSemiGenericRegex([]string{
"messagebird", "messagebird",
"message-bird", "message-bird",
"message_bird", "message_bird",
}, alphaNumeric("25"), true), }, utils.AlphaNumeric("25"), true),
Keywords: []string{ Keywords: []string{
"messagebird", "messagebird",
@@ -25,11 +26,11 @@ func MessageBirdAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("messagebird", secrets.NewSecret(alphaNumeric("25"))), utils.GenerateSampleSecret("messagebird", secrets.NewSecret(utils.AlphaNumeric("25"))),
generateSampleSecret("message-bird", secrets.NewSecret(alphaNumeric("25"))), utils.GenerateSampleSecret("message-bird", secrets.NewSecret(utils.AlphaNumeric("25"))),
generateSampleSecret("message_bird", secrets.NewSecret(alphaNumeric("25"))), utils.GenerateSampleSecret("message_bird", secrets.NewSecret(utils.AlphaNumeric("25"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func MessageBirdClientID() *config.Rule { func MessageBirdClientID() *config.Rule {
@@ -37,11 +38,11 @@ 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: generateSemiGenericRegex([]string{ Regex: utils.GenerateSemiGenericRegex([]string{
"messagebird", "messagebird",
"message-bird", "message-bird",
"message_bird", "message_bird",
}, hex8_4_4_4_12(), true), }, utils.Hex8_4_4_4_12(), true),
Keywords: []string{ Keywords: []string{
"messagebird", "messagebird",
@@ -54,5 +55,5 @@ func MessageBirdClientID() *config.Rule {
tps := []string{ tps := []string{
`const MessageBirdClientID = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow `const MessageBirdClientID = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+5 -4
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,8 +11,8 @@ func NetlifyAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "netlify-access-token", RuleID: "netlify-access-token",
Description: "Detected a Netlify Access Token, potentially compromising web hosting services and site management.", Description: "Detected a Netlify Access Token, potentially compromising web hosting services and site management.",
Regex: generateSemiGenericRegex([]string{"netlify"}, Regex: utils.GenerateSemiGenericRegex([]string{"netlify"},
alphaNumericExtended("40,46"), true), utils.AlphaNumericExtended("40,46"), true),
Keywords: []string{ Keywords: []string{
"netlify", "netlify",
@@ -20,7 +21,7 @@ func NetlifyAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("netlify", secrets.NewSecret(alphaNumericExtended("40,46"))), utils.GenerateSampleSecret("netlify", secrets.NewSecret(utils.AlphaNumericExtended("40,46"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+34 -10
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func NewRelicUserID() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "new-relic-user-api-key", RuleID: "new-relic-user-api-key",
Description: "Discovered a New Relic user API Key, which could lead to compromised application insights and performance monitoring.", Description: "Discovered a New Relic user API Key, which could lead to compromised application insights and performance monitoring.",
Regex: generateSemiGenericRegex([]string{ Regex: utils.GenerateSemiGenericRegex([]string{
"new-relic", "new-relic",
"newrelic", "newrelic",
"new_relic", "new_relic",
@@ -23,9 +24,9 @@ func NewRelicUserID() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("new-relic", "NRAK-"+secrets.NewSecret(alphaNumeric("27"))), utils.GenerateSampleSecret("new-relic", "NRAK-"+secrets.NewSecret(utils.AlphaNumeric("27"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func NewRelicUserKey() *config.Rule { func NewRelicUserKey() *config.Rule {
@@ -33,11 +34,11 @@ func NewRelicUserKey() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "new-relic-user-api-id", RuleID: "new-relic-user-api-id",
Description: "Found a New Relic user API ID, posing a risk to application monitoring services and data integrity.", Description: "Found a New Relic user API ID, posing a risk to application monitoring services and data integrity.",
Regex: generateSemiGenericRegex([]string{ Regex: utils.GenerateSemiGenericRegex([]string{
"new-relic", "new-relic",
"newrelic", "newrelic",
"new_relic", "new_relic",
}, alphaNumeric("64"), true), }, utils.AlphaNumeric("64"), true),
Keywords: []string{ Keywords: []string{
"new-relic", "new-relic",
@@ -48,9 +49,9 @@ func NewRelicUserKey() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("new-relic", secrets.NewSecret(alphaNumeric("64"))), utils.GenerateSampleSecret("new-relic", secrets.NewSecret(utils.AlphaNumeric("64"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func NewRelicBrowserAPIKey() *config.Rule { func NewRelicBrowserAPIKey() *config.Rule {
@@ -58,7 +59,7 @@ func NewRelicBrowserAPIKey() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "new-relic-browser-api-token", RuleID: "new-relic-browser-api-token",
Description: "Identified a New Relic ingest browser API token, risking unauthorized access to application performance data and analytics.", Description: "Identified a New Relic ingest browser API token, risking unauthorized access to application performance data and analytics.",
Regex: generateSemiGenericRegex([]string{ Regex: utils.GenerateSemiGenericRegex([]string{
"new-relic", "new-relic",
"newrelic", "newrelic",
"new_relic", "new_relic",
@@ -71,7 +72,30 @@ func NewRelicBrowserAPIKey() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("new-relic", "NRJS-"+secrets.NewSecret(hex("19"))), utils.GenerateSampleSecret("new-relic", "NRJS-"+secrets.NewSecret(utils.Hex("19"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
}
func NewRelicInsertKey() *config.Rule {
// define rule
r := config.Rule{
RuleID: "new-relic-insert-key",
Description: "Discovered a New Relic insight insert key, compromising data injection into the platform.",
Regex: utils.GenerateSemiGenericRegex([]string{
"new-relic",
"newrelic",
"new_relic",
}, `NRII-[a-z0-9-]{32}`, true),
Keywords: []string{
"NRII-",
},
}
// validate
tps := []string{
utils.GenerateSampleSecret("new-relic", "NRII-"+secrets.NewSecret(utils.Hex("32"))),
}
return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func NPM() *config.Rule {
r := config.Rule{ r := 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: generateUniqueTokenRegex(`npm_[a-z0-9]{36}`, true), Regex: utils.GenerateUniqueTokenRegex(`npm_[a-z0-9]{36}`, true),
Keywords: []string{ Keywords: []string{
"npm_", "npm_",
@@ -19,7 +20,7 @@ func NPM() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("npmAccessToken", "npm_"+secrets.NewSecret(alphaNumeric("36"))), utils.GenerateSampleSecret("npmAccessToken", "npm_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+5 -4
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,9 +11,9 @@ func NytimesAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "nytimes-access-token", RuleID: "nytimes-access-token",
Description: "Detected a Nytimes Access Token, risking unauthorized access to New York Times APIs and content services.", Description: "Detected a Nytimes Access Token, risking unauthorized access to New York Times APIs and content services.",
Regex: generateSemiGenericRegex([]string{ Regex: utils.GenerateSemiGenericRegex([]string{
"nytimes", "new-york-times,", "newyorktimes"}, "nytimes", "new-york-times,", "newyorktimes"},
alphaNumericExtended("32"), true), utils.AlphaNumericExtended("32"), true),
Keywords: []string{ Keywords: []string{
"nytimes", "nytimes",
@@ -23,7 +24,7 @@ func NytimesAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("nytimes", secrets.NewSecret(alphaNumeric("32"))), utils.GenerateSampleSecret("nytimes", secrets.NewSecret(utils.AlphaNumeric("32"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+5 -4
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,8 +11,8 @@ 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: generateSemiGenericRegex([]string{"okta"}, Regex: utils.GenerateSemiGenericRegex([]string{"okta"},
alphaNumericExtended("42"), true), utils.AlphaNumericExtended("42"), true),
Keywords: []string{ Keywords: []string{
"okta", "okta",
@@ -20,7 +21,7 @@ func OktaAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("okta", secrets.NewSecret(alphaNumeric("42"))), utils.GenerateSampleSecret("okta", secrets.NewSecret(utils.AlphaNumeric("42"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ 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: 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}`, true),
Keywords: []string{ Keywords: []string{
"T3BlbkFJ", "T3BlbkFJ",
@@ -19,7 +20,7 @@ func OpenAI() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("openaiApiKey", "sk-"+secrets.NewSecret(alphaNumeric("20"))+"T3BlbkFJ"+secrets.NewSecret(alphaNumeric("20"))), utils.GenerateSampleSecret("openaiApiKey", "sk-"+secrets.NewSecret(utils.AlphaNumeric("20"))+"T3BlbkFJ"+secrets.NewSecret(utils.AlphaNumeric("20"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+38
View File
@@ -0,0 +1,38 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
// OpenShift 4 user tokens are prefixed with `sha256~`.
// https://docs.redhat.com/en/documentation/openshift_container_platform/4.10/html-single/authentication_and_authorization/index#oauth-view-details-tokens_managing-oauth-access-tokens
func OpenshiftUserToken() *config.Rule {
r := config.Rule{
RuleID: "openshift-user-token",
Description: "Found an OpenShift user token, potentially compromising an OpenShift/Kubernetes cluster.",
// TODO: Do tokens vary in length or are they always 43?
Regex: regexp.MustCompile(`\b(sha256~[\w-]{43})(?:[^\w-]|\z)`),
Entropy: 3.5,
SecretGroup: 0,
Keywords: []string{
"sha256~",
},
}
// validate
tps := []string{
`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
"sha256~" + secrets.NewSecret(`[\w-]{43}`),
}
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
`oc login --token=sha256~_xxxxxx_xxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxx-X \
--server=https://api.${zone}.appuio.cloud:6443`,
}
return utils.Validate(r, tps, fps)
}
+11 -10
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/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
@@ -12,7 +13,7 @@ func PlaidAccessID() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "plaid-client-id", RuleID: "plaid-client-id",
Description: "Uncovered a Plaid Client ID, which could lead to unauthorized financial service integrations and data breaches.", Description: "Uncovered a Plaid Client ID, which could lead to unauthorized financial service integrations and data breaches.",
Regex: generateSemiGenericRegex([]string{"plaid"}, alphaNumeric("24"), true), Regex: utils.GenerateSemiGenericRegex([]string{"plaid"}, utils.AlphaNumeric("24"), true),
Entropy: 3.5, Entropy: 3.5,
Keywords: []string{ Keywords: []string{
@@ -22,9 +23,9 @@ func PlaidAccessID() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("plaid", secrets.NewSecret(alphaNumeric("24"))), utils.GenerateSampleSecret("plaid", secrets.NewSecret(utils.AlphaNumeric("24"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func PlaidSecretKey() *config.Rule { func PlaidSecretKey() *config.Rule {
@@ -32,7 +33,7 @@ func PlaidSecretKey() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "plaid-secret-key", RuleID: "plaid-secret-key",
Description: "Detected a Plaid Secret key, risking unauthorized access to financial accounts and sensitive transaction data.", Description: "Detected a Plaid Secret key, risking unauthorized access to financial accounts and sensitive transaction data.",
Regex: generateSemiGenericRegex([]string{"plaid"}, alphaNumeric("30"), true), Regex: utils.GenerateSemiGenericRegex([]string{"plaid"}, utils.AlphaNumeric("30"), true),
Entropy: 3.5, Entropy: 3.5,
Keywords: []string{ Keywords: []string{
@@ -42,9 +43,9 @@ func PlaidSecretKey() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("plaid", secrets.NewSecret(alphaNumeric("30"))), utils.GenerateSampleSecret("plaid", secrets.NewSecret(utils.AlphaNumeric("30"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func PlaidAccessToken() *config.Rule { func PlaidAccessToken() *config.Rule {
@@ -52,8 +53,8 @@ func PlaidAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "plaid-api-token", RuleID: "plaid-api-token",
Description: "Discovered a Plaid API Token, potentially compromising financial data aggregation and banking services.", Description: "Discovered a Plaid API Token, potentially compromising financial data aggregation and banking services.",
Regex: generateSemiGenericRegex([]string{"plaid"}, Regex: utils.GenerateSemiGenericRegex([]string{"plaid"},
fmt.Sprintf("access-(?:sandbox|development|production)-%s", hex8_4_4_4_12()), true), fmt.Sprintf("access-(?:sandbox|development|production)-%s", utils.Hex8_4_4_4_12()), true),
Keywords: []string{ Keywords: []string{
"plaid", "plaid",
@@ -62,7 +63,7 @@ func PlaidAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("plaid", secrets.NewSecret(fmt.Sprintf("access-(?:sandbox|development|production)-%s", hex8_4_4_4_12()))), utils.GenerateSampleSecret("plaid", secrets.NewSecret(fmt.Sprintf("access-(?:sandbox|development|production)-%s", utils.Hex8_4_4_4_12()))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+16 -15
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ 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: generateUniqueTokenRegex(`pscale_pw_(?i)[a-z0-9=\-_\.]{32,64}`, true), Regex: utils.GenerateUniqueTokenRegex(`pscale_pw_(?i)[a-z0-9=\-_\.]{32,64}`, true),
Keywords: []string{ Keywords: []string{
"pscale_pw_", "pscale_pw_",
@@ -19,11 +20,11 @@ func PlanetScalePassword() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("planetScalePassword", "pscale_pw_"+secrets.NewSecret(alphaNumericExtended("32"))), utils.GenerateSampleSecret("planetScalePassword", "pscale_pw_"+secrets.NewSecret(utils.AlphaNumericExtended("32"))),
generateSampleSecret("planetScalePassword", "pscale_pw_"+secrets.NewSecret(alphaNumericExtended("43"))), utils.GenerateSampleSecret("planetScalePassword", "pscale_pw_"+secrets.NewSecret(utils.AlphaNumericExtended("43"))),
generateSampleSecret("planetScalePassword", "pscale_pw_"+secrets.NewSecret(alphaNumericExtended("64"))), utils.GenerateSampleSecret("planetScalePassword", "pscale_pw_"+secrets.NewSecret(utils.AlphaNumericExtended("64"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func PlanetScaleAPIToken() *config.Rule { func PlanetScaleAPIToken() *config.Rule {
@@ -31,7 +32,7 @@ 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: generateUniqueTokenRegex(`pscale_tkn_(?i)[a-z0-9=\-_\.]{32,64}`, true), Regex: utils.GenerateUniqueTokenRegex(`pscale_tkn_(?i)[a-z0-9=\-_\.]{32,64}`, true),
Keywords: []string{ Keywords: []string{
"pscale_tkn_", "pscale_tkn_",
@@ -40,11 +41,11 @@ func PlanetScaleAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("planetScalePassword", "pscale_tkn_"+secrets.NewSecret(alphaNumericExtended("32"))), utils.GenerateSampleSecret("planetScalePassword", "pscale_tkn_"+secrets.NewSecret(utils.AlphaNumericExtended("32"))),
generateSampleSecret("planetScalePassword", "pscale_tkn_"+secrets.NewSecret(alphaNumericExtended("43"))), utils.GenerateSampleSecret("planetScalePassword", "pscale_tkn_"+secrets.NewSecret(utils.AlphaNumericExtended("43"))),
generateSampleSecret("planetScalePassword", "pscale_tkn_"+secrets.NewSecret(alphaNumericExtended("64"))), utils.GenerateSampleSecret("planetScalePassword", "pscale_tkn_"+secrets.NewSecret(utils.AlphaNumericExtended("64"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func PlanetScaleOAuthToken() *config.Rule { func PlanetScaleOAuthToken() *config.Rule {
@@ -52,7 +53,7 @@ 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: generateUniqueTokenRegex(`pscale_oauth_(?i)[a-z0-9=\-_\.]{32,64}`, true), Regex: utils.GenerateUniqueTokenRegex(`pscale_oauth_(?i)[a-z0-9=\-_\.]{32,64}`, true),
Keywords: []string{ Keywords: []string{
"pscale_oauth_", "pscale_oauth_",
@@ -61,9 +62,9 @@ func PlanetScaleOAuthToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("planetScalePassword", "pscale_oauth_"+secrets.NewSecret(alphaNumericExtended("32"))), utils.GenerateSampleSecret("planetScalePassword", "pscale_oauth_"+secrets.NewSecret(utils.AlphaNumericExtended("32"))),
generateSampleSecret("planetScalePassword", "pscale_oauth_"+secrets.NewSecret(alphaNumericExtended("43"))), utils.GenerateSampleSecret("planetScalePassword", "pscale_oauth_"+secrets.NewSecret(utils.AlphaNumericExtended("43"))),
generateSampleSecret("planetScalePassword", "pscale_oauth_"+secrets.NewSecret(alphaNumericExtended("64"))), utils.GenerateSampleSecret("planetScalePassword", "pscale_oauth_"+secrets.NewSecret(utils.AlphaNumericExtended("64"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ 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: 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}`, true),
Keywords: []string{ Keywords: []string{
"PMAK-", "PMAK-",
@@ -19,7 +20,7 @@ func PostManAPI() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("postmanAPItoken", "PMAK-"+secrets.NewSecret(hex("24"))+"-"+secrets.NewSecret(hex("34"))), utils.GenerateSampleSecret("postmanAPItoken", "PMAK-"+secrets.NewSecret(utils.Hex("24"))+"-"+secrets.NewSecret(utils.Hex("34"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ 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: generateUniqueTokenRegex(`pnu_[a-z0-9]{36}`, true), Regex: utils.GenerateUniqueTokenRegex(`pnu_[a-z0-9]{36}`, true),
Keywords: []string{ Keywords: []string{
"pnu_", "pnu_",
@@ -19,7 +20,7 @@ func Prefect() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("api-token", "pnu_"+secrets.NewSecret(alphaNumeric("36"))), utils.GenerateSampleSecret("api-token", "pnu_"+secrets.NewSecret(utils.AlphaNumeric("36"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+3 -2
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
@@ -11,7 +12,7 @@ func PrivateKey() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Identified a Private Key, which may compromise cryptographic security and sensitive data encryption.", Description: "Identified a Private Key, which may compromise cryptographic security and sensitive data encryption.",
RuleID: "private-key", RuleID: "private-key",
Regex: regexp.MustCompile(`(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY( BLOCK)?-----[\s\S-]*KEY( BLOCK)?----`), Regex: regexp.MustCompile(`(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY(?: BLOCK)?-----[\s\S-]*KEY(?: BLOCK)?----`),
Keywords: []string{"-----BEGIN"}, Keywords: []string{"-----BEGIN"},
} }
@@ -27,5 +28,5 @@ abcdefghijklmnopqrstuvwxyz
anything anything
-----END PRIVATE KEY BLOCK-----`, -----END PRIVATE KEY BLOCK-----`,
} // gitleaks:allow } // gitleaks:allow
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func PulumiAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "pulumi-api-token", RuleID: "pulumi-api-token",
Description: "Found a Pulumi API token, posing a risk to infrastructure as code services and cloud resource management.", Description: "Found a Pulumi API token, posing a risk to infrastructure as code services and cloud resource management.",
Regex: generateUniqueTokenRegex(`pul-[a-f0-9]{40}`, true), Regex: utils.GenerateUniqueTokenRegex(`pul-[a-f0-9]{40}`, true),
Keywords: []string{ Keywords: []string{
"pul-", "pul-",
@@ -19,7 +20,7 @@ func PulumiAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("pulumi-api-token", "pul-"+secrets.NewSecret(hex("40"))), utils.GenerateSampleSecret("pulumi-api-token", "pul-"+secrets.NewSecret(utils.Hex("40"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
@@ -20,7 +21,7 @@ func PyPiUploadToken() *config.Rule {
} }
// validate // validate
tps := []string{"pypiToken := \"pypi-AgEIcHlwaS5vcmc" + secrets.NewSecret(hex("32")) + tps := []string{"pypiToken := \"pypi-AgEIcHlwaS5vcmc" + secrets.NewSecret(utils.Hex("32")) +
secrets.NewSecret(hex("32")) + "\""} secrets.NewSecret(utils.Hex("32")) + "\""}
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+6 -5
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,8 +11,8 @@ func RapidAPIAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "rapidapi-access-token", RuleID: "rapidapi-access-token",
Description: "Uncovered a RapidAPI Access Token, which could lead to unauthorized access to various APIs and data services.", Description: "Uncovered a RapidAPI Access Token, which could lead to unauthorized access to various APIs and data services.",
Regex: generateSemiGenericRegex([]string{"rapidapi"}, Regex: utils.GenerateSemiGenericRegex([]string{"rapidapi"},
alphaNumericExtendedShort("50"), true), utils.AlphaNumericExtendedShort("50"), true),
Keywords: []string{ Keywords: []string{
"rapidapi", "rapidapi",
@@ -20,8 +21,8 @@ func RapidAPIAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("rapidapi", utils.GenerateSampleSecret("rapidapi",
secrets.NewSecret(alphaNumericExtendedShort("50"))), secrets.NewSecret(utils.AlphaNumericExtendedShort("50"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func ReadMe() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "readme-api-token", RuleID: "readme-api-token",
Description: "Detected a Readme API token, risking unauthorized documentation management and content exposure.", Description: "Detected a Readme API token, risking unauthorized documentation management and content exposure.",
Regex: generateUniqueTokenRegex(`rdme_[a-z0-9]{70}`, true), Regex: utils.GenerateUniqueTokenRegex(`rdme_[a-z0-9]{70}`, true),
Keywords: []string{ Keywords: []string{
"rdme_", "rdme_",
@@ -19,7 +20,7 @@ func ReadMe() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("api-token", "rdme_"+secrets.NewSecret(alphaNumeric("70"))), utils.GenerateSampleSecret("api-token", "rdme_"+secrets.NewSecret(utils.AlphaNumeric("70"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func RubyGemsAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "rubygems-api-token", RuleID: "rubygems-api-token",
Description: "Identified a Rubygem API token, potentially compromising Ruby library distribution and package management.", Description: "Identified a Rubygem API token, potentially compromising Ruby library distribution and package management.",
Regex: generateUniqueTokenRegex(`rubygems_[a-f0-9]{48}`, true), Regex: utils.GenerateUniqueTokenRegex(`rubygems_[a-f0-9]{48}`, true),
Keywords: []string{ Keywords: []string{
"rubygems_", "rubygems_",
@@ -19,7 +20,7 @@ func RubyGemsAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("rubygemsAPIToken", "rubygems_"+secrets.NewSecret(hex("48"))), utils.GenerateSampleSecret("rubygemsAPIToken", "rubygems_"+secrets.NewSecret(utils.Hex("48"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
-126
View File
@@ -1,126 +0,0 @@
package rules
import (
"fmt"
"regexp"
"strings"
"github.com/rs/zerolog/log"
"github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/detect"
)
const (
// case insensitive prefix
caseInsensitive = `(?i)`
// identifier prefix (just an ignore group)
identifierCaseInsensitivePrefix = `(?i:`
identifierCaseInsensitiveSuffix = `)`
identifierPrefix = `(?:`
identifierSuffix = `)(?:[0-9a-z\-_\t .]{0,20})(?:[\s|']|[\s|"]){0,3}`
// commonly used assignment operators or function call
operator = `(?:=|>|:{1,3}=|\|\|:|<=|=>|:|\?=)`
// boundaries for the secret
// \x60 = `
secretPrefixUnique = `\b(`
secretPrefix = `(?:'|\"|\s|=|\x60){0,5}(`
secretSuffix = `)(?:['|\"|\n|\r|\s|\x60|;]|$)`
)
func generateSemiGenericRegex(identifiers []string, secretRegex string, isCaseInsensitive bool) *regexp.Regexp {
var sb strings.Builder
// The identifiers should always be case-insensitive.
// This is inelegant but prevents an extraneous `(?i:)` from being added to the pattern; it could be removed.
if isCaseInsensitive {
sb.WriteString(caseInsensitive)
writeIdentifiers(&sb, identifiers)
} else {
sb.WriteString(identifierCaseInsensitivePrefix)
writeIdentifiers(&sb, identifiers)
sb.WriteString(identifierCaseInsensitiveSuffix)
}
sb.WriteString(operator)
sb.WriteString(secretPrefix)
sb.WriteString(secretRegex)
sb.WriteString(secretSuffix)
return regexp.MustCompile(sb.String())
}
func writeIdentifiers(sb *strings.Builder, identifiers []string) {
sb.WriteString(identifierPrefix)
sb.WriteString(strings.Join(identifiers, "|"))
sb.WriteString(identifierSuffix)
}
func generateUniqueTokenRegex(secretRegex string, isCaseInsensitive bool) *regexp.Regexp {
var sb strings.Builder
if isCaseInsensitive {
sb.WriteString(caseInsensitive)
}
sb.WriteString(secretPrefixUnique)
sb.WriteString(secretRegex)
sb.WriteString(secretSuffix)
return regexp.MustCompile(sb.String())
}
func generateSampleSecret(identifier string, secret string) string {
return fmt.Sprintf("%s_api_token = \"%s\"", identifier, secret)
}
func validate(r config.Rule, truePositives []string, falsePositives []string) *config.Rule {
// normalize keywords like in the config package
var keywords []string
for _, k := range r.Keywords {
keywords = append(keywords, strings.ToLower(k))
}
r.Keywords = keywords
rules := make(map[string]config.Rule)
rules[r.RuleID] = r
d := detect.NewDetector(config.Config{
Rules: rules,
Keywords: keywords,
})
for _, tp := range truePositives {
if len(d.DetectString(tp)) != 1 {
log.Fatal().Msgf("Failed to validate. For rule ID [%s], true positive [%s] was not detected by regexp [%s]", r.RuleID, tp, r.Regex)
}
}
for _, fp := range falsePositives {
if len(d.DetectString(fp)) != 0 {
log.Fatal().Msgf("Failed to validate. For rule ID [%s], false positive [%s] was detected by regexp [%s]", r.RuleID, fp, r.Regex)
}
}
return &r
}
func numeric(size string) string {
return fmt.Sprintf(`[0-9]{%s}`, size)
}
func hex(size string) string {
return fmt.Sprintf(`[a-f0-9]{%s}`, size)
}
func alphaNumeric(size string) string {
return fmt.Sprintf(`[a-z0-9]{%s}`, size)
}
func alphaNumericExtendedShort(size string) string {
return fmt.Sprintf(`[a-z0-9_-]{%s}`, size)
}
func alphaNumericExtended(size string) string {
return fmt.Sprintf(`[a-z0-9=_\-]{%s}`, size)
}
func alphaNumericExtendedLong(size string) string {
return fmt.Sprintf(`[a-z0-9\/=_\+\-]{%s}`, size)
}
func hex8_4_4_4_12() string {
return `[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}`
}
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,14 +11,14 @@ func ScalingoAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Found a Scalingo API token, posing a risk to cloud platform services and application deployment security.", Description: "Found a Scalingo API token, posing a risk to cloud platform services and application deployment security.",
RuleID: "scalingo-api-token", RuleID: "scalingo-api-token",
Regex: generateUniqueTokenRegex(`tk-us-[a-zA-Z0-9-_]{48}`, false), Regex: utils.GenerateUniqueTokenRegex(`tk-us-[a-zA-Z0-9-_]{48}`, false),
Keywords: []string{"tk-us-"}, Keywords: []string{"tk-us-"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("scalingo", "tk-us-"+secrets.NewSecret(alphaNumericExtendedShort("48"))), utils.GenerateSampleSecret("scalingo", "tk-us-"+secrets.NewSecret(utils.AlphaNumericExtendedShort("48"))),
`scalingo_api_token = "tk-us-loys7ib9yrxcys_ta2sq85mjar6lgcsspkd9x61s7h5epf_-"`, // gitleaks:allow `scalingo_api_token = "tk-us-loys7ib9yrxcys_ta2sq85mjar6lgcsspkd9x61s7h5epf_-"`, // gitleaks:allow
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+7 -6
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func SendbirdAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "sendbird-access-token", RuleID: "sendbird-access-token",
Description: "Uncovered a Sendbird Access Token, potentially risking unauthorized access to communication services and user data.", Description: "Uncovered a Sendbird Access Token, potentially risking unauthorized access to communication services and user data.",
Regex: generateSemiGenericRegex([]string{"sendbird"}, hex("40"), true), Regex: utils.GenerateSemiGenericRegex([]string{"sendbird"}, utils.Hex("40"), true),
Keywords: []string{ Keywords: []string{
"sendbird", "sendbird",
@@ -19,9 +20,9 @@ func SendbirdAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("sendbird", secrets.NewSecret(hex("40"))), utils.GenerateSampleSecret("sendbird", secrets.NewSecret(utils.Hex("40"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
func SendbirdAccessID() *config.Rule { func SendbirdAccessID() *config.Rule {
@@ -29,7 +30,7 @@ func SendbirdAccessID() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "sendbird-access-id", RuleID: "sendbird-access-id",
Description: "Discovered a Sendbird Access ID, which could compromise chat and messaging platform integrations.", Description: "Discovered a Sendbird Access ID, which could compromise chat and messaging platform integrations.",
Regex: generateSemiGenericRegex([]string{"sendbird"}, hex8_4_4_4_12(), true), Regex: utils.GenerateSemiGenericRegex([]string{"sendbird"}, utils.Hex8_4_4_4_12(), true),
Keywords: []string{ Keywords: []string{
"sendbird", "sendbird",
@@ -38,7 +39,7 @@ func SendbirdAccessID() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("sendbird", secrets.NewSecret(hex8_4_4_4_12())), utils.GenerateSampleSecret("sendbird", secrets.NewSecret(utils.Hex8_4_4_4_12())),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func SendGridAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "sendgrid-api-token", RuleID: "sendgrid-api-token",
Description: "Detected a SendGrid API token, posing a risk of unauthorized email service operations and data exposure.", Description: "Detected a SendGrid API token, posing a risk of unauthorized email service operations and data exposure.",
Regex: generateUniqueTokenRegex(`SG\.(?i)[a-z0-9=_\-\.]{66}`, true), Regex: utils.GenerateUniqueTokenRegex(`SG\.(?i)[a-z0-9=_\-\.]{66}`, true),
Keywords: []string{ Keywords: []string{
"SG.", "SG.",
@@ -19,7 +20,7 @@ func SendGridAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("sengridAPIToken", "SG."+secrets.NewSecret(alphaNumericExtended("66"))), utils.GenerateSampleSecret("sengridAPIToken", "SG."+secrets.NewSecret(utils.AlphaNumericExtended("66"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func SendInBlueAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "sendinblue-api-token", RuleID: "sendinblue-api-token",
Description: "Identified a Sendinblue API token, which may compromise email marketing services and subscriber data privacy.", Description: "Identified a Sendinblue API token, which may compromise email marketing services and subscriber data privacy.",
Regex: generateUniqueTokenRegex(`xkeysib-[a-f0-9]{64}\-(?i)[a-z0-9]{16}`, true), Regex: utils.GenerateUniqueTokenRegex(`xkeysib-[a-f0-9]{64}\-(?i)[a-z0-9]{16}`, true),
Keywords: []string{ Keywords: []string{
"xkeysib-", "xkeysib-",
@@ -19,7 +20,7 @@ func SendInBlueAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("sendinblue", "xkeysib-"+secrets.NewSecret(hex("64"))+"-"+secrets.NewSecret(alphaNumeric("16"))), utils.GenerateSampleSecret("sendinblue", "xkeysib-"+secrets.NewSecret(utils.Hex("64"))+"-"+secrets.NewSecret(utils.AlphaNumeric("16"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func SentryAccessToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "sentry-access-token", RuleID: "sentry-access-token",
Description: "Found a Sentry Access Token, risking unauthorized access to error tracking services and sensitive application data.", Description: "Found a Sentry Access Token, risking unauthorized access to error tracking services and sensitive application data.",
Regex: generateSemiGenericRegex([]string{"sentry"}, hex("64"), true), Regex: utils.GenerateSemiGenericRegex([]string{"sentry"}, utils.Hex("64"), true),
Keywords: []string{ Keywords: []string{
"sentry", "sentry",
@@ -19,7 +20,7 @@ func SentryAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("sentry", secrets.NewSecret(hex("64"))), utils.GenerateSampleSecret("sentry", secrets.NewSecret(utils.Hex("64"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
+5 -4
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"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"
) )
@@ -10,7 +11,7 @@ func ShippoAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "shippo-api-token", RuleID: "shippo-api-token",
Description: "Discovered a Shippo API token, potentially compromising shipping services and customer order data.", Description: "Discovered a Shippo API token, potentially compromising shipping services and customer order data.",
Regex: generateUniqueTokenRegex(`shippo_(live|test)_[a-f0-9]{40}`, true), Regex: utils.GenerateUniqueTokenRegex(`shippo_(live|test)_[a-f0-9]{40}`, true),
Keywords: []string{ Keywords: []string{
"shippo_", "shippo_",
@@ -19,8 +20,8 @@ func ShippoAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("shippo", "shippo_live_"+secrets.NewSecret(hex("40"))), utils.GenerateSampleSecret("shippo", "shippo_live_"+secrets.NewSecret(utils.Hex("40"))),
generateSampleSecret("shippo", "shippo_test_"+secrets.NewSecret(hex("40"))), utils.GenerateSampleSecret("shippo", "shippo_test_"+secrets.NewSecret(utils.Hex("40"))),
} }
return validate(r, tps, nil) return utils.Validate(r, tps, nil)
} }
Loaded 100 of 146 files, more files were not shown because too many files have changed in this diff. Show more