130 Commits
Author SHA1 Message Date
Zachary Rice ca20267a84 its the simple things (#2020) 2026-01-08 14:48:47 -06:00
bplaxco c5ccbb9468 Respect contexts with timeouts (#1948)
rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED
2025-10-24 12:30:13 -05:00
Zachary Rice b1c9c7ecbe Composite rules (#1905)
* composite rules

* add test config

* tests

* taking care of some pr comments

* naming
2025-07-20 11:13:38 -05:00
Zachary Rice 2a7bcffd7c dont prematurely calculate fragment newlines (#1909) 2025-07-08 20:48:55 -05:00
Richard Gomez 9faaa4a09c Add experimental allowlist optimizations (#1731)
* feat(allowlist): optimization experiments

* refactor(allowlist): remove useOptimizations flag

* refactor(allowlist): simplify Validate() with helper func

* refactor(config): replace global feature flag
2025-06-08 10:33:05 -05:00
Tilo Brueckner 20f9a1d4eb Add Platform Bitbucket (#1886) 2025-06-04 19:46:01 -05:00
Tilo Brueckner 722ce8213a Add Platform Gitea (#1884) 2025-06-04 09:15:06 -05:00
bplaxcoandAlex Layne 782f310478 Archive support (#1872)
* Start Files Source

* Keep cmd the same for now

* Get tests to pass

* s.MaxTargetMegaBytes -> s.MaxFileSize

* Tweak some log messages & use q semgroup for files

* Just call yield inside the semgroup

* Refactor a check and revert some log lines

* Move mg && misc tuning

* Add `make profile`

(Benchmark results are only added if tools are installed)

Example output:

```
========================================================================
generating profile data
------------------------------------------------------------------------
- mode: dir
  benchmark:
    tool: hyperfine
    path: profile/1748019612/dir/benchmark.json
    results:
      mean: 1.12852930166
      stddev: 0.12163775966037399
      median: 1.07242928416
      user: 3.9699382799999996
      system: 0.04382341999999999
      min: 1.03207673016
      max: 1.3913475181600001
  profile:
    - mode: cpu
      path: profile/1748019612/dir/cpu.pprof
      view: go tool pprof -http=localhost: ./gitleaks profile/1748019612/dir/cpu.pprof
    - mode: mem
      path: profile/1748019612/dir/mem.pprof
      view: go tool pprof -http=localhost: ./gitleaks profile/1748019612/dir/mem.pprof
    - mode: trace
      path: profile/1748019612/dir/trace.out
      view: go tool trace profile/1748019612/dir/trace.out
- mode: git
  ...snip...
```

* Archive support for File based sources

* Move Git to Source interface

* Scan archives in git

* Misc linter fixes

* Exclude certain diffs: --diff-filter=tuxdb

* Add git archives tests

* Log error instead of fatal

* Fix spacing in test config

* Refine source comments/wording

* Make MB conversions more readable

* Format cmd

* Adjust DetectSource logging

* MiB -> MB in logs

* Add testdata/repos/archives/dotGit/refs/.gitkeep

Without it the refs folder gets deleted and the
and then it isn't detected as a git repo ¯\_(ツ)_/¯

So then the test starts scanning the whole gitleaks
repo instead :D

* Handle finding links for archives

* Working on archive depth

* Fixes from failfast test

* cmd max-archive-depth

* added comments, fixed warnings

* removed test print

* Update README.md

* Set archive depth for DetectFiles

* Tweak logs & pass max archive for readers

* Pass ctx to Fragments

* Add make lint target and address some issues

* Fix compat issue

* Report path in fragment errors

* Apply PR suggestions & misc changes

- Update blobReader.Close() to discard the buffer
- Misc logger issues & uses
- Tweak .golangci.yaml to default to none
- Discard remaining blobReader data on close
- Undo a De Morgan's Law suggestion (and disable QF1001)

* Add http mode for diagnostics

gitleaks --diagnostics=http ...
-----

From the net/http/pprof docs:

Use the pprof tool to look at the heap profile:
```
go tool pprof http://localhost:6060/debug/pprof/heap
```

Or to look at a 30-second CPU profile:
```
go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30
```

Or to look at the goroutine blocking profile, after calling runtime.SetBlockProfileRate in your program:
```
go tool pprof http://localhost:6060/debug/pprof/block
```

Or to look at the holders of contended mutexes, after calling runtime.SetMutexProfileFraction in your program:
```
go tool pprof http://localhost:6060/debug/pprof/mutex
```

(For more info see https://pkg.go.dev/net/http/pprof)

---------

Co-authored-by: Alex Layne <alayne@redhat.com>
2025-06-01 11:29:34 -05:00
Zachary Rice 0589ae0298 unicode decoding (#1854) 2025-05-14 10:14:31 -05:00
Richard Gomez f97a9ee872 chore: include decoder in debug log (#1853) 2025-05-12 21:54:55 -05:00
bplaxco 78eebaca9d Percent/URL Decoding Support (#1831)
* Add initial percent decoding support

* Refactor multi encoding support

* Add detect tests to confirm positions

* Avoid a few extra passes during decoding

* Do multiple passes for finding encodings re

* Fix issue with overlapping encodings when doing separate passes
2025-05-12 11:22:36 -05:00
Richard Gomez 88f56d3695 feat: identify slow file (#1479) 2025-05-01 07:39:13 -05:00
Zach 9609928c02 rm 1password detect test since we test it in cfg gen 2025-04-30 09:57:28 -05:00
Jordan BradfordandRichard Gomez 23cb69fba4 feat(rules): Add 1Password secret key detection (#1834)
* Add `1password-secret-key` detection

* Document key details

* Update cmd/generate/config/rules/1password.go

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

* Generate new `.toml`

* Use `GenerateSampleSecrets` to test more scenarios

* Comment lowercase `fps`

* Decrease entropy

---------

Co-authored-by: Richard Gomez <32133502+rgmz@users.noreply.github.com>
2025-04-30 09:30:58 -05:00
Richard Gomez d1c77598da fix(detect): test all allowlists (#1845) 2025-04-30 08:29:57 -05:00
Richard Gomez 4451b455f3 feat(config): define multiple global allowlists (#1777) 2025-04-29 08:49:04 -05:00
Richard Gomez b6cc71aa3a fix(baseline): work with --redact (#1741) 2025-04-13 09:40:15 -05:00
Richard Gomez cfdeb0d7e0 feat(rule): validate & sort rule when generating (#1817) 2025-04-12 10:09:19 -05:00
bplaxco 4b541044e8 Fix currentLine out of bounds error (#1810)
Because `segment.adjustMatchIndex(matchIndex)` was above
`segment.lineEndIndex(currentRaw, matchIndex[1]-matchIndex[0])` there
were cases where it would cause an out of bounds error.

This change resolves the issue by just assuming the whole segment is a
opaque chunk of text and starts at the boundaries of the segment instead
so that the order doesn't matter as much.

The other option would have been to reorder the assignments and add
tests to account for that case, but I figured this option is less likely
to have gotchas when working with different encoding formats at the
potential expense of getting an extra line or two if an encoding format
in the future ever allows multiple lines of encoded content to be
considered a single segment.
2025-04-02 20:10:47 -05:00
Joost Voskuil af7d5bcb83 add support for Azure DevOps platform in SCM detection and link (#1807)
* feat: add support for Azure DevOps platform in SCM detection and link generation

* feat: add support for visualstudio.com in Azure DevOps platform detection

* feat: consolidate Azure DevOps platform detection for dev.azure.com and visualstudio.com
2025-03-31 08:38:08 -05:00
Zachary Rice c08cb1dc9a Fix decoded line allowlist (#1788)
* fix

* B patch

* buh bye
2025-03-12 20:16:16 -05:00
bplaxco f6a7439306 Make AddFindings public (#1767)
- Rename d.addFindings -> d.AddFindings
- Add d.Findings()

To allow other tools using d.Detect() to leverage the code in
AddFindings
2025-02-24 08:28:06 -06:00
Richard Gomez c2afd56bbe Make paths and fingerprints platform-agnostic (#1622)
* test: windows

* fix: make paths platform-agnostic

this change also fixes, or skips, windows failures
2025-02-19 19:36:42 -06:00
ahrav 2020e6a9ab Add support for streaming DetectReader (#1760) 2025-02-19 07:38:34 -06:00
Richard Gomez ae26eff464 feat(git): disable link generation (#1748)
Add an option to disable link creation. If there are any weird edge cases, it shouldn't block scanning
2025-02-10 13:15:44 -06:00
Richard Gomez d2ffffecbd fix(git): remove .git suffix for links (#1716) 2025-01-21 19:17:26 -06:00
Richard Gomez a43dc0d3d0 chore: refine generic-api-key fps + trace logging (#1720) 2025-01-21 08:29:24 -06:00
Richard Gomez 3f4d91fc22 build: support either stdlib or 3rd-party regexp (#1706) 2025-01-20 10:45:31 -06:00
Richard Gomez 049f5b2435 chore(detect): update trace logging (#1713) 2025-01-20 09:30:59 -06:00
Richard Gomez 7a6183dab0 feat(git): redact passwords from remote URL (#1709) 2025-01-19 15:17:07 -06:00
Richard Gomez 3c7f3f0e08 feat(git): include link in report (#1698) 2025-01-19 14:03:57 -06:00
Richard Gomez 977236cb5f fix: unaligned 64-bit atomic operation panic (#1696) 2025-01-15 06:45:37 -06:00
Richard Gomez c4526b2c55 refactor(generic-api-key): remove hard-coded 'magic' (#1600) 2025-01-13 19:57:25 -06:00
Richard Gomez ab38a46986 refactor: central logger (#1692) 2025-01-13 08:09:22 -06:00
almaz045andAlmaz Vakhitov b69b5157a0 Entropy trace (#1659)
* I do an entropy check earlier than the others and add the info to the trace

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

* adding info into trace about entropy

* Fixed name of variables

---------

Co-authored-by: Almaz Vakhitov <a.vakhitov@vk.team>
2024-12-30 10:15:51 -06:00
Richard Gomez 4c3da6ebb7 refactor(detect): create readUntilSafeBoundary + add tests (#1676) 2024-12-28 15:14:49 -06:00
Richard Gomez efe40cae39 fix: only use non-empty secret groups (#1632) 2024-12-20 20:53:44 -06:00
ahrav a91c6717a0 replace std library regex engine with go-re2 (#1669) 2024-12-20 09:53:01 -06:00
Zachary Rice 8a8306288e log bytes (#1670) 2024-12-20 05:46:25 -06:00
Richard Gomez 0bf13fc25a feat(dir): better chunking (#1665) 2024-12-12 10:27:27 -06:00
Richard Gomez 83e99bacf1 feat(report): allow user-defined templates (#1650) 2024-12-10 18:56:11 -06:00
Richard Gomez ed205a5f63 fix(dir): skip opening file&dir if allowlist matches (#1653) 2024-12-05 08:35:42 -06:00
Richard Gomez 6018012b7e fix: increase chunk size 10kb -> 100kb (#1652) 2024-12-01 19:42:40 -06:00
Richard Gomez c1add1d268 feat(dir): continue on permission error (#1621) 2024-11-05 07:58:36 -06:00
Richard Gomez 5407c44e0c chore: log skipped symlinks (#1591) 2024-10-22 08:23:10 -05:00
Richard Gomez 9152eaa57a feat(aws): add entropy & allowlist (#1582) 2024-10-19 19:47:45 -05:00
Richard Gomez 5c03fa4a3e refactor(allowlist): use iota for condition (#1569) 2024-10-16 14:59:37 -05:00
Richard Gomez aabe381539 Define multiple allowlists per rule (#1496)
* feat: multiple rule allowlists

* feat(config): add allowlist 'condition'
2024-10-14 19:17:37 -05:00
Zach 9c354f51c3 print tags if they exist 2024-10-02 20:06:31 -05:00
bplaxcoandRichard Gomez 2278a2a97e Decode Base64 (#1488)
* Support base64 decoding during scans

rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED

* Add failing tests for the case when the match starts outside the decoded value

* Align locations for overlapping, encoded matches

rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED

* Add --max-decode-depth flag and update README help output

rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED

* Move keywords off of fragment

rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED

* Fix comment typo

rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED

* Refactor how keywords are used in detect

rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED

* Clarify comments and rename method to match

rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED

* Improve performance

rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED

* Fix issues after rebase

Only adjust matchIndex to fix the following line issue when not working
with encoded segments since they handle adjusting the index themselves.

rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED

* Update detect/decoder.go

Don't escape characters that don't need escaping

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

* Update flag help text

rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED

* Add meta data tags from decoding

rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED

---------

Co-authored-by: Richard Gomez <32133502+rgmz@users.noreply.github.com>
2024-10-02 19:33:55 -05:00