Commit Graph
45 Commits
Author SHA1 Message Date
Casey Tran d17df48451 Add test cases for escaped unicode (#4812)
The purpose of this PR is to add escaped unicode test cases for the engine tests.
2026-03-13 09:31:45 -05:00
Shahzad Haider 71c48afda8 Added detector for JFrog Artifactory Reference Tokens (#4684)
* added detector for artifactory reference tokens

* add artifactory reference token detector to the no cloud endpoints list

* address mustansir feedback; remove the invalid host deletion

* use detectors.DetectorHttpClientWithNoLocalAddresses instead of common.SaneHttpClient() just like sibling artifactory detector
2026-03-04 16:56:24 +01:00
Cody Rose 041f07e9df Move verify flag into detectableChunk (#4558)
Chunk.Verify is an odd field - it originally conveys whether a source is going to run with verification, but then, at a certain point in the scanning pipeline, is mutated such that it instead indicates whether the chunk should be scanned with verification - which is not solely dependent on the source's verify flag. This is unnecessarily difficult to understand and maintain. This commit separates those two pieces of information into two flags:

- Chunk.Verify has been renamed to Chunk.SourceVerify
- It is no longer mutated; instead "should this chunk's secrets be verified?" is now captured by a new field on detectableChunk
2026-02-27 10:05:52 -05:00
Dylan AyreyandCursor Agent 952df702b3 Base64 decoding depth assessment (#4744)
* feat: iterative decoding pipeline with configurable depth

Decoders (base64, UTF-16, escaped unicode) now chain iteratively:
each decoder's output is fed back through all decoders until no new
transformations occur or --max-decode-depth is reached (default: 5).

This finds secrets hidden inside layered encodings, e.g. a base64
Docker auth blob containing a GCP private key, or a UTF-16 file
with base64-encoded credentials.

At depth=1 behavior is identical to the previous implementation.
Extra depths exit early when no new data is produced, so the cost
is <5% wall time on a large repo scan.

Co-authored-by: Dylan Ayrey <dxa4481@rit.edu>

* docs: iterative decoding performance data

Co-authored-by: Dylan Ayrey <dxa4481@rit.edu>

* comment: explain why PLAIN decoder is skipped at depth > 0

Co-authored-by: Dylan Ayrey <dxa4481@rit.edu>

* refactor: extract iterativeDecode, address review feedback

- Extract decode loop into standalone iterativeDecode() function,
  separating decoding from channel dispatch (rosecodym, camgunz).
- Drop decodeInput struct, use []byte directly (camgunz).
- Remove redundant maxDepth clamp from scannerWorker (camgunz).
- Inline decoderType variable (camgunz).
- Replace byteSliceSeen with slices.ContainsFunc (camgunz).

Co-authored-by: Dylan Ayrey <dxa4481@rit.edu>

* fix: remove unused decodeLatency metric (lint)

Co-authored-by: Dylan Ayrey <dxa4481@rit.edu>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-02-19 21:26:37 -08:00
MustansirandKashif Khan 4158734f23 [INS-285] Fix custom detectors line number reporting to match the full regex instead of capture group (#4697)
* set the full match as primary secret for correct line number reporting

* add test case for multiline, update documentation

* update comment

* add test case to engine

* sort regexes before selecting first for deterministic behaviour

* remove leftover todo comment

---------

Co-authored-by: Kashif Khan <70996046+kashifkhan0771@users.noreply.github.com>
2026-02-09 10:52:05 +05:00
Cody Rose 4d4080bd27 remove tracker type (#4723)
There is a test seam in the engine that counts verification overlaps. This commit converts it from a bespoke mutex-wrapping-an-int type to a simple atomic integer. This is a minor thing but by gum I just love deleting code so much that I can't help myself.
2026-02-03 08:40:43 -05:00
Cody Rose a9a7416312 Unify false positive/overlap tests (#4699)
The engine tests include two tests that are almost identical: TestVerificationOverlapChunkFalsePositive and TestRetainFalsePositives. This commit unifies them into a single, table-driven test. It also deletes some fake detectors they used, because we have a different fake detector that we can use instead.
2026-01-28 15:46:43 -05:00
Cody Rose 94fdf01214 Stop using detectableChunk in processResult (#4691)
The processResult function took a detectableChunk as a parameter, but that was purely out of convenience, because callers originally happened to have that type available. We later added more callers that didn't have a detectableChunk available, so they had to synthesize one. This was tolerable, but we're exploring more refactors that will introduce processResult callers that cannot synthesize a detectableChunk (because they don't have the right information available). This PR therefore modifies the signature of processResult to require only the necessary information so that we're not sandbagged by this unrelated structure down the road.
2026-01-23 16:05:15 -05:00
Cody Rose e19b948313 Add tests for processResult (#4674)
I have a burning desire to refactor processResult, but I realized it doesn't have any tests. This commit adds some.
2026-01-16 13:34:33 -05:00
Amaan Ullah 05cccb53bc Update Azure Repos link format (#4598)
* fix(giturl): correct Azure Repos link format to use query parameters

* lineEnd should not be same as line

* update azure repos link engine test
2025-12-11 16:40:06 +05:00
Cody Rose 35a5bf210f Add some engine tests around the Verify flag (#4566)
I was poking around at a refactor idea (in #4558) and realized that it had no test coverage. This PR adds that test coverage. I think I uncovered a bug in the process - see a comment in one of the tests.
2025-11-24 13:10:11 -05:00
SyedAliHamadandAmaan Ullah 05e2328da2 [Detector]-Detector for tableau personal access token (#4261)
* add detector for tableau personal access token

* add test for tableau detector

* removed unnecessary checks

* add cloud endpoint for tableau

* cleanup: simplify map copying with maps.Copy

* resolve comments

* added correct detector type for tableau

* updated tableau PAT key and corrected integration tests

* resolved comments

* updated test cases

* resolved comments

* fixed integration tests

* removed redundant validation

* resolved false positive issue

* updated regex for pat-name

* resolved comments

* update regex for better token name extraction

* simplify prefix regex  for tableau pat name

* merged main into origin/detector/tableau-personal-access-token

---------

Co-authored-by: Amaan Ullah <aman.ullah.jalal@trufflesec.com>
2025-07-28 21:42:58 +05:00
Kashif Khan 9d5669eae2 Enabled and Enhanced Artifactory Detector (#4207)
* enhanced artifactory detector

* Enabled and enhanced artifactory detector

* fixed engine test

* removed noncapturing group
2025-06-25 16:34:44 +05:00
Kashif Khan 6cd30e17a7 [Fix] Line number issue for custom detector (#3997)
* initial commit

* initial commit

* added test cases

* fixed test cases

* removed primary secret from shopify
2025-05-16 14:27:17 -05:00
Kashif KhanandRichard Gomez 39d24534f2 fixed sentry auth token detector (#3827)
* fixed sentry auth token detector

* not sure why this is failing

* Updated http client logic

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

* resolved comments

* improved decoding logic

* removed response type

* splitted to two versions

* splitted to two versions

* this is confusing error

---------

Co-authored-by: Richard Gomez <32133502+rgmz@users.noreply.github.com>
2025-01-20 15:31:08 +05:00
Miccah 6a77b73f51 [chore] Log non-fatal errors encountered during a scan (#3612)
* [chore] Log non-fatal errors encountered during a scan

* Update tests

* Update tests
2024-11-18 16:52:22 -08:00
ahrav aeaebdd2d9 [refactor] - Add DataOrErr (#3520)
* adjust error handling to make more explicit

* Add DataOrErr

* update

* fix apk handler to use DataOrErr

* fix

* fix tests

* remove timeout as it wont ever be used
2024-11-15 18:31:07 -08:00
ahrav cca7e6bd3d [bug] - correctly capture db type for postgres detector (#3610)
* correctly capture db type for postgres detector.

* use const and rename other consts
2024-11-15 14:57:40 -08:00
joeleonjrandRichard Gomez 8f2ebc924e Add support for scanning APK files (#3517)
* apk initial

* added a couple tests

* Update pkg/handlers/handlers.go

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

* updating log status

* refactored + added new integration test

* updated test

* fixed linting error

* added keyword-value pairs during dex file scanning

* fixed test

* performance updates

* fixing decodeXML memory issue

* added feature flag

* refactored keyword matching + ahocorasick

* small updates

* refactored for dextk.WithReadCache()

---------

Co-authored-by: Richard Gomez <32133502+rgmz@users.noreply.github.com>
2024-11-15 13:25:11 -05:00
ahrav bf89c89e09 [bug] - Correct Line Number Calculation (#3550)
* correclty report line number

* add addiitonal test cases
2024-11-05 08:53:18 -08:00
Miccah 1a0cf04c3d [chore] Ensure testing Endpoints() doesn't silently pass on change (#3334)
Since Endpoints() isn't a defined interface, we are testing an
implementation detail of EndpointSetter. If that function changes in
anyway, the test will now fail instead of skipping every detector and
passing.
2024-09-25 15:27:13 -07:00
Miccah 4484bf443b [fix] Correctly initialize detectors with cloud endpoint customization (#3333)
* [fix] Correctly initialize detectors with cloud endpoint customization

We were only initializing if the detector was configured with a custom
endpoint, but not in the default case.

* Add test

* Fix gitlab.v2 detector
2024-09-25 13:06:00 -07:00
0f427b3c6a Adding Descriptions (#3258)
* adding AI generated descriptions of the key types and their capabilities

* removing empty file

* Update abbysale.go

* update to interface

* fixes

* fix

* small cleanup

---------

Co-authored-by: Dylan Ayrey <dxa4481@rit.edu>
Co-authored-by: Dustin Decker <dustin@trufflesec.com>
2024-09-24 16:10:16 -07:00
Cody Rose f39a5254ff Customize results cleaning (using smuggled interface) (#3235)
We have identified some cases in which the results "cleaning" logic (the logic that eliminates superfluous results) should not run. In order to allow this, we need to expose the cleaning logic to the engine. This PR does so by doing these things:

- Create a CustomResultsCleaner interface that can be implemented by detectors that want to use custom cleaning logic
- Implement this interface for the aws and awssessionkey detectors (and remove their previous invocation of their custom cleaning logic)
- Modify the engine to invoke this logic (conditionally)

This PR also removes the "custom" cleaning logic for the opsgenie, razorpay, and twilio detectors, because it was added erroneously.

This is an alternative implementation of #3233.
2024-08-21 09:42:20 -04:00
Harmon Herring f664472da1 Include default detectors when using a config that contains detectors (#3115)
* include default detectors when config file is used

* fix test
2024-07-29 14:36:40 -07:00
ahrav 347e8a6683 [feat] - Add Option to Retain False Positives During Detection (#2967)
* provide a mechanism to retain false positive findings

* update

* reorganzie

* revert comment

* update test

* typo

* fix test

* fix test

* update

* update
2024-06-18 09:40:21 -07:00
ahrav cb072603dc Modularize scanning engine (#2887)
* POC: Modularize scanning engine.

* fix typo

* update interface name

* fix tests

* update test

* fix moar tests

* fix bug

* fixes.

* fix merge

* add detector verification overrides

* handle --no-verification flag

* support fp

* add test

* update name

* filter

* update test

* explicit use of detector

* updates
2024-06-13 13:47:09 -07:00
ahrav 68bea576db [fix] - Refactor Filtering Logic to Fix Known False Positive Handling in Overlapping Cases (#2946)
* Filter results for verification overlap results

* add test
2024-06-11 07:25:12 -07:00
ahrav ce1ce29b90 [feat] - Optimize detector performance by reducing data passed to regex (#2812)
* optimize maching detetors

* update method name

* updates

* update naming

* updates

* update comment

* updates

* remove testcase

* update default match len to 512

* update

* update test

* add support for multpart cred provider

* add ability to scan entire chunk

* encapsulate matches logic within FindDetectorMatches

* use []byte directly

* nil chunk data

* use []byte

* set hidden flag to true

* remove

* [refactor] - multi part detectors (#2906)

* Detectors beginning w/ a

* Detectors beginning w/ b

* Detectors beginning w/ c

* Detectors beginning w/ d

* Detectors beginning w/ e

* Detectors beginning w/ f

* Detectors beginning w/ f&g

* fix

* Detectors beginning w/ i-l

* Detectors beginning w/ m-p

* Detectors beginning w/ r-s

* Detectors beginning w/ t

* Detectors beginning w/ u-z

* revert alconst

* remaining fixes

* lint

* [feat] - Add Support for `compareDetectionStrategies` Mode (#2918)

* Detector comparison mode

* remove else

* return error if results dont match

* update default hidden flag to not scan entire chunks

* fix tests

* enhance encapsulation by including methods on DetectorMatch to handle merging and extracting

* remove space

* fix

* update detector

* updates

* remove else

* run comparison concurrently
2024-06-05 13:28:19 -07:00
Cody Rose 4882d230e0 Use fake detectors in versioned detectors test (#2847)
This automated test used to run with the real GitLab detectors because they were versioned. However, the test doesn't need real detectors to actually validate the functionality in question, and relying on real detectors means that we're susceptible to token expiration, which we recently discovered when it happened. The test has been updated to use fake detectors (which means it can run correctly in the community suite as well now.)
2024-05-14 13:15:06 -04:00
Dustin Decker 14e44db2be Move detectors.IsKnownFalsePositive from the detectors and into the engine (#2643)
* Remove detectors.IsKnownFalsePositive from detectors

* Centralize false positive removal in engine

* Don't apply fp filtering on custom regex to preserve previous behavior.

* fix empty branch

* update excludes

* update filtering

* Add result flag option and exclude some detectors
2024-04-22 15:18:04 -07:00
Ryan Jacobchick 7296bcdc5d Allow CLI version pinning in GHA (#2397) (#2398)
* Allow CLI version pinning in GHA (#2397)

* prevent segfault in test-community
2024-02-07 16:58:04 -06:00
ahrav 28d079bdad use only the DetectorKey as a map field (#2374) 2024-02-05 06:53:08 -08:00
b2074ad05d Polite Verification (#2356)
* draft reverify chunks

* remove

* remove

* reduce dupe map cap

* do not verify chunk

* cli arg and use val for dupe lut

* remove counter

* skipp empty results]

* working on test and normalizing val for comparison

* forgot to save file

* optimize normalize

* reuse map

* remove print

* use levenshtein distance to check dupes

* forgot to leave in emptying map

* use slice

* small tweak

* comment

* use bytes

* praise

* use ctx logger

* add len check

* add comments

* use 8x concurrency for reverifier workers

* revert worker count

* use more workers

* process result directly for any collisions

* continue after decoder match for reverifying

* use map

* use map

* otimization and fix the bug.

* revert worker count

* better option naming

* handle identical secrets in chunks

* update comment

* update comment

* fix test

* use DetecotrKey

* rm out of scope tests and testdata

* rename all reverification elements

* don't re-write map entry

* use correct key

* rename worker, remove log val

* test likelydupe, add eq detector check in loop

* add test

* add comment

* add test

* Set verification error

* Update tests

---------

Co-authored-by: Zachary Rice <zachary.rice@trufflesec.com>
Co-authored-by: Dustin Decker <dustin@trufflesec.com>
2024-02-02 09:29:18 -08:00
Cody Rose 876a55821b Remove verify flag from Aho-Corasick core (#2010)
The Aho-Corasick wrapper we have tracks information about whether verification should be enabled on an individual detector basis, but that functionality isn't related to the matching functionality of Aho-Corasick, and including it complicates the implementation. This PR removes it to simplify some things.

This PR removes some code that supported a potential future implementation of detector-specific verification settings, but that feature has not actually been implemented yet, so there's no loss of functionality. If we want that feature we can add it back on top of this in a more separated way.
2023-10-30 09:52:51 -04:00
Cody Rose e556bdd7b2 Revert "Fix off by one (#1891)" (#1963)
This reverts commit 7f534d0bb7.
2023-10-24 08:40:44 -07:00
Shreyas Sriram 7f534d0bb7 Fix off by one (#1891) 2023-10-17 07:02:27 -07:00
ahrav 6affc903e1 add line to link for azure repos. (#1801) 2023-09-21 16:07:11 -07:00
ahrav a8c89c59b9 [bug] - fix link line (#1793)
* fix link line.

* rename.
2023-09-20 14:46:00 -07:00
ahrav 47d5ddebf2 Ability to update line number in link (#1788)
* Add functionality to update a source's link in the metadata with the updated line number.

* update comment.

* add logic to engine.

* only update link for non empty links.

* add tests for bb.
2023-09-19 15:39:13 -07:00
ahrav fdeccf06a0 cache dupes w/ different decoders (#1754)
* only cache dupes that have different decoders.

* add test.

* remove file.

* update comment.
2023-09-11 08:18:48 -07:00
Miccah eae66ccf7e Refactor FragmentLineOffset to match multiline secrets (#1612)
* Refactor FragmentLineOffset to match multiline secrets

* Add tests and benchmarks

* Use bytes.Count and fix an ignore tag edge case
2023-08-14 10:51:41 -07:00
ahrav a9213a1103 [chore] - Update loop to switch. (#1487)
* Update loop to switch.

* remove unused fxn.
2023-07-12 15:47:43 -07:00
Zachary Rice b48ac24c46 Dedupe results (#1479)
* init 4 dedupin

* use raw rather than rawv2

* rm comment

* comments

* nits

* clean up and use rawv2 too

* add decoder order test
2023-07-11 15:48:00 -05:00
Zachary Rice 18a70b64bb Introduce trufflehog:ignore tag feature (#1433)
* init ignore

* cleanup and add test

* update readme
2023-06-29 08:45:56 -05:00