Compare commits

..
37 Commits
Author SHA1 Message Date
Zachary 05c165deb2 Fixes accidental type typos while translating rules from validation spreadsheet, adds bittrex rule 2022-06-27 17:03:32 -05:00
Zachary Rice f6a87ca58c Remove ssn allowlist (#898)
* Adding a bunch of new rules, update allowlist to include node_modules and vendor folders, extend helper config functions

* remove ssns from allowlist since default config does not detect ssn
2022-06-27 08:58:00 -05:00
Zachary Rice 73a3cf8afb Adding a bunch of new rules, update allowlist to include node_modules… (#896)
* Adding a bunch of new rules, update allowlist to include node_modules and vendor folders, extend helper config functions

* use func instead of function in stopwords
2022-06-25 11:43:51 -05:00
Zachary Rice d196b83ca6 contributing guidelines first draft (#895)
* contributing guidelines first draft

* update links, add readme note
2022-06-23 17:17:39 -05:00
Alex 35f2ea5da2 Lint python commit script to satisfy PEP8 (#893) 2022-06-21 06:55:43 -05:00
Zachary Rice 70028079b4 Update generate (#892)
* maintain parity with recent changes... need to create rule contributing guidelines

* missed on, ensure uniqueness in rule-id
2022-06-20 14:57:48 -05:00
Zachary Rice c14af5ffdf maintain parity with recent changes... need to create rule contributing guidelines (#891) 2022-06-20 14:14:14 -05:00
Craig SmithandCraig Smith 06b1396a2a Fix duplicate TOML Rules and IDs (#889)
* Remove duplicate rule

* Fix duplicate rule IDs

Co-authored-by: Craig Smith <5344211-craigmsmith@users.noreply.gitlab.com>
2022-06-20 08:49:47 -05:00
Zachary Rice 5d3f247d7d Update README.md 2022-06-16 08:11:20 -05:00
Zachary Rice 404dd8e0c0 Update gitleaks.yml 2022-06-15 17:20:08 -05:00
Zachary Rice 3a1ab48818 Update README.md 2022-06-12 13:25:03 -05:00
Zachary Rice f5c2b636f3 user accounts don't need gitleaks license 2022-06-07 11:48:43 -05:00
Zachary Rice b5ed7ff1b2 Update README.md 2022-06-02 17:47:36 -05:00
Zachary Rice 09007da395 Add gitleaks badge 2022-06-02 17:46:47 -05:00
Zachary Rice d51ce47d86 Create gitleaks.yml (#884) 2022-06-02 17:40:57 -05:00
Zachary Rice 6919447094 add link to gitleaks.io 2022-06-02 17:21:08 -05:00
fooliooandx c3b7932544 fix git unsafe directory (#883)
* fix git unsafe directory

fixes https://github.com/zricethezav/gitleaks/issues/846

* Update Dockerfile

Co-authored-by: x <>
2022-06-02 14:22:03 -05:00
Zachary Rice 82e409a434 Limit newlines regex (#881)
* improve regex to reduce fps with newlines

* remove version from regex and rely on stopwords instead

* add false positive for validation
2022-05-30 12:07:06 -05:00
Zachary 0eb57cbe4d add combo to stopwords, update cmd/generate 2022-05-28 11:47:17 -05:00
Don C. Bigler 3531887941 Fix generic-api-key detected erroneously (zricethezav#877) (#878) 2022-05-28 11:44:49 -05:00
Zachary Rice e9ebde73bc ignore end line when comparing generic rules (#879) 2022-05-28 09:49:27 -05:00
Zachary Rice 469cd22f61 updating generic regex and algoia regex (#875) 2022-05-25 08:00:10 -05:00
SimonGurney 93e72c215d feat: add algolia key support (#866)
* feat: add algolia key support

* feat: add algolia key to generator

* chore: update algolia regex to match gen
2022-05-25 07:39:20 -05:00
Dirkjan Bussink 865478bcdc Improve PlanetScale token detection (#874)
This improves the PlanetScale token detection. It add some flexibility
in length. There is no guarantee that the length is always 43 characters
(in fact, it's very likely to change a bit soon).

Additionally, it adds support for detecting oauth tokens as well.
2022-05-24 22:15:36 -05:00
Zachary Rice d6c0de7c85 Update README.md 2022-05-16 19:08:06 -05:00
Zachary Rice 0266ab8958 Adding JIT Security messages 2022-05-10 11:21:04 -05:00
Zachary Rice 6b7ab73a52 Update README.md 2022-05-02 10:21:40 -05:00
Zachary Rice 61ee7c58cc fix no-git bug (#859) 2022-04-27 21:48:56 -05:00
Zachary Rice ad7509e3b4 Removing private keyword from private key rule (#858) 2022-04-27 07:29:09 -05:00
Zachary Rice a62cc52aba nasty little bug (#853) 2022-04-23 11:18:56 -05:00
Zachary Rice f93e5dc844 adding a ton of stopwords to the generic rule only as that is the loudest rule (#851) 2022-04-21 17:01:21 -05:00
Zachary Rice 8481f0e9cd adding stopwords (#849)
* adding stopwords

* format readme, update default config
2022-04-21 08:31:58 -05:00
Zachary Rice 82f7d61593 Update dockerfile (#848)
* bump alpine and add default safe dir for git

* comment out safe dir fix

* update deps
2022-04-20 18:19:33 -05:00
Zachary Rice a42b32bdf1 fix EOL in secret suffix (#847)
* fix EOL in secret suffix

* allow quoted key value syntax
2022-04-20 17:55:07 -05:00
foolioo 79638b080c unpin docker version in pre-commit hook (#832)
eliminating inconsistency. e.g. for version 8.6.1, pre-commit hooks points to outdated version https://github.com/zricethezav/gitleaks/blob/c33ee3f25215635c0afbb210672779e7efb6f1d2/.pre-commit-hooks.yaml#L10
2022-04-19 21:33:23 -05:00
Zachary Rice 3474c58c9e Generate tps (#845)
* WIP

* simplify tp generation
2022-04-18 21:59:38 -05:00
Zachary Rice d8cd93cabe maybe fix out of bounds (#843) 2022-04-18 14:57:40 -05:00
101 changed files with 5105 additions and 595 deletions

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
name: gitleaks
on: [pull_request, push, workflow_dispatch]
jobs:
scan:
name: gitleaks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+1 -1
View File
@@ -7,5 +7,5 @@
- id: gitleaks-docker - id: gitleaks-docker
name: Detect hardcoded secrets name: Detect hardcoded secrets
description: Detect hardcoded secrets using Gitleaks description: Detect hardcoded secrets using Gitleaks
entry: zricethezav/gitleaks:v8.5.2 protect --verbose --redact --staged entry: zricethezav/gitleaks protect --verbose --redact --staged
language: docker_image language: docker_image
+103
View File
@@ -0,0 +1,103 @@
# Contribution guidelines
## General
### Issues
If you have a feature or bug fix you would like to contribute please check if
there are any open issues describing your proposed addition. If there are open
issues, make a comment stating you are working on fixing or implementing said
issue. If not, then please open an issue describing your addition. Make sure to
link your PR to an issue.
### Pull Requests
Fill out the template as best you can. Make sure your tests pass. If you see a
PR that isn't one you opened and want it introduced in the next release,
give it a :thumbsup: on the PR description.
## Adding new Gitleaks rules
If you want to add a new rule to the [default Gitleaks configuration](https://github.com/zricethezav/gitleaks/blob/master/config/gitleaks.toml) then follow these steps.
1. Create a `cmd/generate/config/rules/{provider}.go` file.
This file is used to generate a new Gitleaks rule.
Let's look at `beamer.go` for example. Comments have been added for context.
```golang
func Beamer() *config.Rule {
// Define Rule
r := config.Rule{
// Human redable description of the rule
Description: "Beamer API token",
// Unique ID for the rule
RuleID: "beamer-api-token",
// Regex capture group for the actual secret
SecretGroup: 1,
// Regex used for detecting secrets. See regex section below for more details
Regex: generateSemiGenericRegex([]string{"beamer"}, `b_[a-z0-9=_\-]{44}`),
// Keywords used for string matching on fragments (think of this as a prefilter)
Keywords: []string{"beamer"},
}
// validate
tps := []string{
generateSampleSecret("beamer", "b_"+secrets.NewSecret(alphaNumericExtended("44"))),
}
return validate(r, tps, nil)
}
```
Feel free to use this example as a template when writing new rules.
This file should be fairly self-explanatory except for a few items;
regex and secret generation. To help with maintence, _most_ rules should
be uniform. The functions,
[`generateSemiGenericRegex`](https://github.com/zricethezav/gitleaks/blob/master/cmd/generate/config/rules/rule.go#L31) and [`generateUniqueTokenRegex`](https://github.com/zricethezav/gitleaks/blob/master/cmd/generate/config/rules/rule.go#L44) will generate rules
that follow defined patterns.
The function signatures look like this:
```golang
func generateSemiGenericRegex(identifiers []string, secretRegex string) *regexp.Regexp
func generateUniqueTokenRegex(secretRegex string) *regexp.Regexp
```
`generateSemiGenericRegex` accepts a list of identifiers and a regex.
The list of identifiers _should_ match the list of `Keywords` in the rule
definition above. Both `identifiers` in the `generateSemiGenericRegex`
function _and_ `Keywords` act as filters for Gitleaks telling the program
"_at least one of these strings must be present to be considered a leak_"
`generateUniqueToken` just accepts a regex. If you are writing a rule for a
token that is unique enough not to require an identifier then you can use
this function. For example, Pulumi's API Token has the prefix `pul-` which is
unique enough to use `generateUniqueToken`. But something like Beamer's API
token that has a `b_` prefix is not unqiue enough to use `generateUniqueToken`,
so instead we use `generateSemiGenericRegex` and require a `beamer`
identifier is part of the rule.
If a token's prefix has more than `3` characters then you could
probably get away with using `generateUniqueToken`.
Last thing you'll want to hit before we move on from this file is the
validation part. You can use `generateSampleSecret` to create a secret for the
true positives (`tps` in the example above) used in `validate`.
1. Update `cmd/generate/config/main.go`. Add a line like
`configRules = append(configRules, rules.Beamer())` in `main()`. Try and keep
this alphabetically pretty please.
1. Change directories into `cmd/generate/config` and run `go run main.go`
```
cd cmd/generate/config && go run main.go
```
1. Check out your new rules in `config/gitleaks.toml` and see if everything looks good.
1. Open a PR
+5 -2
View File
@@ -1,12 +1,15 @@
FROM golang:1.17 AS build FROM golang:1.18 AS build
WORKDIR /go/src/github.com/zricethezav/gitleaks WORKDIR /go/src/github.com/zricethezav/gitleaks
COPY . . COPY . .
RUN VERSION=$(git describe --tags --abbrev=0) && \ RUN VERSION=$(git describe --tags --abbrev=0) && \
CGO_ENABLED=0 go build -o bin/gitleaks -ldflags "-X="github.com/zricethezav/gitleaks/v8/cmd.Version=${VERSION} CGO_ENABLED=0 go build -o bin/gitleaks -ldflags "-X="github.com/zricethezav/gitleaks/v8/cmd.Version=${VERSION}
FROM alpine:3.14.2 FROM alpine:3.16
RUN adduser -D gitleaks && \ RUN adduser -D gitleaks && \
apk add --no-cache bash git openssh-client apk add --no-cache bash git openssh-client
COPY --from=build /go/src/github.com/zricethezav/gitleaks/bin/* /usr/bin/ COPY --from=build /go/src/github.com/zricethezav/gitleaks/bin/* /usr/bin/
USER gitleaks USER gitleaks
RUN git config --global --add safe.directory '*'
ENTRYPOINT ["gitleaks"] ENTRYPOINT ["gitleaks"]
+91 -23
View File
@@ -1,4 +1,5 @@
# gitleaks # gitleaks
``` ```
┌─○───┐ ┌─○───┐
│ │╲ │ │ │╲ │
@@ -7,7 +8,6 @@
└─░───┘ └─░───┘
``` ```
<p align="left"> <p align="left">
<p align="left"> <p align="left">
<a href="https://github.com/zricethezav/gitleaks/actions/workflows/test.yml"> <a href="https://github.com/zricethezav/gitleaks/actions/workflows/test.yml">
@@ -16,6 +16,12 @@
<a href="https://hub.docker.com/r/zricethezav/gitleaks"> <a href="https://hub.docker.com/r/zricethezav/gitleaks">
<img src="https://img.shields.io/docker/pulls/zricethezav/gitleaks.svg" /> <img src="https://img.shields.io/docker/pulls/zricethezav/gitleaks.svg" />
</a> </a>
<a href="https://www.jit.io/jit-open-source-gitleaks?utm_source=github&utm_medium=badge&utm_campaign=GitleaksReadme&utm_id=oss&items=item-secret-detection">
<img src="https://img.shields.io/badge/Secured%20by-Jit-B8287F?style=?style=plastic" />
</a>
<a href="https://github.com/zricethezav/gitleaks-action">
<img alt="gitleaks badge" src="https://img.shields.io/badge/protected%20by-gitleaks-blue">
</a>
<a href="https://twitter.com/intent/follow?screen_name=zricethezav"> <a href="https://twitter.com/intent/follow?screen_name=zricethezav">
<img src="https://img.shields.io/twitter/follow/zricethezav?label=Follow%20zricethezav&style=social&color=blue" alt="Follow @zricethezav" /> <img src="https://img.shields.io/twitter/follow/zricethezav?label=Follow%20zricethezav&style=social&color=blue" alt="Follow @zricethezav" />
</a> </a>
@@ -27,6 +33,7 @@ Gitleaks is a SAST tool for **detecting** and **preventing** hardcoded secrets l
[![asciicast](https://asciinema.org/a/455683.svg)](https://asciinema.org/a/455683) [![asciicast](https://asciinema.org/a/455683.svg)](https://asciinema.org/a/455683)
## Getting Started ## Getting Started
Gitleaks can be installed using Homebrew, Docker, or Go. Gitleaks is also available in binary form for many popular platforms and OS types on the [releases page](https://github.com/zricethezav/gitleaks/releases). In addition, Gitleaks can be implemented as a pre-commit hook directly in your repo. Gitleaks can be installed using Homebrew, Docker, or Go. Gitleaks is also available in binary form for many popular platforms and OS types on the [releases page](https://github.com/zricethezav/gitleaks/releases). In addition, Gitleaks can be implemented as a pre-commit hook directly in your repo.
### MacOS ### MacOS
@@ -36,32 +43,63 @@ brew install gitleaks
``` ```
### Docker ### Docker
#### DockerHub #### DockerHub
```bash ```bash
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] --source="/path" [OPTIONS]
``` ```
#### ghcr.io #### ghcr.io
```bash ```bash
docker pull ghcr.io/zricethezav/gitleaks:latest docker pull ghcr.io/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] --source="/path" [OPTIONS]
``` ```
### From Source ### From Source
1. Download and install Go from https://golang.org/dl/ 1. Download and install Go from https://golang.org/dl/
2. Clone the repo 2. Clone the repo
```bash ```bash
git clone https://github.com/zricethezav/gitleaks.git git clone https://github.com/zricethezav/gitleaks.git
``` ```
3. Build the binary 3. Build the binary
```bash ```bash
cd gitleaks cd gitleaks
make build make build
``` ```
### Github Action
Check out the official [Gitleaks GitHub Action](https://github.com/gitleaks/gitleaks-action)
```
name: gitleaks
on: [pull_request, push, workflow_dispatch]
jobs:
scan:
name: gitleaks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE}} # Only required for Organizations, not personal accounts.
```
### Pre-Commit ### Pre-Commit
1. Install pre-commit from https://pre-commit.com/#install 1. Install pre-commit from https://pre-commit.com/#install
2. Create a `.pre-commit-config.yaml` file at the root of your repository with the following content: 2. Create a `.pre-commit-config.yaml` file at the root of your repository with the following content:
``` ```
repos: repos:
- repo: https://github.com/zricethezav/gitleaks - repo: https://github.com/zricethezav/gitleaks
@@ -69,22 +107,27 @@ make build
hooks: hooks:
- id: gitleaks - id: gitleaks
``` ```
for a [native execution of GitLeaks](https://github.com/zricethezav/gitleaks/releases) or use the [`gitleaks-docker` pre-commit ID](https://github.com/zricethezav/gitleaks/blob/master/.pre-commit-hooks.yaml) for executing GitLeaks using the [official Docker images](#docker) for a [native execution of GitLeaks](https://github.com/zricethezav/gitleaks/releases) or use the [`gitleaks-docker` pre-commit ID](https://github.com/zricethezav/gitleaks/blob/master/.pre-commit-hooks.yaml) for executing GitLeaks using the [official Docker images](#docker)
3. Install with `pre-commit install` 3. Install with `pre-commit install`
4. Now you're all set! 4. Now you're all set!
``` ```
➜ git commit -m "this commit contains a secret" ➜ git commit -m "this commit contains a secret"
Detect hardcoded secrets.................................................Failed Detect hardcoded secrets.................................................Failed
``` ```
Note: to disable the gitleaks pre-commit hook you can prepend `SKIP=gitleaks` to the commit command Note: to disable the gitleaks pre-commit hook you can prepend `SKIP=gitleaks` to the commit command
and it will skip running gitleaks and it will skip running gitleaks
``` ```
➜ SKIP=gitleaks git commit -m "skip gitleaks check" ➜ SKIP=gitleaks git commit -m "skip gitleaks check"
Detect hardcoded secrets................................................Skipped Detect hardcoded secrets................................................Skipped
``` ```
## Usage ## Usage
``` ```
Usage: Usage:
gitleaks [command] gitleaks [command]
@@ -116,20 +159,24 @@ 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`. There are two commands you will use to detect secrets; `detect` and `protect`.
#### Detect #### Detect
The `detect` command is used to scan repos, directories, and files. This command can be used on developer machines and in CI environments.
The `detect` command is used to scan repos, directories, and files. This command can be used on developer machines and in CI environments.
When running `detect` on a git repository, gitleaks will parse the output of a `git log -p` command (you can see how this executed When running `detect` on a git repository, gitleaks will parse the output of a `git log -p` command (you can see how this executed
[here](https://github.com/zricethezav/gitleaks/blob/7240e16769b92d2a1b137c17d6bf9d55a8562899/git/git.go#L17-L25)). [here](https://github.com/zricethezav/gitleaks/blob/7240e16769b92d2a1b137c17d6bf9d55a8562899/git/git.go#L17-L25)).
[`git log -p` generates patches](https://git-scm.com/docs/git-log#_generating_patch_text_with_p) which gitleaks will use to detect secrets. [`git log -p` generates patches](https://git-scm.com/docs/git-log#_generating_patch_text_with_p) which gitleaks will use to detect secrets.
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`. 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 --source . --log-opts="--all commitA..commitB"`. 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. 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. You can scan files and directories by using the `--no-git` option.
#### Protect #### Protect
The `protect` command is used to uncommitted changes in a git repo. This command should be used on developer machines in accordance with The `protect` command is used to 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). [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 When running `protect` on a git repository, gitleaks will parse the output of a `git diff` command (you can see how this executed
@@ -140,8 +187,10 @@ 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. **NOTE**: the `protect` command can only be used on git repos, running `protect` on files or directories will result in an error message.
### Verify Findings ### Verify Findings
You can verify a finding found by gitleaks using a `git log` command. You can verify a finding found by gitleaks using a `git log` command.
Example output: Example output:
``` ```
{ {
"Description": "AWS", "Description": "AWS",
@@ -163,15 +212,19 @@ Example output:
} }
``` ```
We can use the following format to verify the leak: We can use the following format to verify the leak:
``` ```
git log -L {StartLine,EndLine}:{File} {Commit} git log -L {StartLine,EndLine}:{File} {Commit}
``` ```
So in this example it would look like: So in this example it would look like:
``` ```
git log -L 37,37:checks_test.go ec2fc9d6cb0954fb3b57201cf6133c48d8ca0d29 git log -L 37,37:checks_test.go ec2fc9d6cb0954fb3b57201cf6133c48d8ca0d29
``` ```
Which gives us: Which gives us:
``` ```
@@ -190,11 +243,14 @@ diff --git a/checks_test.go b/checks_test.go
``` ```
## 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
your `.git/hooks/` directory. your `.git/hooks/` directory.
## Configuration ## Configuration
Gitleaks offers a configuration format you can follow to write your own secret detection rules: Gitleaks offers a configuration format you can follow to write your own secret detection rules:
```toml ```toml
# Title for the gitleaks configuration file. # Title for the gitleaks configuration file.
title = "Gitleaks title" title = "Gitleaks title"
@@ -233,9 +289,9 @@ entropy = 3.5
# either be part of the idenitifer or unique strings specific to the rule's regex # either be part of the idenitifer or unique strings specific to the rule's regex
# (introduced in v8.6.0) # (introduced in v8.6.0)
keywords = [ keywords = [
"auth", "auth",
"password", "password",
"token", "token",
] ]
# You can include an allowlist table for a single rule to reduce false positives or ignore commits # You can include an allowlist table for a single rule to reduce false positives or ignore commits
@@ -244,13 +300,20 @@ keywords = [
description = "ignore commit A" description = "ignore commit A"
commits = [ "commit-A", "commit-B"] commits = [ "commit-A", "commit-B"]
paths = [ paths = [
'''go\.mod''', '''go\.mod''',
'''go\.sum''' '''go\.sum'''
] ]
regexes = [ regexes = [
'''process''', '''process''',
'''getenv''', '''getenv''',
] ]
# note: stopwords targets the extracted secret, not the entire regex match
# like 'regexes' does. (stopwords introduced in 8.8.0)
stopwords = [
'''client''',
'''endpoint''',
]
# This is a global allowlist which has a higher order of precedence than rule-specific allowlists. # This is a global allowlist which has a higher order of precedence than rule-specific allowlists.
# If a commit listed in the `commits` field below is encountered then that commit will be skipped and no # If a commit listed in the `commits` field below is encountered then that commit will be skipped and no
@@ -259,35 +322,40 @@ regexes = [
description = "global allow list" description = "global allow list"
commits = [ "commit-A", "commit-B", "commit-C"] commits = [ "commit-A", "commit-B", "commit-C"]
paths = [ paths = [
'''gitleaks\.toml''', '''gitleaks\.toml''',
'''(.*?)(jpg|gif|doc)''' '''(.*?)(jpg|gif|doc)'''
] ]
regexes = [ regexes = [
'''219-09-9999''', '''219-09-9999''',
'''078-05-1120''', '''078-05-1120''',
'''(9[0-9]{2}|666)-\d{2}-\d{4}''', '''(9[0-9]{2}|666)-\d{2}-\d{4}''',
]
# note: stopwords targets the extracted secret, not the entire regex match
# like 'regexes' does. (stopwords introduced in 8.8.0)
stopwords = [
'''client''',
'''endpoint''',
] ]
``` ```
Refer to the default [gitleaks config](https://github.com/zricethezav/gitleaks/blob/master/config/gitleaks.toml) for examples and advice on writing regular expressions for secret detection.
Refer to the default [gitleaks config](https://github.com/zricethezav/gitleaks/blob/master/config/gitleaks.toml) for examples or follow the [contributing guidelines](https://github.com/zricethezav/gitleaks/blob/master/README.md).
## Secured by Jit
We use [Jit](https://www.jit.io/jit-open-source-gitleaks?utm_source=github&utm_medium=readme&utm_campaign=GitleaksReadme&utm_id=oss&items=item-secret-detection) to secure our codebase, to achieve fully automated, full-stack continuous security using the world's best OSS security tools.
## Sponsorships ## Sponsorships
<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>
<a href="https://www.typeform.com/">
<img src="https://user-images.githubusercontent.com/15034943/146945294-a6473d55-86b8-4f53-941e-7f185ad6b3d7.png" width=200/>
</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:
``` ```
0 - no leaks present 0 - no leaks present
1 - leaks or error encountered 1 - leaks or error encountered
+55 -10
View File
@@ -16,9 +16,10 @@ const (
func main() { func main() {
configRules := []*config.Rule{} configRules := []*config.Rule{}
configRules = append(configRules, rules.AgeSecretKey())
configRules = append(configRules, rules.AdobeClientID()) configRules = append(configRules, rules.AdobeClientID())
configRules = append(configRules, rules.AdobeClientSecret()) configRules = append(configRules, rules.AdobeClientSecret())
configRules = append(configRules, rules.AgeSecretKey())
configRules = append(configRules, rules.AlgoliaApiKey())
configRules = append(configRules, rules.AlibabaAccessKey()) configRules = append(configRules, rules.AlibabaAccessKey())
configRules = append(configRules, rules.AlibabaSecretKey()) configRules = append(configRules, rules.AlibabaSecretKey())
configRules = append(configRules, rules.AsanaClientID()) configRules = append(configRules, rules.AsanaClientID())
@@ -27,42 +28,58 @@ func main() {
configRules = append(configRules, rules.AWS()) configRules = append(configRules, rules.AWS())
configRules = append(configRules, rules.BitBucketClientID()) configRules = append(configRules, rules.BitBucketClientID())
configRules = append(configRules, rules.BitBucketClientSecret()) configRules = append(configRules, rules.BitBucketClientSecret())
configRules = append(configRules, rules.BittrexAccessKey())
configRules = append(configRules, rules.BittrexSecretKey())
configRules = append(configRules, rules.Beamer()) configRules = append(configRules, rules.Beamer())
configRules = append(configRules, rules.CoinbaseAccessToken())
configRules = append(configRules, rules.Clojars()) configRules = append(configRules, rules.Clojars())
configRules = append(configRules, rules.ConfluentAccessToken())
configRules = append(configRules, rules.ConfluentSecretKey())
configRules = append(configRules, rules.Contentful()) configRules = append(configRules, rules.Contentful())
configRules = append(configRules, rules.Databricks()) configRules = append(configRules, rules.Databricks())
configRules = append(configRules, rules.DatadogtokenAccessToken())
configRules = append(configRules, rules.DiscordAPIToken()) configRules = append(configRules, rules.DiscordAPIToken())
configRules = append(configRules, rules.DiscordClientID()) configRules = append(configRules, rules.DiscordClientID())
configRules = append(configRules, rules.DiscordClientSecret()) configRules = append(configRules, rules.DiscordClientSecret())
configRules = append(configRules, rules.Doppler())
configRules = append(configRules, rules.DropBoxAPISecret()) configRules = append(configRules, rules.DropBoxAPISecret())
configRules = append(configRules, rules.DropBoxLongLivedAPIToken()) configRules = append(configRules, rules.DropBoxLongLivedAPIToken())
configRules = append(configRules, rules.DropBoxShortLivedAPIToken()) configRules = append(configRules, rules.DropBoxShortLivedAPIToken())
configRules = append(configRules, rules.Doppler()) configRules = append(configRules, rules.DroneciAccessToken())
configRules = append(configRules, rules.Duffel()) configRules = append(configRules, rules.Duffel())
configRules = append(configRules, rules.Dynatrace()) configRules = append(configRules, rules.Dynatrace())
configRules = append(configRules, rules.EasyPost()) configRules = append(configRules, rules.EasyPost())
configRules = append(configRules, rules.EasyPostTestAPI()) configRules = append(configRules, rules.EasyPostTestAPI())
configRules = append(configRules, rules.EtsyAccessToken())
configRules = append(configRules, rules.Facebook()) configRules = append(configRules, rules.Facebook())
configRules = append(configRules, rules.FastlyAPIToken()) configRules = append(configRules, rules.FastlyAPIToken())
configRules = append(configRules, rules.FinicityClientSecret()) configRules = append(configRules, rules.FinicityClientSecret())
configRules = append(configRules, rules.FinicityAPIToken()) configRules = append(configRules, rules.FinicityAPIToken())
configRules = append(configRules, rules.FlickrAccessToken())
configRules = append(configRules, rules.FinnhubAccessToken())
configRules = append(configRules, rules.FlutterwavePublicKey()) configRules = append(configRules, rules.FlutterwavePublicKey())
configRules = append(configRules, rules.FlutterwaveSecretKey()) configRules = append(configRules, rules.FlutterwaveSecretKey())
configRules = append(configRules, rules.FlutterwaveSecretKey()) configRules = append(configRules, rules.FlutterwaveEncKey())
configRules = append(configRules, rules.FrameIO()) configRules = append(configRules, rules.FrameIO())
configRules = append(configRules, rules.GenericCredential()) configRules = append(configRules, rules.FreshbooksAccessToken())
configRules = append(configRules, rules.GoCardless()) configRules = append(configRules, rules.GoCardless())
// TODO figure out what makes sense for GCP // TODO figure out what makes sense for GCP
// configRules = append(configRules, rules.GCPServiceAccount()) // configRules = append(configRules, rules.GCPServiceAccount())
configRules = append(configRules, rules.GCPAPIKey())
configRules = append(configRules, rules.GitHubPat()) configRules = append(configRules, rules.GitHubPat())
configRules = append(configRules, rules.GitHubOauth()) configRules = append(configRules, rules.GitHubOauth())
configRules = append(configRules, rules.GitHubApp()) configRules = append(configRules, rules.GitHubApp())
configRules = append(configRules, rules.GitHubRefresh()) configRules = append(configRules, rules.GitHubRefresh())
configRules = append(configRules, rules.Gitlab()) configRules = append(configRules, rules.Gitlab())
configRules = append(configRules, rules.GitterAccessToken())
configRules = append(configRules, rules.Hashicorp()) configRules = append(configRules, rules.Hashicorp())
configRules = append(configRules, rules.Heroku()) configRules = append(configRules, rules.Heroku())
configRules = append(configRules, rules.HubSpot()) configRules = append(configRules, rules.HubSpot())
configRules = append(configRules, rules.Intercom()) configRules = append(configRules, rules.Intercom())
configRules = append(configRules, rules.KrakenAccessToken())
configRules = append(configRules, rules.KucoinAccessToken())
configRules = append(configRules, rules.KucoinSecretKey())
configRules = append(configRules, rules.LaunchDarklyAccessToken())
configRules = append(configRules, rules.LinearAPIToken()) configRules = append(configRules, rules.LinearAPIToken())
configRules = append(configRules, rules.LinearClientSecret()) configRules = append(configRules, rules.LinearClientSecret())
configRules = append(configRules, rules.LinkedinClientID()) configRules = append(configRules, rules.LinkedinClientID())
@@ -74,21 +91,31 @@ func main() {
configRules = append(configRules, rules.MailGunPrivateAPIToken()) configRules = append(configRules, rules.MailGunPrivateAPIToken())
configRules = append(configRules, rules.MailGunSigningKey()) configRules = append(configRules, rules.MailGunSigningKey())
configRules = append(configRules, rules.MapBox()) configRules = append(configRules, rules.MapBox())
configRules = append(configRules, rules.MattermostAccessToken())
configRules = append(configRules, rules.MessageBirdAPIToken()) configRules = append(configRules, rules.MessageBirdAPIToken())
configRules = append(configRules, rules.MessageBirdClientID()) configRules = append(configRules, rules.MessageBirdClientID())
configRules = append(configRules, rules.NetlifyAccessToken())
configRules = append(configRules, rules.NewRelicUserID()) configRules = append(configRules, rules.NewRelicUserID())
configRules = append(configRules, rules.NewRelicUserKey()) configRules = append(configRules, rules.NewRelicUserKey())
configRules = append(configRules, rules.NewRelicBrowserAPIKey()) configRules = append(configRules, rules.NewRelicBrowserAPIKey())
configRules = append(configRules, rules.NPM()) configRules = append(configRules, rules.NPM())
configRules = append(configRules, rules.NytimesAccessToken())
configRules = append(configRules, rules.PlaidAccessID())
configRules = append(configRules, rules.PlaidAccessToken())
configRules = append(configRules, rules.PlanetScalePassword()) configRules = append(configRules, rules.PlanetScalePassword())
configRules = append(configRules, rules.PlanetScaleToken()) configRules = append(configRules, rules.PlanetScaleAPIToken())
configRules = append(configRules, rules.PlanetScaleOAuthToken())
configRules = append(configRules, rules.PostManAPI()) configRules = append(configRules, rules.PostManAPI())
configRules = append(configRules, rules.PrivateKey()) configRules = append(configRules, rules.PrivateKey())
configRules = append(configRules, rules.PulumiAPIToken()) configRules = append(configRules, rules.PulumiAPIToken())
configRules = append(configRules, rules.PyPiUploadToken()) configRules = append(configRules, rules.PyPiUploadToken())
configRules = append(configRules, rules.RubyGemsAPIToken()) configRules = append(configRules, rules.RubyGemsAPIToken())
configRules = append(configRules, rules.RapidAPIAccessToken())
configRules = append(configRules, rules.SendbirdAccessID())
configRules = append(configRules, rules.SendbirdAccessToken())
configRules = append(configRules, rules.SendGridAPIToken()) configRules = append(configRules, rules.SendGridAPIToken())
configRules = append(configRules, rules.SendInBlueAPIToken()) configRules = append(configRules, rules.SendInBlueAPIToken())
configRules = append(configRules, rules.SentryAccessToken())
configRules = append(configRules, rules.ShippoAPIToken()) configRules = append(configRules, rules.ShippoAPIToken())
configRules = append(configRules, rules.ShopifyAccessToken()) configRules = append(configRules, rules.ShopifyAccessToken())
configRules = append(configRules, rules.ShopifyCustomAccessToken()) configRules = append(configRules, rules.ShopifyCustomAccessToken())
@@ -97,11 +124,32 @@ func main() {
configRules = append(configRules, rules.SlackAccessToken()) configRules = append(configRules, rules.SlackAccessToken())
configRules = append(configRules, rules.SlackWebHook()) configRules = append(configRules, rules.SlackWebHook())
configRules = append(configRules, rules.StripeAccessToken()) configRules = append(configRules, rules.StripeAccessToken())
configRules = append(configRules, rules.SquareAccessToken())
configRules = append(configRules, rules.SquareSpaceAccessToken())
configRules = append(configRules, rules.SumoLogicAccessID())
configRules = append(configRules, rules.SumoLogicAccessToken())
configRules = append(configRules, rules.Twilio()) configRules = append(configRules, rules.Twilio())
configRules = append(configRules, rules.TwitchAPIToken()) configRules = append(configRules, rules.TwitchAPIToken())
configRules = append(configRules, rules.Twitter()) configRules = append(configRules, rules.TwitterAPIKey())
configRules = append(configRules, rules.TwitterAPISecret())
configRules = append(configRules, rules.TwitterAccessToken())
configRules = append(configRules, rules.TwitterAccessSecret())
configRules = append(configRules, rules.TwitterBearerToken())
configRules = append(configRules, rules.Typeform()) configRules = append(configRules, rules.Typeform())
configRules = append(configRules, rules.YandexAPIKey())
configRules = append(configRules, rules.YandexAWSAccessToken())
configRules = append(configRules, rules.YandexAccessToken())
configRules = append(configRules, rules.GenericCredential())
// ensure rules have unique ids
ruleLookUp := make(map[string]bool)
for _, rule := range configRules {
// check if rule is in ruleLookUp
if _, ok := ruleLookUp[rule.RuleID]; ok {
log.Fatal().Msgf("rule id %s is not unique", rule.RuleID)
}
ruleLookUp[rule.RuleID] = true
}
config := config.Config{ config := config.Config{
Rules: configRules, Rules: configRules,
} }
@@ -110,13 +158,10 @@ func main() {
log.Fatal().Err(err).Msg("Failed to parse template") log.Fatal().Err(err).Msg("Failed to parse template")
} }
f, err := os.Create("gitleaks.toml") f, err := os.Create("../../../config/gitleaks.toml")
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("Failed to create rules.toml") log.Fatal().Err(err).Msg("Failed to create rules.toml")
} }
tmpl.Execute(f, config) tmpl.Execute(f, config)
} }
// TODO introduce skiplists:
// https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/wordlist-skipfish.fuzz.txt
+7 -8
View File
@@ -1,8 +1,7 @@
package rules package rules
import ( import (
"regexp" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -11,16 +10,16 @@ func AdobeClientID() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Adobe Client ID (Oauth Web)", Description: "Adobe Client ID (Oauth Web)",
RuleID: "adobe-client-id", RuleID: "adobe-client-id",
Regex: generateSemiGenericRegex([]string{"adobe"}, hex32), Regex: generateSemiGenericRegex([]string{"adobe"}, hex("32")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{"adobe"}, Keywords: []string{"adobe"},
} }
// validate // validate
tps := []string{ tps := []string{
"adobeClient := \"" + sampleHex32Token + "\"", generateSampleSecret("adobe", secrets.NewSecret(hex("32"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
func AdobeClientSecret() *config.Rule { func AdobeClientSecret() *config.Rule {
@@ -28,13 +27,13 @@ func AdobeClientSecret() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Adobe Client Secret", Description: "Adobe Client Secret",
RuleID: "adobe-client-secret", RuleID: "adobe-client-secret",
Regex: regexp.MustCompile(`(p8e-)(?i)[a-z0-9]{32}`), Regex: generateUniqueTokenRegex(`(p8e-)(?i)[a-z0-9]{32}`),
Keywords: []string{"p8e-"}, Keywords: []string{"p8e-"},
} }
// validate // validate
tps := []string{ tps := []string{
"adobeClient := \"p8e-" + sampleHex32Token + "\"", "adobeClient := \"p8e-" + secrets.NewSecret(hex("32")) + "\"",
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+1 -1
View File
@@ -19,5 +19,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) return validate(r, tps, nil)
} }
+22
View File
@@ -0,0 +1,22 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func AlgoliaApiKey() *config.Rule {
// define rule
r := config.Rule{
Description: "Algolia API Key",
RuleID: "algolia-api-key",
Regex: generateSemiGenericRegex([]string{"algolia"}, `[a-z0-9]{32}`),
Keywords: []string{"algolia"},
}
// validate
tps := []string{
"algolia_key := " + secrets.NewSecret(hex("32")),
}
return validate(r, tps, nil)
}
+7 -8
View File
@@ -1,8 +1,7 @@
package rules package rules
import ( import (
"regexp" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -11,15 +10,15 @@ func AlibabaAccessKey() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Alibaba AccessKey ID", Description: "Alibaba AccessKey ID",
RuleID: "alibaba-access-key-id", RuleID: "alibaba-access-key-id",
Regex: regexp.MustCompile(`(LTAI)(?i)[a-z0-9]{20}`), Regex: generateUniqueTokenRegex(`(LTAI)(?i)[a-z0-9]{20}`),
Keywords: []string{"LTAI"}, Keywords: []string{"LTAI"},
} }
// validate // validate
tps := []string{ tps := []string{
"alibabaKey := \"LTAI" + sampleHex20Token + "\"", "alibabaKey := \"LTAI" + secrets.NewSecret(hex("20")) + "\"",
} }
return validate(r, tps) return validate(r, tps, nil)
} }
// TODO // TODO
@@ -29,14 +28,14 @@ func AlibabaSecretKey() *config.Rule {
Description: "Alibaba Secret Key", Description: "Alibaba Secret Key",
RuleID: "alibaba-secret-key", RuleID: "alibaba-secret-key",
Regex: generateSemiGenericRegex([]string{"alibaba"}, Regex: generateSemiGenericRegex([]string{"alibaba"},
alphaNumeric30), alphaNumeric("30")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{"alibaba"}, Keywords: []string{"alibaba"},
} }
// validate // validate
tps := []string{ tps := []string{
"alibabaSecret Key:= \"" + sampleAlphaNumeric30Token + "\"", generateSampleSecret("alibaba", secrets.NewSecret(alphaNumeric("30"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+8 -6
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -9,16 +10,16 @@ func AsanaClientID() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Asana Client ID", Description: "Asana Client ID",
RuleID: "asana-client-id", RuleID: "asana-client-id",
Regex: generateSemiGenericRegex([]string{"asana"}, numeric16), Regex: generateSemiGenericRegex([]string{"asana"}, numeric("16")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{"asana"}, Keywords: []string{"asana"},
} }
// validate // validate
tps := []string{ tps := []string{
"asanaKey := \"" + sampleNumeric16 + "\"", generateSampleSecret("asana", secrets.NewSecret(numeric("16"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
func AsanaClientSecret() *config.Rule { func AsanaClientSecret() *config.Rule {
@@ -26,13 +27,14 @@ func AsanaClientSecret() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Asana Client Secret", Description: "Asana Client Secret",
RuleID: "asana-client-secret", RuleID: "asana-client-secret",
Regex: generateSemiGenericRegex([]string{"asana"}, alphaNumeric32), Regex: generateSemiGenericRegex([]string{"asana"}, alphaNumeric("32")),
SecretGroup: 1,
Keywords: []string{"asana"}, Keywords: []string{"asana"},
} }
// validate // validate
tps := []string{ tps := []string{
"asanaKey := \"" + sampleAlphaNumeric32Token + "\"", generateSampleSecret("asana", secrets.NewSecret(alphaNumeric("32"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+6 -4
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -9,14 +10,15 @@ func Atlassian() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Atlassian API token", Description: "Atlassian API token",
RuleID: "atlassian-api-token", RuleID: "atlassian-api-token",
Regex: generateSemiGenericRegex([]string{"atlassian"}, alphaNumeric24), Regex: generateSemiGenericRegex([]string{"atlassian", "confluence"}, alphaNumeric("24")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{"atlassian"}, Keywords: []string{"atlassian", "confluence"},
} }
// validate // validate
tps := []string{ tps := []string{
"atlassian:= \"" + sampleAlphaNumeric24Token + "\"", generateSampleSecret("atlassian", secrets.NewSecret(alphaNumeric("24"))),
generateSampleSecret("confluence", secrets.NewSecret(alphaNumeric("24"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+2 -2
View File
@@ -26,6 +26,6 @@ func AWS() *config.Rule {
} }
// validate // validate
tps := []string{"AWSToken := \"" + "AKIALALEMEL33243OLIB" + "\""} // gitleaks:allow tps := []string{generateSampleSecret("AWS", "AKIALALEMEL33243OLIB")} // gitleaks:allow
return validate(r, tps) return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -17,7 +18,7 @@ func Beamer() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
"beamer := \"b_" + sampleAlphaNumeric32Token + "-_=_xxxxxxxx\"", generateSampleSecret("beamer", "b_"+secrets.NewSecret(alphaNumericExtended("44"))),
} }
return validate(r, tps) return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -9,16 +10,16 @@ func BitBucketClientID() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "BitBucket Client ID", Description: "BitBucket Client ID",
RuleID: "bitbucket-client-id", RuleID: "bitbucket-client-id",
Regex: generateSemiGenericRegex([]string{"bitbucket"}, alphaNumeric32), Regex: generateSemiGenericRegex([]string{"bitbucket"}, alphaNumeric("32")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{"bitbucket"}, Keywords: []string{"bitbucket"},
} }
// validate // validate
tps := []string{ tps := []string{
"bitbucket := \"" + sampleAlphaNumeric32Token + "\"", generateSampleSecret("bitbucket", secrets.NewSecret(alphaNumeric("32"))),
} }
return validate(r, tps) return 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: "BitBucket Client Secret", Description: "BitBucket Client Secret",
RuleID: "bitbucket-client-secret", RuleID: "bitbucket-client-secret",
Regex: generateSemiGenericRegex([]string{"bitbucket"}, extendedAlphaNumeric64), Regex: generateSemiGenericRegex([]string{"bitbucket"}, alphaNumericExtended("64")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{"bitbucket"}, Keywords: []string{"bitbucket"},
} }
// validate // validate
tps := []string{ tps := []string{
"bitbucket := \"" + sampleExtendedAlphaNumeric64Token + "\"", generateSampleSecret("bitbucket", secrets.NewSecret(alphaNumeric("64"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+40
View File
@@ -0,0 +1,40 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func BittrexAccessKey() *config.Rule {
// define rule
r := config.Rule{
Description: "Bittrex Access Key",
RuleID: "bittrex-access-key",
Regex: generateSemiGenericRegex([]string{"bittrex"}, alphaNumeric("32")),
SecretGroup: 1,
Keywords: []string{"bittrex"},
}
// validate
tps := []string{
generateSampleSecret("bittrex", secrets.NewSecret(alphaNumeric("32"))),
}
return validate(r, tps, nil)
}
func BittrexSecretKey() *config.Rule {
// define rule
r := config.Rule{
Description: "Bittrex Secret Key",
RuleID: "bittrex-secret-key",
Regex: generateSemiGenericRegex([]string{"bittrex"}, alphaNumeric("32")),
SecretGroup: 1,
Keywords: []string{"bittrex"},
}
// validate
tps := []string{
generateSampleSecret("bittrex", secrets.NewSecret(alphaNumeric("32"))),
}
return validate(r, tps, nil)
}
+4 -3
View File
@@ -3,6 +3,7 @@ package rules
import ( import (
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -11,13 +12,13 @@ func Clojars() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Clojars API token", Description: "Clojars API token",
RuleID: "clojars-api-token", RuleID: "clojars-api-token",
Regex: regexp.MustCompile(`(CLOJARS_)(?i)[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{
"clojarsAPIToken := \"CLOJARS_" + sampleAlphaNumeric60Token + "\"", generateSampleSecret("clojars", "CLOJARS_"+secrets.NewSecret(alphaNumeric("60"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+27
View File
@@ -0,0 +1,27 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func CoinbaseAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "coinbase-access-token",
Description: "Coinbase Access Token",
Regex: generateSemiGenericRegex([]string{"coinbase"},
alphaNumericExtendedShort("64")),
SecretGroup: 1,
Keywords: []string{
"coinbase",
},
}
// validate
tps := []string{
generateSampleSecret("coinbase",
secrets.NewSecret(alphaNumericExtendedShort("64"))),
}
return validate(r, tps, nil)
}
+23 -8
View File
@@ -1,24 +1,39 @@
# This file has been auto-generated. Do not edit manually.
# If you would like to contribute new rules, please use
# cmd/generate/config/main.go and follow the contributing guidelines
# at https://github.com/zricethezav/gitleaks/blob/master/CONTRIBUTING.md
# This is the default gitleaks configuration file. # This is the default gitleaks configuration file.
# Rules and allowlists are defined within this file. # Rules and allowlists are defined within this file.
# Rules instruct gitleaks on what should be considered a secret. # Rules instruct gitleaks on what should be considered a secret.
# Allowlists instruct gitleaks on what is allowed, i.e. not a secret. # Allowlists instruct gitleaks on what is allowed, i.e. not a secret.
title = "gitleaks config" title = "gitleaks config"
[allowlist] [allowlist]
description = "global allow lists" description = "global allow lists"
regexes = [
'''219-09-9999''',
'''078-05-1120''',
'''(9[0-9]{2}|666)-\d{2}-\d{4}''',
]
paths = [ paths = [
'''gitleaks.toml''', '''gitleaks.toml''',
'''(.*?)(jpg|gif|doc|pdf|bin|svg|socket)$''', '''(.*?)(jpg|gif|doc|docx|zip|xls|pdf|bin|svg|socket)$''',
'''(go.mod|go.sum)$''' '''(go.mod|go.sum)$''',
'''node_modules''',
'''vendor''',
] ]
{{ range $i, $rule := .Rules }}[[rules]] {{ range $i, $rule := .Rules }}[[rules]]
{{ if and $rule.SecretGroup $rule.Entropy }}description = "{{$rule.Description}}" {{ if and $rule.SecretGroup $rule.Entropy $rule.Allowlist.StopWords }}description = "{{$rule.Description}}"
id = "{{$rule.RuleID}}"
regex = '''{{$rule.Regex}}'''
secretGroup = {{ $rule.SecretGroup }}
entropy = {{ $rule.Entropy}}
keywords = [
{{ range $j, $keyword := $rule.Keywords }}"{{$keyword}}",{{end}}
]
[rules.allowlist]
stopwords= [{{ range $j, $stopword := $rule.Allowlist.StopWords }}
"{{$stopword}}",{{end}}
]
{{ else if and $rule.SecretGroup $rule.Entropy }}description = "{{$rule.Description}}"
id = "{{$rule.RuleID}}" id = "{{$rule.RuleID}}"
regex = '''{{$rule.Regex}}''' regex = '''{{$rule.Regex}}'''
secretGroup = {{ $rule.SecretGroup }} secretGroup = {{ $rule.SecretGroup }}
+44
View File
@@ -0,0 +1,44 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func ConfluentSecretKey() *config.Rule {
// define rule
r := config.Rule{
RuleID: "confluent-secret-key",
Description: "Confluent Secret Key",
Regex: generateSemiGenericRegex([]string{"confluent"}, alphaNumeric("64")),
SecretGroup: 1,
Keywords: []string{
"confluent",
},
}
// validate
tps := []string{
generateSampleSecret("confluent", secrets.NewSecret(alphaNumeric("64"))),
}
return validate(r, tps, nil)
}
func ConfluentAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "confluent-access-token",
Description: "Confluent Access Token",
Regex: generateSemiGenericRegex([]string{"confluent"}, alphaNumeric("16")),
SecretGroup: 1,
Keywords: []string{
"confluent",
},
}
// validate
tps := []string{
generateSampleSecret("confluent", secrets.NewSecret(alphaNumeric("16"))),
}
return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -10,14 +11,14 @@ func Contentful() *config.Rule {
Description: "Contentful delivery API token", Description: "Contentful delivery API token",
RuleID: "contentful-delivery-api-token", RuleID: "contentful-delivery-api-token",
Regex: generateSemiGenericRegex([]string{"contentful"}, Regex: generateSemiGenericRegex([]string{"contentful"},
`[a-z0-9\-=_]{43}`), alphaNumericExtended("43")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{"contentful"}, Keywords: []string{"contentful"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("contentful", sampleExtendedAlphaNumeric43Token), generateSampleSecret("contentful", secrets.NewSecret(alphaNumeric("43"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+4 -5
View File
@@ -1,8 +1,7 @@
package rules package rules
import ( import (
"regexp" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -11,13 +10,13 @@ func Databricks() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Databricks API token", Description: "Databricks API token",
RuleID: "databricks-api-token", RuleID: "databricks-api-token",
Regex: regexp.MustCompile(`dapi[a-h0-9]{32}`), Regex: generateUniqueTokenRegex(`dapi[a-h0-9]{32}`),
Keywords: []string{"dapi"}, Keywords: []string{"dapi"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("databricks", "dapi"+sampleHex32Token), generateSampleSecret("databricks", "dapi"+secrets.NewSecret(hex("32"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+26
View File
@@ -0,0 +1,26 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func DatadogtokenAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "datadog-access-token",
Description: "Datadog Access Token",
Regex: generateSemiGenericRegex([]string{"datadog"},
alphaNumeric("40")),
SecretGroup: 1,
Keywords: []string{
"datadog",
},
}
// validate
tps := []string{
generateSampleSecret("datadog", secrets.NewSecret(alphaNumeric("40"))),
}
return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -9,16 +10,16 @@ func DiscordAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Discord API key", Description: "Discord API key",
RuleID: "discord-api-token", RuleID: "discord-api-token",
Regex: generateSemiGenericRegex([]string{"discord"}, hex64), Regex: generateSemiGenericRegex([]string{"discord"}, hex("64")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{"discord"}, Keywords: []string{"discord"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("discord", sampleHex64Token), generateSampleSecret("discord", secrets.NewSecret(hex("64"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
func DiscordClientID() *config.Rule { func DiscordClientID() *config.Rule {
@@ -26,16 +27,16 @@ func DiscordClientID() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Discord client ID", Description: "Discord client ID",
RuleID: "discord-client-id", RuleID: "discord-client-id",
Regex: generateSemiGenericRegex([]string{"discord"}, numeric18), Regex: generateSemiGenericRegex([]string{"discord"}, numeric("18")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{"discord"}, Keywords: []string{"discord"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("discord", sampleNumeric18), generateSampleSecret("discord", secrets.NewSecret(numeric("18"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
func DiscordClientSecret() *config.Rule { func DiscordClientSecret() *config.Rule {
@@ -43,14 +44,14 @@ func DiscordClientSecret() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Discord client secret", Description: "Discord client secret",
RuleID: "discord-client-secret", RuleID: "discord-client-secret",
Regex: generateSemiGenericRegex([]string{"discord"}, extendedAlphaNumeric32), Regex: generateSemiGenericRegex([]string{"discord"}, alphaNumericExtended("32")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{"discord"}, Keywords: []string{"discord"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("discord", sampleExtendedAlphaNumeric32Token), generateSampleSecret("discord", secrets.NewSecret(numeric("32"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+3 -2
View File
@@ -3,6 +3,7 @@ package rules
import ( import (
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -17,9 +18,9 @@ func Doppler() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("doppler", "dp.pt."+sampleAlphaNumeric43Token), generateSampleSecret("doppler", "dp.pt."+secrets.NewSecret(alphaNumeric("43"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
// TODO add additional doppler formats: // TODO add additional doppler formats:
+25
View File
@@ -0,0 +1,25 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func DroneciAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "droneci-access-token",
Description: "Droneci Access Token",
Regex: generateSemiGenericRegex([]string{"droneci"}, alphaNumeric("32")),
SecretGroup: 1,
Keywords: []string{
"droneci",
},
}
// validate
tps := []string{
generateSampleSecret("droneci", secrets.NewSecret(alphaNumeric("32"))),
}
return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -8,17 +9,17 @@ func DropBoxAPISecret() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Dropbox API secret", Description: "Dropbox API secret",
RuleID: "doppler-api-token", RuleID: "dropbox-api-token",
Regex: generateSemiGenericRegex([]string{"dropbox"}, alphaNumeric15), Regex: generateSemiGenericRegex([]string{"dropbox"}, alphaNumeric("15")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{"dropbox"}, Keywords: []string{"dropbox"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("dropbox", sampleAlphaNumeric15Token), generateSampleSecret("dropbox", secrets.NewSecret(alphaNumeric("15"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
func DropBoxShortLivedAPIToken() *config.Rule { func DropBoxShortLivedAPIToken() *config.Rule {
+3 -2
View File
@@ -3,6 +3,7 @@ package rules
import ( import (
"regexp" "regexp"
"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 Duffel() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("duffel", "duffel_test_"+sampleExtendedAlphaNumeric43Token), generateSampleSecret("duffel", "duffel_test_"+secrets.NewSecret(alphaNumericExtended("43"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+3 -2
View File
@@ -3,6 +3,7 @@ package rules
import ( import (
"regexp" "regexp"
"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 Dynatrace() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("dynatrace", "dt0c01."+sampleAlphaNumeric24Token+"."+sampleAlphaNumeric64Token), generateSampleSecret("dynatrace", "dt0c01."+secrets.NewSecret(alphaNumeric("24"))+"."+secrets.NewSecret(alphaNumeric("64"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+5 -4
View File
@@ -3,6 +3,7 @@ package rules
import ( import (
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -17,9 +18,9 @@ func EasyPost() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("EZAK", "EZAK"+sampleAlphaNumeric54Token), generateSampleSecret("EZAK", "EZAK"+secrets.NewSecret(alphaNumeric("54"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
func EasyPostTestAPI() *config.Rule { func EasyPostTestAPI() *config.Rule {
@@ -33,7 +34,7 @@ func EasyPostTestAPI() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("EZTK", "EZTK"+sampleAlphaNumeric54Token), generateSampleSecret("EZTK", "EZTK"+secrets.NewSecret(alphaNumeric("54"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+25
View File
@@ -0,0 +1,25 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func EtsyAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "etsy-access-token",
Description: "Etsy Access Token",
Regex: generateSemiGenericRegex([]string{"etsy"}, alphaNumeric("24")),
SecretGroup: 1,
Keywords: []string{
"etsy",
},
}
// validate
tps := []string{
generateSampleSecret("etsy", secrets.NewSecret(alphaNumeric("24"))),
}
return validate(r, tps, nil)
}
+6 -4
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -9,13 +10,14 @@ func Facebook() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "facebook", Description: "facebook",
RuleID: "facebook", RuleID: "facebook",
Regex: generateSemiGenericRegex([]string{"facebook"}, Regex: generateSemiGenericRegex([]string{"facebook"}, hex("32")),
hex32),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{"facebook"}, Keywords: []string{"facebook"},
} }
// validate // validate
tps := []string{"facebookToken := \"" + sampleHex32Token + "\""} tps := []string{
return validate(r, tps) generateSampleSecret("facebook", secrets.NewSecret(hex("32"))),
}
return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -9,14 +10,14 @@ func FastlyAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Fastly API key", Description: "Fastly API key",
RuleID: "fastly-api-token", RuleID: "fastly-api-token",
Regex: generateSemiGenericRegex([]string{"fastly"}, extendedAlphaNumeric32), Regex: generateSemiGenericRegex([]string{"fastly"}, alphaNumericExtended("32")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{"fastly"}, Keywords: []string{"fastly"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("fastly", sampleExtendedAlphaNumeric32Token), generateSampleSecret("fastly", secrets.NewSecret(alphaNumericExtended("32"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+7 -17
View File
@@ -1,10 +1,8 @@
package rules package rules
import ( import (
"github.com/rs/zerolog/log" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/detect"
) )
func FinicityClientSecret() *config.Rule { func FinicityClientSecret() *config.Rule {
@@ -12,24 +10,16 @@ func FinicityClientSecret() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Finicity Client Secret", Description: "Finicity Client Secret",
RuleID: "finicity-client-secret", RuleID: "finicity-client-secret",
Regex: generateSemiGenericRegex([]string{"finicity"}, alphaNumeric20), Regex: generateSemiGenericRegex([]string{"finicity"}, alphaNumeric("20")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{"finicity"}, Keywords: []string{"finicity"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("finicity", sampleAlphaNumeric20Token), generateSampleSecret("finicity", secrets.NewSecret(alphaNumeric("20"))),
} }
d := detect.NewDetector(config.Config{ return validate(r, tps, nil)
Rules: []*config.Rule{&r},
})
for _, tp := range tps {
if len(d.DetectString(tp)) != 1 {
log.Fatal().Msg("Failed to validate finicity-client-secret")
}
}
return &r
} }
func FinicityAPIToken() *config.Rule { func FinicityAPIToken() *config.Rule {
@@ -37,14 +27,14 @@ func FinicityAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Finicity API token", Description: "Finicity API token",
RuleID: "finicity-api-token", RuleID: "finicity-api-token",
Regex: generateSemiGenericRegex([]string{"finicity"}, hex32), Regex: generateSemiGenericRegex([]string{"finicity"}, hex("32")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{"finicity"}, Keywords: []string{"finicity"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("finicity", sampleHex32Token), generateSampleSecret("finicity", secrets.NewSecret(hex("32"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+25
View File
@@ -0,0 +1,25 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func FinnhubAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "finnhub-access-token",
Description: "Finnhub Access Token",
Regex: generateSemiGenericRegex([]string{"finnhub"}, alphaNumeric("20")),
SecretGroup: 1,
Keywords: []string{
"finnhub",
},
}
// validate
tps := []string{
generateSampleSecret("finnhub", secrets.NewSecret(alphaNumeric("20"))),
}
return validate(r, tps, nil)
}
+25
View File
@@ -0,0 +1,25 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func FlickrAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "flickr-access-token",
Description: "Flickr Access Token",
Regex: generateSemiGenericRegex([]string{"flickr"}, alphaNumeric("32")),
SecretGroup: 1,
Keywords: []string{
"flickr",
},
}
// validate
tps := []string{
generateSampleSecret("flickr", secrets.NewSecret(alphaNumeric("32"))),
}
return validate(r, tps, nil)
}
+11 -10
View File
@@ -3,6 +3,7 @@ package rules
import ( import (
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -17,39 +18,39 @@ func FlutterwavePublicKey() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("flutterwavePubKey", "FLWPUBK_TEST-"+sampleHex32Token+"-X"), generateSampleSecret("flutterwavePubKey", "FLWPUBK_TEST-"+secrets.NewSecret(hex("32"))+"-X"),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
func FlutterwaveSecretKey() *config.Rule { func FlutterwaveSecretKey() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Finicity Secret Key", Description: "Flutterwave Secret Key",
RuleID: "flutterwave-public-key", RuleID: "flutterwave-secret-key",
Regex: regexp.MustCompile(`FLWSECK_TEST-(?i)[a-h0-9]{32}-X`), Regex: regexp.MustCompile(`FLWSECK_TEST-(?i)[a-h0-9]{32}-X`),
Keywords: []string{"FLWSECK_TEST"}, Keywords: []string{"FLWSECK_TEST"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("flutterwavePubKey", "FLWSECK_TEST-"+sampleHex32Token+"-X"), generateSampleSecret("flutterwavePubKey", "FLWSECK_TEST-"+secrets.NewSecret(hex("32"))+"-X"),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
func FlutterwaveEncKey() *config.Rule { func FlutterwaveEncKey() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "Finicity Secret Key", Description: "Flutterwave Encryption Key",
RuleID: "flutterwave-public-key", RuleID: "flutterwave-encryption-key",
Regex: regexp.MustCompile(`FLWSECK_TEST-(?i)[a-h0-9]{12}`), Regex: regexp.MustCompile(`FLWSECK_TEST-(?i)[a-h0-9]{12}`),
Keywords: []string{"FLWSECK_TEST"}, Keywords: []string{"FLWSECK_TEST"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("flutterwavePubKey", "FLWSECK_TEST-"+sampleHex12Token), generateSampleSecret("flutterwavePubKey", "FLWSECK_TEST-"+secrets.NewSecret(hex("12"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+3 -2
View File
@@ -3,6 +3,7 @@ package rules
import ( import (
"regexp" "regexp"
"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 FrameIO() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("frameio", "fio-u-"+sampleExtendedAlphaNumeric64Token), generateSampleSecret("frameio", "fio-u-"+secrets.NewSecret(alphaNumericExtended("64"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+25
View File
@@ -0,0 +1,25 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func FreshbooksAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "freshbooks-access-token",
Description: "Freshbooks Access Token",
Regex: generateSemiGenericRegex([]string{"freshbooks"}, alphaNumeric("64")),
SecretGroup: 1,
Keywords: []string{
"freshbooks",
},
}
// validate
tps := []string{
generateSampleSecret("freshbooks", secrets.NewSecret(alphaNumeric("64"))),
}
return validate(r, tps, nil)
}
+21 -1
View File
@@ -3,6 +3,7 @@ package rules
import ( import (
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -20,5 +21,24 @@ func GCPServiceAccount() *config.Rule {
tps := []string{ tps := []string{
`"type": "service_account"`, `"type": "service_account"`,
} }
return validate(r, tps) return validate(r, tps, nil)
}
func GCPAPIKey() *config.Rule {
// define rule
r := config.Rule{
RuleID: "gcp-api-key",
Description: "GCP API key",
Regex: generateUniqueTokenRegex(`AIza[0-9A-Za-z\\-_]{35}`),
SecretGroup: 1,
Keywords: []string{
"AIza",
},
}
// validate
tps := []string{
generateSampleSecret("gcp", secrets.NewSecret(`AIza[0-9A-Za-z\\-_]{35}`)),
}
return validate(r, tps, nil)
} }
+18 -6
View File
@@ -11,11 +11,11 @@ func GenericCredential() *config.Rule {
Description: "Generic API Key", Description: "Generic API Key",
Regex: generateSemiGenericRegex([]string{ Regex: generateSemiGenericRegex([]string{
"key", "key",
"api[^Version]", "api",
"token", "token",
"pat",
"secret", "secret",
"client", "client",
"passwd",
"password", "password",
"auth", "auth",
}, `[0-9a-z\-_.=]{10,150}`), }, `[0-9a-z\-_.=]{10,150}`),
@@ -26,16 +26,28 @@ func GenericCredential() *config.Rule {
"token", "token",
"secret", "secret",
"client", "client",
"pat", "passwd",
"password", "password",
"auth", "auth",
}, },
Entropy: 3.7, Entropy: 3.5,
Allowlist: config.Allowlist{
StopWords: DefaultStopWords,
},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("generic", "8dyfuiRyq=vVc3RRr_edRk-fK__JItpZ"), generateSampleSecret("generic", "CLOJARS_34bf0e88955ff5a1c328d6a7491acc4f48e865a7b8dd4d70a70749037443"),
generateSampleSecret("generic", "Zf3D0LXCM3EIMbgJpUNnkRtOfOueHznB"),
`"client_id" : "0afae57f3ccfd9d7f5767067bc48b30f719e271ba470488056e37ab35d4b6506"`,
`"client_secret" : "6da89121079f83b2eb6acccf8219ea982c3d79bccc3e9c6a85856480661f8fde",`,
} }
return validate(r, tps) fps := []string{
`client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.client-vpn-endpoint.id`,
`password combination.
R5: Regulatory--21`,
}
return validate(r, tps, fps)
} }
+18 -8
View File
@@ -3,6 +3,7 @@ package rules
import ( import (
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -16,8 +17,10 @@ func GitHubPat() *config.Rule {
} }
// validate // validate
tps := []string{"gihubPAT := \"ghp_" + sampleAlphaNumeric36Token + "\""} tps := []string{
return validate(r, tps) generateSampleSecret("github", "ghp_"+secrets.NewSecret(alphaNumeric("36"))),
}
return validate(r, tps, nil)
} }
func GitHubOauth() *config.Rule { func GitHubOauth() *config.Rule {
@@ -30,8 +33,10 @@ func GitHubOauth() *config.Rule {
} }
// validate // validate
tps := []string{"gihubAuth := \"gho_" + sampleAlphaNumeric36Token + "\""} tps := []string{
return validate(r, tps) generateSampleSecret("github", "gho_"+secrets.NewSecret(alphaNumeric("36"))),
}
return validate(r, tps, nil)
} }
func GitHubApp() *config.Rule { func GitHubApp() *config.Rule {
@@ -44,8 +49,11 @@ func GitHubApp() *config.Rule {
} }
// validate // validate
tps := []string{"gihubAuth := \"ghs_" + sampleAlphaNumeric36Token + "\""} tps := []string{
return validate(r, tps) generateSampleSecret("github", "ghu_"+secrets.NewSecret(alphaNumeric("36"))),
generateSampleSecret("github", "ghs_"+secrets.NewSecret(alphaNumeric("36"))),
}
return validate(r, tps, nil)
} }
func GitHubRefresh() *config.Rule { func GitHubRefresh() *config.Rule {
@@ -58,6 +66,8 @@ func GitHubRefresh() *config.Rule {
} }
// validate // validate
tps := []string{"gihubAuth := \"ghr_" + sampleAlphaNumeric36Token + "\""} tps := []string{
return validate(r, tps) generateSampleSecret("github", "ghr_"+secrets.NewSecret(alphaNumeric("36"))),
}
return validate(r, tps, nil)
} }
+5 -2
View File
@@ -3,6 +3,7 @@ package rules
import ( import (
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -16,6 +17,8 @@ func Gitlab() *config.Rule {
} }
// validate // validate
tps := []string{"gitlabPAT := \"glpat-" + sampleAlphaNumeric20Token + "\""} tps := []string{
return validate(r, tps) generateSampleSecret("gitlab", "glpat-"+secrets.NewSecret(alphaNumeric("20"))),
}
return validate(r, tps, nil)
} }
+27
View File
@@ -0,0 +1,27 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func GitterAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "gitter-access-token",
Description: "Gitter Access Token",
Regex: generateSemiGenericRegex([]string{"gitter"},
alphaNumericExtendedShort("40")),
SecretGroup: 1,
Keywords: []string{
"gitter",
},
}
// validate
tps := []string{
generateSampleSecret("gitter",
secrets.NewSecret(alphaNumericExtendedShort("40"))),
}
return validate(r, tps, nil)
}
+4 -2
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -10,6 +11,7 @@ func GoCardless() *config.Rule {
RuleID: "gocardless-api-token", RuleID: "gocardless-api-token",
Description: "GoCardless API token", Description: "GoCardless API token",
Regex: generateSemiGenericRegex([]string{"gocardless"}, `live_(?i)[a-z0-9\-_=]{40}`), Regex: generateSemiGenericRegex([]string{"gocardless"}, `live_(?i)[a-z0-9\-_=]{40}`),
SecretGroup: 1,
Keywords: []string{ Keywords: []string{
"live_", "live_",
"gocardless", "gocardless",
@@ -18,7 +20,7 @@ func GoCardless() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("gocardless", "live_"+sampleExtendedAlphaNumeric40Token), generateSampleSecret("gocardless", "live_"+secrets.NewSecret(alphaNumericExtended("40"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+3 -2
View File
@@ -3,6 +3,7 @@ package rules
import ( import (
"regexp" "regexp"
"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 Hashicorp() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("hashicorpToken", sampleHex14Token+".atlasv1."+sampleExtendedAlphaNumeric64Token), generateSampleSecret("hashicorpToken", secrets.NewSecret(hex("14"))+".atlasv1."+secrets.NewSecret(alphaNumericExtended("60,70"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+2 -3
View File
@@ -9,8 +9,7 @@ func Heroku() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Heroku API Key", Description: "Heroku API Key",
RuleID: "heroku-api-key", RuleID: "heroku-api-key",
Regex: generateSemiGenericRegex([]string{"heroku"}, Regex: generateSemiGenericRegex([]string{"heroku"}, hex8_4_4_4_12()),
`[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}`),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{"heroku"}, Keywords: []string{"heroku"},
} }
@@ -19,5 +18,5 @@ func Heroku() *config.Rule {
tps := []string{ tps := []string{
`const HEROKU_KEY = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow `const HEROKU_KEY = "12345678-ABCD-ABCD-ABCD-1234567890AB"`, // gitleaks:allow
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+1 -1
View File
@@ -19,5 +19,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) return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -9,14 +10,14 @@ func Intercom() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Intercom API Token", Description: "Intercom API Token",
RuleID: "intercom-api-key", RuleID: "intercom-api-key",
Regex: generateSemiGenericRegex([]string{"intercom"}, extendedAlphaNumeric60), Regex: generateSemiGenericRegex([]string{"intercom"}, alphaNumericExtended("60")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{"intercom"}, Keywords: []string{"intercom"},
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("intercom", sampleExtendedAlphaNumeric60Token), generateSampleSecret("intercom", secrets.NewSecret(alphaNumericExtended("60"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+27
View File
@@ -0,0 +1,27 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func KrakenAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "kraken-access-token",
Description: "Kraken Access Token",
Regex: generateSemiGenericRegex([]string{"kraken"},
alphaNumericExtendedLong("80,90")),
SecretGroup: 1,
Keywords: []string{
"kraken",
},
}
// validate
tps := []string{
generateSampleSecret("kraken",
secrets.NewSecret(alphaNumericExtendedLong("80,90"))),
}
return validate(r, tps, nil)
}
+44
View File
@@ -0,0 +1,44 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func KucoinAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "kucoin-access-token",
Description: "Kucoin Access Token",
Regex: generateSemiGenericRegex([]string{"kucoin"}, hex("24")),
SecretGroup: 1,
Keywords: []string{
"kucoin",
},
}
// validate
tps := []string{
generateSampleSecret("kucoin", secrets.NewSecret(hex("24"))),
}
return validate(r, tps, nil)
}
func KucoinSecretKey() *config.Rule {
// define rule
r := config.Rule{
RuleID: "kucoin-secret-key",
Description: "Kucoin Secret Key",
Regex: generateSemiGenericRegex([]string{"kucoin"}, hex8_4_4_4_12()),
SecretGroup: 1,
Keywords: []string{
"kucoin",
},
}
// validate
tps := []string{
generateSampleSecret("kucoin", secrets.NewSecret(hex8_4_4_4_12())),
}
return validate(r, tps, nil)
}
+25
View File
@@ -0,0 +1,25 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func LaunchDarklyAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "launchdarkly-access-token",
Description: "Launchdarkly Access Token",
Regex: generateSemiGenericRegex([]string{"launchdarkly"}, alphaNumericExtended("40")),
SecretGroup: 1,
Keywords: []string{
"launchdarkly",
},
}
// validate
tps := []string{
generateSampleSecret("launchdarkly", secrets.NewSecret(alphaNumericExtended("40"))),
}
return validate(r, tps, nil)
}
+7 -5
View File
@@ -3,6 +3,7 @@ package rules
import ( import (
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -17,9 +18,9 @@ func LinearAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("linear", "lin_api_"+sampleAlphaNumeric40Token), generateSampleSecret("linear", "lin_api_"+secrets.NewSecret(alphaNumeric("40"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
func LinearClientSecret() *config.Rule { func LinearClientSecret() *config.Rule {
@@ -27,13 +28,14 @@ func LinearClientSecret() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Linear Client Secret", Description: "Linear Client Secret",
RuleID: "linear-client-secret", RuleID: "linear-client-secret",
Regex: generateSemiGenericRegex([]string{"linear"}, hex32), Regex: generateSemiGenericRegex([]string{"linear"}, hex("32")),
Keywords: []string{"linear"}, Keywords: []string{"linear"},
SecretGroup: 1,
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("linear", sampleHex32Token), generateSampleSecret("linear", secrets.NewSecret(hex("32"))),
} }
return validate(r, tps) return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -12,7 +13,7 @@ func LinkedinClientSecret() *config.Rule {
Regex: generateSemiGenericRegex([]string{ Regex: generateSemiGenericRegex([]string{
"linkedin", "linkedin",
"linked-in", "linked-in",
}, alphaNumeric16), }, alphaNumeric("16")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{ Keywords: []string{
"linkedin", "linkedin",
@@ -22,9 +23,9 @@ func LinkedinClientSecret() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("linkedin", sampleAlphaNumeric16Token), generateSampleSecret("linkedin", secrets.NewSecret(alphaNumeric("16"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
func LinkedinClientID() *config.Rule { func LinkedinClientID() *config.Rule {
@@ -35,7 +36,7 @@ func LinkedinClientID() *config.Rule {
Regex: generateSemiGenericRegex([]string{ Regex: generateSemiGenericRegex([]string{
"linkedin", "linkedin",
"linked-in", "linked-in",
}, alphaNumeric14), }, alphaNumeric("14")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{ Keywords: []string{
"linkedin", "linkedin",
@@ -45,7 +46,7 @@ func LinkedinClientID() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("linkedin", sampleAlphaNumeric14Token), generateSampleSecret("linkedin", secrets.NewSecret(alphaNumeric("14"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+7 -4
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -10,6 +11,7 @@ func LobPubAPIToken() *config.Rule {
Description: "Lob Publishable API Key", Description: "Lob Publishable API Key",
RuleID: "lob-pub-api-key", RuleID: "lob-pub-api-key",
Regex: generateSemiGenericRegex([]string{"lob"}, `(test|live)_pub_[a-f0-9]{31}`), Regex: generateSemiGenericRegex([]string{"lob"}, `(test|live)_pub_[a-f0-9]{31}`),
SecretGroup: 1,
Keywords: []string{ Keywords: []string{
"test_pub", "test_pub",
"live_pub", "live_pub",
@@ -19,9 +21,9 @@ func LobPubAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("lob", "test_pub_"+sampleHex31Token), generateSampleSecret("lob", "test_pub_"+secrets.NewSecret(hex("31"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
func LobAPIToken() *config.Rule { func LobAPIToken() *config.Rule {
@@ -34,11 +36,12 @@ func LobAPIToken() *config.Rule {
"test_", "test_",
"live_", "live_",
}, },
SecretGroup: 1,
} }
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("lob", "test_"+sampleHex35Token), generateSampleSecret("lob", "test_"+secrets.NewSecret(hex("35"))),
} }
return validate(r, tps) return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -18,7 +19,7 @@ func MailChimp() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("mailchimp", sampleHex32Token+"-us20"), generateSampleSecret("mailchimp", secrets.NewSecret(hex("32"))+"-us20"),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+7 -25
View File
@@ -1,10 +1,8 @@
package rules package rules
import ( import (
"github.com/rs/zerolog/log" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/detect"
) )
func MailGunPrivateAPIToken() *config.Rule { func MailGunPrivateAPIToken() *config.Rule {
@@ -21,17 +19,9 @@ func MailGunPrivateAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("mailgun", "key-"+sampleHex32Token), generateSampleSecret("mailgun", "key-"+secrets.NewSecret(hex("32"))),
} }
d := detect.NewDetector(config.Config{ return validate(r, tps, nil)
Rules: []*config.Rule{&r},
})
for _, tp := range tps {
if len(d.DetectString(tp)) != 1 {
log.Fatal().Msg("Failed to validate mailgun-private-api-token")
}
}
return &r
} }
func MailGunPubAPIToken() *config.Rule { func MailGunPubAPIToken() *config.Rule {
@@ -48,17 +38,9 @@ func MailGunPubAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("mailgun", "pubkey-"+sampleHex32Token), generateSampleSecret("mailgun", "pubkey-"+secrets.NewSecret(hex("32"))),
} }
d := detect.NewDetector(config.Config{ return validate(r, tps, nil)
Rules: []*config.Rule{&r},
})
for _, tp := range tps {
if len(d.DetectString(tp)) != 1 {
log.Fatal().Msg("Failed to validate mailgun-pub-key")
}
}
return &r
} }
func MailGunSigningKey() *config.Rule { func MailGunSigningKey() *config.Rule {
@@ -75,7 +57,7 @@ func MailGunSigningKey() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("mailgun", sampleHex32Token+"-00001111-22223333"), generateSampleSecret("mailgun", secrets.NewSecret(hex("32"))+"-00001111-22223333"),
} }
return validate(r, tps) return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -16,7 +17,7 @@ func MapBox() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("mapbox", "pk."+sampleAlphaNumeric60Token+"."+sampleAlphaNumeric22Token), generateSampleSecret("mapbox", "pk."+secrets.NewSecret(alphaNumeric("60"))+"."+secrets.NewSecret(alphaNumeric("22"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+25
View File
@@ -0,0 +1,25 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func MattermostAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "mattermost-access-token",
Description: "Mattermost Access Token",
Regex: generateSemiGenericRegex([]string{"mattermost"}, alphaNumeric("26")),
SecretGroup: 1,
Keywords: []string{
"mattermost",
},
}
// validate
tps := []string{
generateSampleSecret("mattermost", secrets.NewSecret(alphaNumeric("26"))),
}
return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -13,7 +14,7 @@ func MessageBirdAPIToken() *config.Rule {
"messagebird", "messagebird",
"message-bird", "message-bird",
"message_bird", "message_bird",
}, alphaNumeric25), }, alphaNumeric("25")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{ Keywords: []string{
"messagebird", "messagebird",
@@ -24,11 +25,11 @@ func MessageBirdAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("messagebird", sampleAlphaNumeric25Token), generateSampleSecret("messagebird", secrets.NewSecret(alphaNumeric("25"))),
generateSampleSecret("message-bird", sampleAlphaNumeric25Token), generateSampleSecret("message-bird", secrets.NewSecret(alphaNumeric("25"))),
generateSampleSecret("message_bird", sampleAlphaNumeric25Token), generateSampleSecret("message_bird", secrets.NewSecret(alphaNumeric("25"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
func MessageBirdClientID() *config.Rule { func MessageBirdClientID() *config.Rule {
@@ -40,7 +41,7 @@ func MessageBirdClientID() *config.Rule {
"messagebird", "messagebird",
"message-bird", "message-bird",
"message_bird", "message_bird",
}, `[a-h0-9]{8}-[a-h0-9]{4}-[a-h0-9]{4}-[a-h0-9]{4}-[a-h0-9]{12}`), }, hex8_4_4_4_12()),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{ Keywords: []string{
"messagebird", "messagebird",
@@ -53,5 +54,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) return validate(r, tps, nil)
} }
+26
View File
@@ -0,0 +1,26 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func NetlifyAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "netlify-access-token",
Description: "Netlify Access Token",
Regex: generateSemiGenericRegex([]string{"netlify"},
alphaNumericExtended("40,46")),
SecretGroup: 1,
Keywords: []string{
"netlify",
},
}
// validate
tps := []string{
generateSampleSecret("netlify", secrets.NewSecret(alphaNumericExtended("40,46"))),
}
return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -22,9 +23,9 @@ func NewRelicUserID() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("new-relic", "NRAK-"+sampleAlphaNumeric27Token), generateSampleSecret("new-relic", "NRAK-"+secrets.NewSecret(alphaNumeric("27"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
func NewRelicUserKey() *config.Rule { func NewRelicUserKey() *config.Rule {
@@ -36,7 +37,7 @@ func NewRelicUserKey() *config.Rule {
"new-relic", "new-relic",
"newrelic", "newrelic",
"new_relic", "new_relic",
}, alphaNumeric64), }, alphaNumeric("64")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{ Keywords: []string{
"new-relic", "new-relic",
@@ -47,9 +48,9 @@ func NewRelicUserKey() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("new-relic", sampleAlphaNumeric64Token), generateSampleSecret("new-relic", secrets.NewSecret(alphaNumeric("64"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
func NewRelicBrowserAPIKey() *config.Rule { func NewRelicBrowserAPIKey() *config.Rule {
@@ -70,7 +71,7 @@ func NewRelicBrowserAPIKey() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("new-relic", "NRJS-"+sampleHex19Token), generateSampleSecret("new-relic", "NRJS-"+secrets.NewSecret(hex("19"))),
} }
return validate(r, tps) return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -18,7 +19,7 @@ func NPM() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("npmAccessToken", "npm_"+sampleAlphaNumeric36Token), generateSampleSecret("npmAccessToken", "npm_"+secrets.NewSecret(alphaNumeric("36"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+29
View File
@@ -0,0 +1,29 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func NytimesAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "nytimes-access-token",
Description: "Nytimes Access Token",
Regex: generateSemiGenericRegex([]string{
"nytimes", "new-york-times,", "newyorktimes"},
alphaNumericExtended("32")),
SecretGroup: 1,
Keywords: []string{
"nytimes",
"new-york-times",
"newyorktimes",
},
}
// validate
tps := []string{
generateSampleSecret("nytimes", secrets.NewSecret(alphaNumeric("32"))),
}
return validate(r, tps, nil)
}
+44
View File
@@ -0,0 +1,44 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func PlaidAccessID() *config.Rule {
// define rule
r := config.Rule{
RuleID: "plaid-client-id",
Description: "Plaid Client ID",
Regex: generateSemiGenericRegex([]string{"plaid"}, alphaNumeric("24")),
SecretGroup: 1,
Keywords: []string{
"plaid",
},
}
// validate
tps := []string{
generateSampleSecret("plaid", secrets.NewSecret(alphaNumeric("24"))),
}
return validate(r, tps, nil)
}
func PlaidAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "plaid-api-secret",
Description: "Plaid API Secret",
Regex: generateSemiGenericRegex([]string{"plaid"}, alphaNumeric("30")),
SecretGroup: 1,
Keywords: []string{
"plaid",
},
}
// validate
tps := []string{
generateSampleSecret("plaid", secrets.NewSecret(alphaNumeric("30"))),
}
return validate(r, tps, nil)
}
+33 -7
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -9,7 +10,7 @@ func PlanetScalePassword() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "planetscale-password", RuleID: "planetscale-password",
Description: "PlanetScale password", Description: "PlanetScale password",
Regex: generateUniqueTokenRegex(`pscale_pw_(?i)[a-z0-9=\-_\.]{43}`), Regex: generateUniqueTokenRegex(`pscale_pw_(?i)[a-z0-9=\-_\.]{32,64}`),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{ Keywords: []string{
"pscale_pw_", "pscale_pw_",
@@ -18,17 +19,19 @@ func PlanetScalePassword() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("planetScalePassword", "pscale_pw_"+sampleExtendedAlphaNumeric43Token), generateSampleSecret("planetScalePassword", "pscale_pw_"+secrets.NewSecret(alphaNumericExtended("32"))),
generateSampleSecret("planetScalePassword", "pscale_pw_"+secrets.NewSecret(alphaNumericExtended("43"))),
generateSampleSecret("planetScalePassword", "pscale_pw_"+secrets.NewSecret(alphaNumericExtended("64"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
func PlanetScaleToken() *config.Rule { func PlanetScaleAPIToken() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
RuleID: "planetscale-api-token", RuleID: "planetscale-api-token",
Description: "PlanetScale API token", Description: "PlanetScale API token",
Regex: generateUniqueTokenRegex(`pscale_tkn_(?i)[a-z0-9=\-_\.]{43}`), Regex: generateUniqueTokenRegex(`pscale_tkn_(?i)[a-z0-9=\-_\.]{32,64}`),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{ Keywords: []string{
"pscale_tkn_", "pscale_tkn_",
@@ -37,7 +40,30 @@ func PlanetScaleToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("planetScalePassword", "pscale_tkn_"+sampleExtendedAlphaNumeric43Token), generateSampleSecret("planetScalePassword", "pscale_tkn_"+secrets.NewSecret(alphaNumericExtended("32"))),
generateSampleSecret("planetScalePassword", "pscale_tkn_"+secrets.NewSecret(alphaNumericExtended("43"))),
generateSampleSecret("planetScalePassword", "pscale_tkn_"+secrets.NewSecret(alphaNumericExtended("64"))),
} }
return validate(r, tps) return validate(r, tps, nil)
}
func PlanetScaleOAuthToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "planetscale-oauth-token",
Description: "PlanetScale OAuth token",
Regex: generateUniqueTokenRegex(`pscale_oauth_(?i)[a-z0-9=\-_\.]{32,64}`),
SecretGroup: 1,
Keywords: []string{
"pscale_oauth_",
},
}
// validate
tps := []string{
generateSampleSecret("planetScalePassword", "pscale_oauth_"+secrets.NewSecret(alphaNumericExtended("32"))),
generateSampleSecret("planetScalePassword", "pscale_oauth_"+secrets.NewSecret(alphaNumericExtended("43"))),
generateSampleSecret("planetScalePassword", "pscale_oauth_"+secrets.NewSecret(alphaNumericExtended("64"))),
}
return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -18,7 +19,7 @@ func PostManAPI() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("postmanAPItoken", "PMAK-"+sampleHex24Token+"-"+sampleHex34Token), generateSampleSecret("postmanAPItoken", "PMAK-"+secrets.NewSecret(hex("24"))+"-"+secrets.NewSecret(hex("34"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+9 -4
View File
@@ -11,13 +11,18 @@ func PrivateKey() *config.Rule {
r := config.Rule{ r := config.Rule{
Description: "Private Key", Description: "Private Key",
RuleID: "private-key", RuleID: "private-key",
Regex: regexp.MustCompile(`(?i)-----\s*?BEGIN[ A-Z0-9_-]*?PRIVATE KEY\s*?-----[\s\S]*?----\s*?END[ A-Z0-9_-]*? PRIVATE KEY\s*?-----`), Regex: regexp.MustCompile(`(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY-----[\s\S-]*KEY----`),
Keywords: []string{"-----BEGIN PRIVATE"}, Keywords: []string{"-----BEGIN"},
} }
// validate // validate
tps := []string{`-----BEGIN PRIVATE KEY----- tps := []string{`-----BEGIN PRIVATE KEY-----
anything anything
-----END PRIVATE KEY-----`} // gitleaks:allow -----END PRIVATE KEY-----`,
return validate(r, tps) `-----BEGIN RSA PRIVATE KEY-----
abcdefghijklmnopqrstuvwxyz
-----END RSA PRIVATE KEY-----
`,
} // gitleaks:allow
return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -18,7 +19,7 @@ func PulumiAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("pulumi-api-token", "pul-"+sampleHex40Token), generateSampleSecret("pulumi-api-token", "pul-"+secrets.NewSecret(hex("40"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+4 -14
View File
@@ -3,10 +3,8 @@ package rules
import ( import (
"regexp" "regexp"
"github.com/rs/zerolog/log" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/detect"
) )
func PyPiUploadToken() *config.Rule { func PyPiUploadToken() *config.Rule {
@@ -22,15 +20,7 @@ func PyPiUploadToken() *config.Rule {
} }
// validate // validate
tps := []string{"pypiToken := \"pypi-AgEIcHlwaS5vcmc" + sampleHex32Token + tps := []string{"pypiToken := \"pypi-AgEIcHlwaS5vcmc" + secrets.NewSecret(hex("32")) +
sampleHex32Token + "\""} secrets.NewSecret(hex("32")) + "\""}
d := detect.NewDetector(config.Config{ return validate(r, tps, nil)
Rules: []*config.Rule{&r},
})
for _, tp := range tps {
if len(d.DetectString(tp)) != 1 {
log.Fatal().Msg("Failed to validate pypi-upload-token")
}
}
return &r
} }
+27
View File
@@ -0,0 +1,27 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func RapidAPIAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "rapidapi-access-token",
Description: "RapidAPI Access Token",
Regex: generateSemiGenericRegex([]string{"rapidapi"},
alphaNumericExtendedShort("50")),
SecretGroup: 1,
Keywords: []string{
"rapidapi",
},
}
// validate
tps := []string{
generateSampleSecret("rapidapi",
secrets.NewSecret(alphaNumericExtendedShort("50"))),
}
return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -18,7 +19,7 @@ func RubyGemsAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("rubygemsAPIToken", "rubygems_"+sampleHex48Token), generateSampleSecret("rubygemsAPIToken", "rubygems_"+secrets.NewSecret(hex("48"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+46 -71
View File
@@ -16,7 +16,7 @@ const (
// identifier prefix (just an ignore group) // identifier prefix (just an ignore group)
identifierPrefix = `(?:` identifierPrefix = `(?:`
identifierSuffix = `)(?:[0-9a-z\-_\s.]{0,20})(?:'|"){0,1}` identifierSuffix = `)(?:[0-9a-z\-_\t .]{0,20})(?:[\s|']|[\s|"]){0,3}`
// commonly used assignment operators or function call // commonly used assignment operators or function call
operator = `(?:=|>|:=|\|\|:|<=|=>|:)` operator = `(?:=|>|:=|\|\|:|<=|=>|:)`
@@ -25,73 +25,7 @@ const (
// \x60 = ` // \x60 = `
secretPrefixUnique = `\b(` secretPrefixUnique = `\b(`
secretPrefix = `(?:'|\"|\s|=|\x60){0,5}(` secretPrefix = `(?:'|\"|\s|=|\x60){0,5}(`
secretSuffix = `)['|\"|\n|\r|\s|\x60]` secretSuffix = `)(?:['|\"|\n|\r|\s|\x60]|$)`
// secret regexes
hex = `[a-f0-9]`
hex32 = `[a-f0-9]{32}`
hex64 = `[a-f0-9]{64}`
alphaNumeric14 = `[a-z0-9]{14}`
alphaNumeric15 = `[a-z0-9]{15}`
alphaNumeric16 = `[a-z0-9]{16}`
alphaNumeric20 = `[a-z0-9]{20}`
alphaNumeric24 = `[a-z0-9]{24}`
alphaNumeric25 = `[a-z0-9]{25}`
alphaNumeric30 = `[a-z0-9]{30}`
alphaNumeric32 = `[a-z0-9]{32}`
alphaNumeric64 = `[a-z0-9]{64}`
numeric16 = `[0-9]{16}`
numeric18 = `[0-9]{18}`
extendedAlphaNumeric32 = `[a-z0-9=_\-]{32}`
extendedAlphaNumeric60 = `[a-z0-9_\-]{60}`
extendedAlphaNumeric64 = `[a-z0-9_\-]{64}`
// token examples
sampleHex12Token = `b0549eee7368` // gitleaks:allow
sampleHex14Token = `b0549eee7368aa` // gitleaks:allow
sampleHex16Token = `bbb0549eee7368aa` // gitleaks:allow
sampleHex19Token = `d0e94828b0549eee736` // gitleaks:allow
sampleHex20Token = `d0e94828b0549eee7368` // gitleaks:allow
sampleHex24Token = `d0e94828b0549eee73688888` // gitleaks:allow
sampleHex31Token = `d0e94828b0549eee7368e53f6cb41d1` // gitleaks:allow
sampleHex32Token = `d0e94828b0549eee7368e53f6cb41d17` // gitleaks:allow
sampleHex34Token = `d0e94828b0549eee7368e53f6cb41d17aa` // gitleaks:allow
sampleHex35Token = `d0e94828b0549eee7368e53f6cb41d17aaa` // gitleaks:allow
sampleHex40Token = `aaaaad0e94828b0549eee7368e53f6cb41d17aaa` // gitleaks:allow
sampleHex48Token = `aaaaaaaaaaaaad0e94828b0549eee7368e53f6cb41d17aaa` // gitleaks:allow
sampleHex64Token = `d0e94828b0549eee7368e53f6cb41d17d0e94828b0549eee7368e53f6cb41d17` // gitleaks:allow
sampleAlphaNumeric14Token = `00000AAAAAbbbb`
sampleAlphaNumeric15Token = `00000AAAAAbbbbb`
sampleAlphaNumeric16Token = `00000AAAAAbbbbbb`
sampleAlphaNumeric20Token = `00000AAAAAbbbbb99999`
sampleAlphaNumeric22Token = `00000AAAAAbbbbb99999qq`
sampleAlphaNumeric24Token = `00000AAAAAbbbbb99999qqqq`
sampleAlphaNumeric25Token = `00000AAAAAbbbbb99999qqqqq`
sampleAlphaNumeric27Token = `00000AAAAAbbbbb99999qqqqqqq`
sampleAlphaNumeric30Token = `00000AAAAAbbbbb99999aaaaalllll`
sampleAlphaNumeric32Token = `00000AAAAAbbbbb99999aaaaalllllzz`
sampleAlphaNumeric36Token = `00000AAAAAbbbbb9999900000AAAAAbbbbb9`
sampleAlphaNumeric40Token = `000000000AAAAAbbbbb9999900000AAAAAbbbbb9`
sampleAlphaNumeric43Token = `00000AAAAAbbbbb99999aaaaallllpppeqaaaa00000`
sampleAlphaNumeric54Token = `00000AAAAAbbbbb99999aaaaallllpppeqaaaa00000ttttttttttt`
sampleAlphaNumeric64Token = `00000AAAAAbbbbb99999aaaaalllllzz00000AAAAAbbbbb99999aaaaalllllll`
sampleNumeric16 = `1111222233334444`
sampleNumeric18 = `111122223333444422`
sampleExtendedAlphaNumeric64Token = `00000AAAAAbbbbb99999aaaaalllllzz00000AAAAAbbbbb99999aaaaalllll_-`
sampleExtendedAlphaNumeric66Token = `0000000AAAAAbbbbb99999aaaaalllllzz00000AAAAAbbbbb99999aaaaalllll_-`
sampleExtendedAlphaNumeric59Token = `AAAAAbbbbb99999aaaaalllllzz00000AAAAAbbbbb99999aaaaalllll_-`
sampleExtendedAlphaNumeric60Token = `AAAAAAbbbbb99999aaaaalllllzz00000AAAAAbbbbb99999aaaaalllll_-`
sampleExtendedAlphaNumeric40Token = `00AAAAAbbbbb99999aaaaallll_--eq-=aa00000`
sampleExtendedAlphaNumeric43Token = `00000AAAAAbbbbb99999aaaaallll_--eq-=aa00000`
sampleExtendedAlphaNumeric32Token = `00000AAAAAbbbbb99999aaaaalllll=_`
sampleExtendedAlphaNumeric20Token = `bbb99999aaaaalllll=_`
sampleAlphaNumeric60Token = `00000AAAAAbbbbb99999aaaaalllllzz00000AAAAAbbbbb99999aaaaalll`
) )
func generateSemiGenericRegex(identifiers []string, secretRegex string) *regexp.Regexp { func generateSemiGenericRegex(identifiers []string, secretRegex string) *regexp.Regexp {
@@ -120,14 +54,55 @@ func generateSampleSecret(identifier string, secret string) string {
return fmt.Sprintf("%s_api_token = \"%s\"", identifier, secret) return fmt.Sprintf("%s_api_token = \"%s\"", identifier, secret)
} }
func validate(r config.Rule, truePositives []string) *config.Rule { 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
d := detect.NewDetector(config.Config{ d := detect.NewDetector(config.Config{
Rules: []*config.Rule{&r}, Rules: []*config.Rule{&r},
Keywords: keywords,
}) })
for _, tp := range truePositives { for _, tp := range truePositives {
if len(d.DetectString(tp)) != 1 { if len(d.DetectString(tp)) != 1 {
log.Fatal().Msgf("Failed to validate %s", r.RuleID) log.Fatal().Msgf("Failed to validate (tp) %s %s", r.RuleID, tp)
}
}
for _, fp := range falsePositives {
if len(d.DetectString(fp)) != 0 {
log.Fatal().Msgf("Failed to validate (fp) %s", r.RuleID)
} }
} }
return &r 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}`
}
+44
View File
@@ -0,0 +1,44 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func SendbirdAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "sendbird-access-token",
Description: "Sendbird Access Token",
Regex: generateSemiGenericRegex([]string{"sendbird"}, hex("40")),
SecretGroup: 1,
Keywords: []string{
"sendbird",
},
}
// validate
tps := []string{
generateSampleSecret("sendbird", secrets.NewSecret(hex("40"))),
}
return validate(r, tps, nil)
}
func SendbirdAccessID() *config.Rule {
// define rule
r := config.Rule{
RuleID: "sendbird-access-id",
Description: "Sendbird Access ID",
Regex: generateSemiGenericRegex([]string{"sendbird"}, hex8_4_4_4_12()),
SecretGroup: 1,
Keywords: []string{
"sendbird",
},
}
// validate
tps := []string{
generateSampleSecret("sendbird", secrets.NewSecret(hex8_4_4_4_12())),
}
return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -18,7 +19,7 @@ func SendGridAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("sengridAPIToken", "SG."+sampleExtendedAlphaNumeric66Token), generateSampleSecret("sengridAPIToken", "SG."+secrets.NewSecret(alphaNumericExtended("66"))),
} }
return validate(r, tps) return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -18,7 +19,7 @@ func SendInBlueAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("sendinblue", "xkeysib-"+sampleHex64Token+"-"+sampleHex16Token), generateSampleSecret("sendinblue", "xkeysib-"+secrets.NewSecret(hex("64"))+"-"+secrets.NewSecret(alphaNumeric("16"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+25
View File
@@ -0,0 +1,25 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func SentryAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "sentry-access-token",
Description: "Sentry Access Token",
Regex: generateSemiGenericRegex([]string{"sentry"}, hex("64")),
SecretGroup: 1,
Keywords: []string{
"sentry",
},
}
// validate
tps := []string{
generateSampleSecret("sentry", secrets.NewSecret(hex("64"))),
}
return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -18,8 +19,8 @@ func ShippoAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("shippo", "shippo_live_"+sampleHex40Token), generateSampleSecret("shippo", "shippo_live_"+secrets.NewSecret(hex("40"))),
generateSampleSecret("shippo", "shippo_test_"+sampleHex40Token), generateSampleSecret("shippo", "shippo_test_"+secrets.NewSecret(hex("40"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+9 -43
View File
@@ -3,10 +3,8 @@ package rules
import ( import (
"regexp" "regexp"
"github.com/rs/zerolog/log" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/detect"
) )
func ShopifySharedSecret() *config.Rule { func ShopifySharedSecret() *config.Rule {
@@ -19,16 +17,8 @@ func ShopifySharedSecret() *config.Rule {
} }
// validate // validate
tps := []string{"shopifySecret := \"shpss_" + sampleHex32Token + "\""} tps := []string{"shopifySecret := \"shpss_" + secrets.NewSecret(hex("32")) + "\""}
d := detect.NewDetector(config.Config{ return validate(r, tps, nil)
Rules: []*config.Rule{&r},
})
for _, tp := range tps {
if len(d.DetectString(tp)) != 1 {
log.Fatal().Msg("Failed to validate shopify-shared-secret")
}
}
return &r
} }
func ShopifyAccessToken() *config.Rule { func ShopifyAccessToken() *config.Rule {
@@ -41,16 +31,8 @@ func ShopifyAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{"shopifyToken := \"shpat_" + sampleHex32Token + "\""} tps := []string{"shopifyToken := \"shpat_" + secrets.NewSecret(hex("32")) + "\""}
d := detect.NewDetector(config.Config{ return validate(r, tps, nil)
Rules: []*config.Rule{&r},
})
for _, tp := range tps {
if len(d.DetectString(tp)) != 1 {
log.Fatal().Msg("Failed to validate shopify-access-token")
}
}
return &r
} }
func ShopifyCustomAccessToken() *config.Rule { func ShopifyCustomAccessToken() *config.Rule {
@@ -63,16 +45,8 @@ func ShopifyCustomAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{"shopifyToken := \"shpca_" + sampleHex32Token + "\""} tps := []string{"shopifyToken := \"shpca_" + secrets.NewSecret(hex("32")) + "\""}
d := detect.NewDetector(config.Config{ return validate(r, tps, nil)
Rules: []*config.Rule{&r},
})
for _, tp := range tps {
if len(d.DetectString(tp)) != 1 {
log.Fatal().Msg("Failed to validate shopify-custom-access-token")
}
}
return &r
} }
func ShopifyPrivateAppAccessToken() *config.Rule { func ShopifyPrivateAppAccessToken() *config.Rule {
@@ -85,14 +59,6 @@ func ShopifyPrivateAppAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{"shopifyToken := \"shppa_" + sampleHex32Token + "\""} tps := []string{"shopifyToken := \"shppa_" + secrets.NewSecret(hex("32")) + "\""}
d := detect.NewDetector(config.Config{ return validate(r, tps, nil)
Rules: []*config.Rule{&r},
})
for _, tp := range tps {
if len(d.DetectString(tp)) != 1 {
log.Fatal().Msg("Failed to validate shopify-private-app-access-token")
}
}
return &r
} }
+5 -4
View File
@@ -3,6 +3,7 @@ package rules
import ( import (
"regexp" "regexp"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -24,9 +25,9 @@ func SlackAccessToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
"\"slackToken\": \"xoxb-" + sampleHex32Token + "\"", "\"slackToken\": \"xoxb-" + secrets.NewSecret(alphaNumeric("30")) + "\"",
} }
return validate(r, tps) return validate(r, tps, nil)
} }
func SlackWebHook() *config.Rule { func SlackWebHook() *config.Rule {
@@ -43,7 +44,7 @@ func SlackWebHook() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
"https://hooks.slack.com/services/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", // gitleaks:allow "https://hooks.slack.com/services/" + secrets.NewSecret(alphaNumeric("44")), // gitleaks:allow
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+36
View File
@@ -0,0 +1,36 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func SquareAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "square-access-token",
Description: "Square Access Token",
Regex: generateUniqueTokenRegex(`sq0atp-[0-9A-Za-z\-_]{22}`),
}
// validate
tps := []string{
generateSampleSecret("square", secrets.NewSecret(`sq0atp-[0-9A-Za-z\-_]{22}`)),
}
return validate(r, tps, nil)
}
func SquareSecret() *config.Rule {
// define rule
r := config.Rule{
RuleID: "square-secret",
Description: "Square Secret",
Regex: generateUniqueTokenRegex(`sq0csp-[0-9A-Za-z\\-_]{43}`),
}
// validate
tps := []string{
generateSampleSecret("square", secrets.NewSecret(`sq0csp-[0-9A-Za-z\\-_]{43}`)),
}
return validate(r, tps, nil)
}
+25
View File
@@ -0,0 +1,25 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func SquareSpaceAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "squarespace-access-token",
Description: "Squarespace Access Token",
Regex: generateSemiGenericRegex([]string{"squarespace"}, hex8_4_4_4_12()),
SecretGroup: 1,
Keywords: []string{
"squarespace",
},
}
// validate
tps := []string{
generateSampleSecret("squarespace", secrets.NewSecret(hex8_4_4_4_12())),
}
return validate(r, tps, nil)
}
File diff suppressed because it is too large. Load diff
+3 -13
View File
@@ -3,10 +3,8 @@ package rules
import ( import (
"regexp" "regexp"
"github.com/rs/zerolog/log" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/detect"
) )
func StripeAccessToken() *config.Rule { func StripeAccessToken() *config.Rule {
@@ -24,14 +22,6 @@ func StripeAccessToken() *config.Rule {
} }
// validate // validate
tps := []string{"stripeToken := \"sk_test_" + sampleHex32Token + "\""} tps := []string{"stripeToken := \"sk_test_" + secrets.NewSecret(alphaNumeric("30")) + "\""}
d := detect.NewDetector(config.Config{ return validate(r, tps, nil)
Rules: []*config.Rule{&r},
})
for _, tp := range tps {
if len(d.DetectString(tp)) != 1 {
log.Fatal().Msg("Failed to validate stripe-access-token")
}
}
return &r
} }
+46
View File
@@ -0,0 +1,46 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func SumoLogicAccessID() *config.Rule {
// define rule
r := config.Rule{
RuleID: "sumologic-access-id",
Description: "SumoLogic Access ID",
Regex: generateSemiGenericRegex([]string{"sumo"},
alphaNumeric("14")),
SecretGroup: 1,
Keywords: []string{
"sumo",
},
}
// validate
tps := []string{
generateSampleSecret("sumo", secrets.NewSecret(alphaNumeric("14"))),
}
return validate(r, tps, nil)
}
func SumoLogicAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "sumologic-access-token",
Description: "SumoLogic Access Token",
Regex: generateSemiGenericRegex([]string{"sumo"},
alphaNumeric("64")),
SecretGroup: 1,
Keywords: []string{
"sumo",
},
}
// validate
tps := []string{
generateSampleSecret("sumo", secrets.NewSecret(alphaNumeric("64"))),
}
return validate(r, tps, nil)
}
+25
View File
@@ -0,0 +1,25 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func TrelloAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "trello-access-token",
Description: "Trello Access Token",
Regex: generateSemiGenericRegex([]string{"trello"}, `[a-zA-Z-0-9]{32}`),
SecretGroup: 1,
Keywords: []string{
"trello",
},
}
// validate
tps := []string{
generateSampleSecret("trello", secrets.NewSecret(`[a-zA-Z-0-9]{32}`)),
}
return validate(r, tps, nil)
}
+3 -13
View File
@@ -3,10 +3,8 @@ package rules
import ( import (
"regexp" "regexp"
"github.com/rs/zerolog/log" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/detect"
) )
func Twilio() *config.Rule { func Twilio() *config.Rule {
@@ -20,15 +18,7 @@ func Twilio() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
"twilioAPIKey := \"SK" + sampleHex32Token + "\"", "twilioAPIKey := \"SK" + secrets.NewSecret(hex("32")) + "\"",
} }
d := detect.NewDetector(config.Config{ return validate(r, tps, nil)
Rules: []*config.Rule{&r},
})
for _, tp := range tps {
if len(d.DetectString(tp)) != 1 {
log.Fatal().Msg("Failed to validate twilio")
}
}
return &r
} }
+4 -3
View File
@@ -1,6 +1,7 @@
package rules package rules
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -9,7 +10,7 @@ func TwitchAPIToken() *config.Rule {
r := config.Rule{ r := config.Rule{
RuleID: "twitch-api-token", RuleID: "twitch-api-token",
Description: "Twitch API token", Description: "Twitch API token",
Regex: generateSemiGenericRegex([]string{"twitch"}, alphaNumeric30), Regex: generateSemiGenericRegex([]string{"twitch"}, alphaNumeric("30")),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{ Keywords: []string{
"twitch", "twitch",
@@ -18,7 +19,7 @@ func TwitchAPIToken() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("twitch", sampleAlphaNumeric30Token), generateSampleSecret("twitch", secrets.NewSecret(alphaNumeric("30"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+75 -19
View File
@@ -1,35 +1,91 @@
package rules package rules
import ( import (
"github.com/rs/zerolog/log" "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/detect"
) )
func Twitter() *config.Rule { func TwitterAPIKey() *config.Rule {
// define rule // define rule
r := config.Rule{ r := config.Rule{
Description: "twitter", Description: "twitter-api-key",
RuleID: "twitter", RuleID: "Twitter API Key",
Regex: generateSemiGenericRegex([]string{"twitter"}, Regex: generateSemiGenericRegex([]string{"twitter"}, alphaNumeric("25")),
hex+"{35,44}"),
SecretGroup: 1, SecretGroup: 1,
Keywords: []string{"twitter"}, Keywords: []string{"twitter"},
} }
// validate // validate
tps := []string{ tps := []string{
"twitterToken := \"" + sampleHex32Token + "aaaa\"", generateSampleSecret("twitter", secrets.NewSecret(alphaNumeric("25"))),
"twitterToken := `" + sampleHex32Token + "aaaa`",
} }
d := detect.NewDetector(config.Config{ return validate(r, tps, nil)
Rules: []*config.Rule{&r}, }
})
for _, tp := range tps { func TwitterAPISecret() *config.Rule {
if len(d.DetectString(tp)) != 1 { // define rule
log.Fatal().Msg("Failed to validate twitter") r := config.Rule{
} Description: "twitter-api-secret",
} RuleID: "Twitter API Secret",
return &r Regex: generateSemiGenericRegex([]string{"twitter"}, alphaNumeric("50")),
SecretGroup: 1,
Keywords: []string{"twitter"},
}
// validate
tps := []string{
generateSampleSecret("twitter", secrets.NewSecret(alphaNumeric("50"))),
}
return validate(r, tps, nil)
}
func TwitterBearerToken() *config.Rule {
// define rule
r := config.Rule{
Description: "twitter-bearer-token",
RuleID: "Twitter Bearer Token",
Regex: generateSemiGenericRegex([]string{"twitter"}, "A{22}[a-zA-Z0-9%]{80,100}"),
SecretGroup: 1,
Keywords: []string{"twitter"},
}
// validate
tps := []string{
generateSampleSecret("twitter", secrets.NewSecret("A{22}[a-zA-Z0-9%]{80,100}")),
}
return validate(r, tps, nil)
}
func TwitterAccessToken() *config.Rule {
// define rule
r := config.Rule{
Description: "twitter-access-token",
RuleID: "Twitter access token",
Regex: generateSemiGenericRegex([]string{"twitter"}, "[0-9]{15,25}-[a-zA-Z0-9]{20,40}"),
SecretGroup: 1,
Keywords: []string{"twitter"},
}
// validate
tps := []string{
generateSampleSecret("twitter", secrets.NewSecret("[0-9]{15,25}-[a-zA-Z0-9]{20,40}")),
}
return validate(r, tps, nil)
}
func TwitterAccessSecret() *config.Rule {
// define rule
r := config.Rule{
Description: "twitter-access-secret",
RuleID: "Twitter access secret",
Regex: generateSemiGenericRegex([]string{"twitter"}, alphaNumeric("45")),
SecretGroup: 1,
Keywords: []string{"twitter"},
}
// validate
tps := []string{
generateSampleSecret("twitter", secrets.NewSecret(alphaNumeric("45"))),
}
return 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/secrets"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
) )
@@ -19,7 +20,7 @@ func Typeform() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
generateSampleSecret("typeformAPIToken", "tfp_"+sampleExtendedAlphaNumeric59Token), generateSampleSecret("typeformAPIToken", "tfp_"+secrets.NewSecret(alphaNumericExtended("59"))),
} }
return validate(r, tps) return validate(r, tps, nil)
} }
+69
View File
@@ -0,0 +1,69 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
func YandexAWSAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "yandex-aws-access-token",
Description: "Yandex AWS Access Token",
Regex: generateSemiGenericRegex([]string{"yandex"},
`YC[a-zA-Z0-9_\-]{38}`),
SecretGroup: 1,
Keywords: []string{
"yandex",
},
}
// validate
tps := []string{
generateSampleSecret("yandex",
secrets.NewSecret(`YC[a-zA-Z0-9_\-]{38}`)),
}
return validate(r, tps, nil)
}
func YandexAPIKey() *config.Rule {
// define rule
r := config.Rule{
RuleID: "yandex-api-key",
Description: "Yandex API Key",
Regex: generateSemiGenericRegex([]string{"yandex"},
`AQVN[A-Za-z0-9_\-]{35,38}`),
SecretGroup: 1,
Keywords: []string{
"yandex",
},
}
// validate
tps := []string{
generateSampleSecret("yandex",
secrets.NewSecret(`AQVN[A-Za-z0-9_\-]{35,38}`)),
}
return validate(r, tps, nil)
}
func YandexAccessToken() *config.Rule {
// define rule
r := config.Rule{
RuleID: "yandex-access-token",
Description: "Yandex Access Token",
Regex: generateSemiGenericRegex([]string{"yandex"},
`t1\.[A-Z0-9a-z_-]+[=]{0,2}\.[A-Z0-9a-z_-]{86}[=]{0,2}`),
SecretGroup: 1,
Keywords: []string{
"yandex",
},
}
// validate
tps := []string{
generateSampleSecret("yandex",
secrets.NewSecret(`t1\.[A-Z0-9a-z_-]+[=]{0,2}\.[A-Z0-9a-z_-]{86}[=]{0,2}`)),
}
return validate(r, tps, nil)
}
+15
View File
@@ -0,0 +1,15 @@
// Package reggen generates text based on regex definitions
// This is a slightly altered version of https://github.com/lucasjones/reggen
package secrets
import (
"github.com/lucasjones/reggen"
)
func NewSecret(regex string) string {
g, err := reggen.NewGenerator(regex)
if err != nil {
panic(err)
}
return g.Generate(1)
}
+19 -1
View File
@@ -1,6 +1,9 @@
package config package config
import "regexp" import (
"regexp"
"strings"
)
// Allowlist allows a rule to be ignored for specific // Allowlist allows a rule to be ignored for specific
// regexes, paths, and/or commits // regexes, paths, and/or commits
@@ -16,6 +19,11 @@ type Allowlist struct {
// Commits is a slice of commit SHAs that are allowed to be ignored. // Commits is a slice of commit SHAs that are allowed to be ignored.
Commits []string Commits []string
// StopWords is a slice of stop words that are allowed to be ignored.
// This targets the _secret_, not the content of the regex match like the
// Regexes slice.
StopWords []string
} }
// CommitAllowed returns true if the commit is allowed to be ignored. // CommitAllowed returns true if the commit is allowed to be ignored.
@@ -40,3 +48,13 @@ func (a *Allowlist) PathAllowed(path string) bool {
func (a *Allowlist) RegexAllowed(s string) bool { func (a *Allowlist) RegexAllowed(s string) bool {
return anyRegexMatch(s, a.Regexes) return anyRegexMatch(s, a.Regexes)
} }
func (a *Allowlist) ContainsStopWord(s string) bool {
s = strings.ToLower(s)
for _, stopWord := range a.StopWords {
if strings.Contains(s, strings.ToLower(stopWord)) {
return true
}
}
return false
}
+20 -13
View File
@@ -4,6 +4,7 @@ import (
_ "embed" _ "embed"
"fmt" "fmt"
"regexp" "regexp"
"strings"
) )
//go:embed gitleaks.toml //go:embed gitleaks.toml
@@ -25,15 +26,17 @@ type ViperConfig struct {
Tags []string Tags []string
Allowlist struct { Allowlist struct {
Regexes []string Regexes []string
Paths []string Paths []string
Commits []string Commits []string
StopWords []string
} }
} }
Allowlist struct { Allowlist struct {
Regexes []string Regexes []string
Paths []string Paths []string
Commits []string Commits []string
StopWords []string
} }
} }
@@ -64,7 +67,9 @@ func (vc *ViperConfig) Translate() (Config, error) {
if r.Keywords == nil { if r.Keywords == nil {
r.Keywords = []string{} r.Keywords = []string{}
} else { } else {
keywords = append(keywords, r.Keywords...) for _, k := range r.Keywords {
keywords = append(keywords, strings.ToLower(k))
}
} }
if r.Tags == nil { if r.Tags == nil {
@@ -93,9 +98,10 @@ func (vc *ViperConfig) Translate() (Config, error) {
Tags: r.Tags, Tags: r.Tags,
Keywords: r.Keywords, Keywords: r.Keywords,
Allowlist: Allowlist{ Allowlist: Allowlist{
Regexes: allowlistRegexes, Regexes: allowlistRegexes,
Paths: allowlistPaths, Paths: allowlistPaths,
Commits: r.Allowlist.Commits, Commits: r.Allowlist.Commits,
StopWords: r.Allowlist.StopWords,
}, },
} }
if r.Regex != nil && r.SecretGroup > r.Regex.NumSubexp() { if r.Regex != nil && r.SecretGroup > r.Regex.NumSubexp() {
@@ -115,9 +121,10 @@ func (vc *ViperConfig) Translate() (Config, error) {
Description: vc.Description, Description: vc.Description,
Rules: rules, Rules: rules,
Allowlist: Allowlist{ Allowlist: Allowlist{
Regexes: allowlistRegexes, Regexes: allowlistRegexes,
Paths: allowlistPaths, Paths: allowlistPaths,
Commits: vc.Allowlist.Commits, Commits: vc.Allowlist.Commits,
StopWords: vc.Allowlist.StopWords,
}, },
Keywords: keywords, Keywords: keywords,
}, nil }, nil
+1961 -124
View File
File diff suppressed because it is too large. Load diff
+10 -3
View File
@@ -217,6 +217,12 @@ func (d *Detector) detectRule(fragment Fragment, rule *config.Rule) []report.Fin
finding.Secret = secret finding.Secret = secret
} }
// check if the secret is in the list of stopwords
if rule.Allowlist.ContainsStopWord(finding.Secret) ||
d.Config.Allowlist.ContainsStopWord(finding.Secret) {
continue
}
// check entropy // check entropy
entropy := shannonEntropy(finding.Secret) entropy := shannonEntropy(finding.Secret)
finding.Entropy = float32(entropy) finding.Entropy = float32(entropy)
@@ -329,7 +335,7 @@ func (d *Detector) DetectFiles(source string) ([]report.Finding, error) {
if err != nil { if err != nil {
return err return err
} }
if fInfo.Name() == ".git" { if fInfo.Name() == ".git" && fInfo.IsDir() {
return filepath.SkipDir return filepath.SkipDir
} }
if fInfo.Mode().IsRegular() { if fInfo.Mode().IsRegular() {
@@ -393,9 +399,10 @@ func (d *Detector) Detect(fragment Fragment) []report.Finding {
fragment.newlineIndices = regexp.MustCompile("\n").FindAllStringIndex(fragment.Raw, -1) fragment.newlineIndices = regexp.MustCompile("\n").FindAllStringIndex(fragment.Raw, -1)
// build keyword map for prefiltering rules // build keyword map for prefiltering rules
matches := d.prefilter.FindAll(strings.ToLower(fragment.Raw)) normalizedRaw := strings.ToLower(fragment.Raw)
matches := d.prefilter.FindAll(normalizedRaw)
for _, m := range matches { for _, m := range matches {
fragment.keywords[strings.ToLower(fragment.Raw[m.Start():m.End()])] = true fragment.keywords[normalizedRaw[m.Start():m.End()]] = true
} }
for _, rule := range d.Config.Rules { for _, rule := range d.Config.Rules {
+1
View File
@@ -22,6 +22,7 @@ func location(fragment Fragment, matchIndex []int) Location {
end := matchIndex[1] end := matchIndex[1]
for lineNum, pair := range fragment.newlineIndices { for lineNum, pair := range fragment.newlineIndices {
_lineNum = lineNum
newLineByteIndex := pair[0] newLineByteIndex := pair[0]
if prevNewLine <= start && start < newLineByteIndex { if prevNewLine <= start && start < newLineByteIndex {
lineSet = true lineSet = true
-1
View File
@@ -65,7 +65,6 @@ func filter(findings []report.Finding, redact bool) []report.Finding {
if strings.Contains(strings.ToLower(f.RuleID), "generic") { if strings.Contains(strings.ToLower(f.RuleID), "generic") {
for _, fPrime := range findings { for _, fPrime := range findings {
if f.StartLine == fPrime.StartLine && if f.StartLine == fPrime.StartLine &&
f.EndLine == fPrime.EndLine &&
f.Commit == fPrime.Commit && f.Commit == fPrime.Commit &&
f.RuleID != fPrime.RuleID && f.RuleID != fPrime.RuleID &&
strings.Contains(fPrime.Secret, f.Secret) && strings.Contains(fPrime.Secret, f.Secret) &&
+4 -3
View File
@@ -4,7 +4,7 @@ go 1.17
require ( require (
github.com/fatih/semgroup v1.2.0 github.com/fatih/semgroup v1.2.0
github.com/gitleaks/go-gitdiff v0.7.4 github.com/gitleaks/go-gitdiff v0.7.6
github.com/rs/zerolog v1.26.1 github.com/rs/zerolog v1.26.1
github.com/spf13/cobra v1.2.1 github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.8.1 github.com/spf13/viper v1.8.1
@@ -14,13 +14,14 @@ require (
require ( require (
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/h2non/filetype v1.1.3 // indirect github.com/h2non/filetype v1.1.3
github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/lucasjones/reggen v0.0.0-20200904144131-37ba4fa293bb
github.com/magiconair/properties v1.8.5 // indirect github.com/magiconair/properties v1.8.5 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/pelletier/go-toml v1.9.3 // indirect github.com/pelletier/go-toml v1.9.3 // indirect
github.com/petar-dambovaliev/aho-corasick v0.0.0-20211021192214-5ab2d9280aa9 // indirect github.com/petar-dambovaliev/aho-corasick v0.0.0-20211021192214-5ab2d9280aa9
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.6.0 // indirect github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.3.1 // indirect github.com/spf13/cast v1.3.1 // indirect
+4 -2
View File
@@ -72,8 +72,8 @@ github.com/fatih/semgroup v1.2.0/go.mod h1:1KAD4iIYfXjE4U13B48VM4z9QUwV5Tt8O4rS8
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gitleaks/go-gitdiff v0.7.4 h1:8vICc4moyRR2poklblThdQ0ckMet22mEvFJSxPsiDlk= github.com/gitleaks/go-gitdiff v0.7.6 h1:atcfoNPD9erzPs9C89a+i2Y+EUmR2QKB5QHJTfB4n60=
github.com/gitleaks/go-gitdiff v0.7.4/go.mod h1:pKz0X4YzCKZs30BL+weqBIG7mx0jl4tF1uXV9ZyNvrA= github.com/gitleaks/go-gitdiff v0.7.6/go.mod h1:pKz0X4YzCKZs30BL+weqBIG7mx0jl4tF1uXV9ZyNvrA=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
@@ -183,6 +183,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lucasjones/reggen v0.0.0-20200904144131-37ba4fa293bb h1:w1g9wNDIE/pHSTmAaUhv4TZQuPBS6GV3mMz5hkgziIU=
github.com/lucasjones/reggen v0.0.0-20200904144131-37ba4fa293bb/go.mod h1:5ELEyG+X8f+meRWHuqUOewBOhvHkl7M76pdGEansxW4=
github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls= github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls=
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
Loaded 100 of 101 files, more files were not shown because too many files have changed in this diff. Show more