Commit Graph
620 Commits
Author SHA1 Message Date
Amaan Ullah 586f66d788 use struct-based SourceMetadataFunc signature across git sources (#4813)
* use struct-based SourceMetadataFunc signature across git sources

* incorporated feedback

- pass SourceMetadataInfo by value
- remove LegacySourceMetadataFunc
2026-03-24 16:22:30 +05:00
Charlie Gunyon afd5336caa Confine symlink state handling to scanSymlink in Filesystem source (#4807)
* Confine symlink state handling to scanSymlink in Filesystem source

* Fix s.canFollowSymlinks snafu

* Update symlink tests to use starting depth 0

* Missed one

* Remove symlink checking from scanFile; this is now always handled in scanSymlink

* Confine errgroup.Groups to scanDir in the Filesystem source (#4808)

* Move path parameter after rootPath parameter in the Filesystem source

* Move the depth parameter too

* Only create an errgroup.Group inside scanDir (where it's used) in the Filesystem source
2026-03-17 11:13:10 +01:00
Charlie Gunyon bc31aa9770 Rearrange some method parameters in the Filesystem source (#4806)
* Move path parameter after rootPath parameter in the Filesystem source

* Move the depth parameter too
2026-03-11 11:21:47 +01:00
Charlie Gunyon 5fb6dfd56a Make naming more consistent in the Filesystem source (#4805)
* Make naming more consistent in the Filesystem source

* Missed one
2026-03-11 11:11:46 +01:00
Charlie Gunyon b2122e4eb2 Use trContext instead of context throughout Filesystem source (#4804) 2026-03-11 10:13:08 +01:00
Cody Rose 6c05c4a00b Stop growing filesystem resume data (#4797)
#4742 (4563dde124) introduced a change to the filesystem source resumption tracking that caused it to start growing linearly with subdirectory count - which causes the payload to get intractably big on large data sets. This commit is an attempt to resolve the issue.

Note that the resumption code still has a bug that can cause data to get inadvertently skipped due to mishandling of the internal parallelization of the scan. This bug has been present for a long time and is present in other sources, so fixing it is out of scope here.

This commit _also_ introduces a new bug related to the fact that lexicographic sorting is not completely appropriate for the resumption check. This needs to be cleaned up as a fast follow, but it's still less serious than the current bug that prevents all scans of large data sets.
2026-03-09 16:02:57 -04:00
Dustin DeckerandCursor Agent 648aca62d5 Thread original chunk data through engine pipeline (#4780)
* [secret-storage] Thread original chunk data through engine pipeline

Adds OriginalData/ChunkData fields to preserve pre-decode source data
through the scan pipeline:

1. Chunk.OriginalData: captures chunk.Data before iterativeDecode
2. engine.go: sets chunk.OriginalData = chunk.Data before decode
3. ResultWithMetadata.ChunkData: populated by CopyMetadata from
   OriginalData (falls back to Data when nil)

This enables downstream consumers (e.g. the dispatcher in thog) to
access the original source data for secret storage encryption.

* Update TestChunkSize for OriginalData field addition

Chunk struct grew from 80 to 104 bytes with the OriginalData []byte
slice header (24 bytes). Field placement is already optimal (adjacent
to Data []byte).

* fix: preserve OriginalData field in EscapedUnicode decoder

The EscapedUnicode decoder constructed a new sources.Chunk manually
copying fields but omitted OriginalData. This caused CopyMetadata to
fall back to the decoded Data instead of the original pre-decode content,
defeating the purpose of preserving original chunk data for secret
storage encryption.

* Address PR review feedback: use testify/assert, add nil-guard comment, remove stale alignment comment

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-03-03 14:34:05 -05:00
Muneeb Ullah Khan 8df943f829 [INS-331] Fix the issue causing the tests file system soruce tests to fail on windows (#4743)
* fix excludepaths flag causing the test to fail

* fixed bugbot comms
2026-03-03 15:13:41 +05: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
Brad Larsen 4f1d07f7c3 Fix typos in comments in json-enumerator source (#4764) 2026-02-24 10:41:20 -05:00
Muneeb Ullah Khan 4563dde124 [INS-283] Support following symlinks in filesystem source (#4742)
* enabled symlinks with maximum depth support

* resolved concurrency bugs and added maxDepthOption to cli

* Removed visited path map and tracked symlink depth by maintaining a counter variable

* separated symlink scanning from scanDir

* resolved bugbot comments

* introduced hash as a separator to avoid collisions
2026-02-24 20:10:16 +05:00
Muneeb Ullah KhanandKashif Khan 0de585530c [INS-309]updated google api version to v0.259.0 (#4736)
* updated google api version to v0.259.0

* fixed panic in test

---------

Co-authored-by: Kashif Khan <70996046+kashifkhan0771@users.noreply.github.com>
2026-02-23 19:57:57 +05:00
Brad Larsen c563a0692f Add a new NDJSON / JSONL input source (#4721)
This adds a new input source to TruffleHog, accessible via `trufflehog json-enumerator`.

This input source requires a list of filenames, each of which is an NDJSON-formatted sequence of objects that take one of two forms:

Form 1: `{"data": "utf-8 string", "metadata": <non-null JSON value>}`
Form 2: `{"data_b64": "base64-encoded bytestring", "metadata": <non-null JSON value>}`

The `data` / `data_b64` field specifies the content to be scanned. The `metadata` field is arbitrary, and is simply propagated downstream with scan results from the corresponding content.

Note that although `trufflehog json-enumerator` requires a list of filenames to be given, the NDJSON data that you wish to scan may not need to be first written to disk. On Linux and macOS, at least, you can use shell process substitution to set up a named pipe from a producer process, like `trufflehog json-enumerator <(some-program-that-emits-ndjson)`.
2026-02-17 10:27:57 -05:00
Mustansir daf5bf1e94 [INS-280] Fix Github "repostories" filter does not respect GHES endpoint (#4677) 2026-02-04 11:17:55 +05:00
Muneeb Ullah Khan f70218bad0 [INS-249] Updated Gitlab client from v0.129.0 to v1.12.0(latest) (#4655)
* updated gitlab client from v0.129.0 to v1.12.0(latest)

* fixed integration test

* unpinned v0.129 gitlab client and migrated code

* Migrated auth code

* Remove unused 'time' import

Removed unused 'time' import from gitlab.go

* reverted merged case statements

* splitted line like before

* splitted code into multiple lines

* resolved bugbot comments
2026-02-03 16:52:13 +05:00
Mustansir b3b1d4180a [INS-258] Revert includeRepos removal from GitHub source (#4673)
* Revert "Remove include repos (#4469)"

This reverts commit 24c73b0cb6.

* generate protos

* preserve tests for repositories
2026-01-27 19:01:50 +05:00
Mustansir 2fdab87df9 bug fix: UnitErr and UnitOK called for the same repo (#4681) 2026-01-27 19:00:31 +05:00
Pascal THUET 37994c5d59 fix(github): preserve trailing hyphens in repository names (#4695)
Fix a bug where repository names ending with a hyphen (e.g., "my-repo-")
would have the trailing hyphen stripped when parsing the URL, causing
404 errors when trying to access the repository via the GitHub API.

The issue was in getRepoURLParts() which reconstructed the URL via
url.URL.String() and then re-parsed it. This process could lose
trailing special characters in some cases.

The fix uses repoURL.Host and repoURL.Path directly instead of
reconstructing via String(), which preserves the original path
including any trailing hyphens.

Fixes #4679
2026-01-26 09:50:20 -05:00
Rusted2361andKashif Khan f946748dd9 Fix/issue 4578 path normalization for unix and windows (#4614)
* Fix Windows file:// URI normalization and index path handling

* add condition to trim leading slash only incase of windows paths

* access path from URL object and identify platform using goos

* simplified path logic

* added test cases for windows powershell & bash

---------

Co-authored-by: Kashif Khan <70996046+kashifkhan0771@users.noreply.github.com>
2026-01-19 18:37:35 +05:00
Shahzad Haider b924c0bfbe added monthly requests limit to postman api request metrics collection (#4667) 2026-01-15 23:33:49 +05:00
Gleb Haranin f3eff52825 fix: report accurate line numbers for chunked file scanning (#1876) (#4615)
Fixes #1876

Problem
Files are processed in ~13KB chunks by default (10KB of actual data plus a 3KB peek into the next chunk). To infer the line the engine would take the line from chunk's metadata SourceMetadata.Line and would consider it absolute, that is it's relative to the entire file. The problem is it was never set anywhere. Since every chunk had line equals to 1 in metadata, all secret scan results appeared at line 1 + FragmentLineOffset() which resulted in line being relative to the chunk not the file itself.

Solution
Track cumulative line numbers in handleNonArchiveContent() by counting newlines as chunks are processed. Each DataOrErr now carries the correct starting line, which flows through to SourceMetadata.Filesystem.Line, giving FragmentFirstLineAndLink() the correct fragStart for the final calculation.

Affected Sources
Directly fixed:

Filesystem - now reports accurate line numbers. I have tested it using the test file provided in the issue wget https://gist.githubusercontent.com/det/1526b4c16d0e07ac023d75c912a68658/raw/c3061c14a811205a65cbdcf0065bd3c11d88bfcb/test.txt

Not affected (no Line field in proto):

S3, GCS, Jenkins, stdin - use handlers but their metadata protos lack a Line field. I think it makes sense for S3 and GCS to report line numbers so it could be a good future change.

Partially affected (own line tracking):

Git, GitHub, GitLab - regular text diffs use git-based scanning with built-in line tracking (unaffected). However, binary archives (tar.gz, zip) go through HandleBinary() → handlers.HandleFile() and benefit from this fix.
others like BitBucket use their own implementations so not affected
2026-01-15 13:21:29 -05:00
Kashif Khan fc3f35cedd Gitlab Source: Backoff from Scan2 which is experimental to legacy pagination API call (#4608)
* Backoff from Scan2 which is experimental to legacy pagination API call

This commit rewrite simplifiedGitlabEnumeration to use legacy pagination API call with keyset pagination instead of Scan2 which is currently in experimental state. Note
that this doesn't promise to fix this problem it's just a test to check. It also adds a retry logic in case any 500 error occurs. I added some logs as well to keep track
of no of projects being enumerated.

* implemented builtin retry mechanism for gitlab and proper handling of next page

* fixed basic auth

* Some enhancements

Reversed the gitlab cloud logic to add membership flag, so that we use the default false for non gitlab.com instances.
This can help if the issue really was membership flag as mentioned in some gitlab issues.
Also added simple flag in list projects to get only minimal fields in response instead of big json response for each project.

Added test case as well.

* enhance the test case
2026-01-14 09:58:21 +05:00
Shahzad Haider 89cc34b8c4 Fix typo in help description for Postman API metric (#4656)
Fixed a small typo in the help description for the total number of Postman API requests remaining this month metric in the Postman source.
2026-01-13 18:48:19 +05:00
Mustansir 964eab023f [INS-232] Fix S3 Source "panic: runtime error: index out of range" bug (#4610)
* use separate checkpointer instance for each scanBucket call, add index out of range check in checkpointer
2026-01-09 12:39:55 +05:00
Muneeb Ullah Khan f5f43368f9 [INS-120] Increase test coverage for nested items(scanItem) function (#4648) 2026-01-09 12:04:58 +05:00
Muneeb Ullah Khan a1d997362d Fix syslog test failing due to hardcoded timestamp (#4646) 2026-01-07 18:40:45 +05:00
Mustansir a633174c3b [INS-206] Store Gitlab Project ID in secret location metadata (#4601)
* add wrapper reporter to append project details to chunk metadata

* use cache to store project details

* revert unnecessary change

* delete from cache when done with scanning in ChunkUnit, implement PR suggestions

* query project details using repo instead of having it in source unit

* revert removal of build tag

* Incorporated PR comments
2025-12-22 10:45:42 +05:00
Muneeb Ullah Khan 8c1219a4f0 [INS-207] Add Role-Aware Resumption Support for Legacy S3 Scan (#4600)
* Added roles to legacy scan resumption

* Test to verify legacy chunks resumption with roles.
2025-12-17 19:00:40 +05:00
Mustansir 8aea6cd9da [INS-226] use pinned image for quay registry test (#4602) 2025-12-15 20:35:02 +05:00
3cb2166ddd Pagination and Rate-Limit Handling In Docker Registry Namespace API Calls (#4557)
* Added pagination and retry logic on rate-limit errors in docker registry list images calls

* added rate limit error failure test

* added exponential backoff

* updated defered response body discards, added more comments, removed some unnecessary logic in Quay.ListImages()

* readded quay list images query that the requests private images

* added golang.org/x/time/rate to limit registry API calling rate

* switched to using retryable http client in docker registry calls

* modified rate limiter. created constant for max page size in api request

---------

Co-authored-by: Amaan Ullah <aman.ullah.jalal@trufflesec.com>
Co-authored-by: Kashif Khan <70996046+kashifkhan0771@users.noreply.github.com>
2025-12-15 13:09:11 +05:00
Cody Rose bf930a2cd9 fix typo (#4599)
I misspelled an identifier in one spot and then just autocompleted to victory everywhere else. This commit fixes the typo!
2025-12-10 15:16:39 -05:00
Cody Rose 702bbefa35 Add optional git clone timeout (#4597)
We have identified some cases in which it is preferable to time a clone out instead of waiting forever. These situations are unusual, so the CLI option to enable this (which I added for testing) is hidden so that we minimize the risk of baking this option into the interface.
2025-12-10 10:09:05 -05:00
Cody Rose 1d87fba935 Apply configured include/ignore lists to GitLab unit scans (#4592)
Previously, the GitLab include and ignore lists were only applied during repository enumeration, which meant that they would be ignored after enumeration completed. For large environments, post-enumeration scanning can take days, and it was awkward that the include/ignore lists could effectively not be modified during that time. This PR changes things such that repositories can be configured to be skipped even post-enumeration.

Importantly, repositories cannot be "un-ignored" post-enumeration. This is unfortunate, but this PR still represents improvement on the status quo.
2025-12-09 09:50:33 -05:00
Cody Rose f1f48726bb Add more clone logging (#4593)
This commit adds timing information to the logs when clones complete successfully. There are several other more robust but also more involved interventions we could do, and I think we should do them, but this is a strict improvement that's easy to get out as a first step.

I also added logging at the precise beginning of the clone command so we know when we're doing that.
2025-12-09 09:42:32 -05:00
Cody Rose 1a83f6bf83 skip flaky test (#4595)
This test has been super flaky, so we're disabling it until we can fix it.
2025-12-09 09:13:49 -05:00
Mustansir 2d008a57d6 [INS-204] Abort Postman scan if monthly API request limit crosses 80% (#4586) 2025-12-05 19:23:13 +05:00
MustansirandAmaan Ullah b6389e2419 [INS-104] Support units in S3 source (#4560)
* implemented Source unit for S3.
Implemented. integration test

* use bucket as source unit

* remove code duplication, reuse from Chunks

* remove unnecessary change

* remove unused functions

* revisit tests

* revert unnecessary change

* change SourceUnitKind to s3_bucket

* handle nil objectCount inside scanBucket

* handle nil objectCount outside loop

* add bucket to resume log

* add bucket and role to error log, remove enumerating log

* implement sub unit resumption

* add comment to checkpointer for unit scans

* implement SourceUnitUnmarshaller on source with the new S3SourceUnit, add test to test resumption on multiple buckets with concurrent ChunkUnit processing

* add role to SourceUnitID

* Revert "add role to SourceUnitID"

This reverts commit 549e6bede9.

* add role to source unit ID, keep track of resumption using source unit ID instead of just bucket name

* rename bucket -> unitID in UnmarshalSourceUnit

---------

Co-authored-by: Amaan Ullah <aman.ullah.jalal@trufflesec.com>
2025-12-04 12:54:28 +05:00
Nabeel Alam 674f6262ec Updated the failing Docker source Quay registry test (#4580) 2025-12-03 17:42:25 +05:00
Nabeel Alam 75c18f2523 Added Additional Metrics and Job ID in the Docker Source (#4547)
* Added new metrics and a Job ID column in Docker source

* Fixed typo in new docker images enumerated metric

* removed job_id from histogram metric
2025-12-03 16:37:51 +05:00
Nabeel Alam d416a804d5 Added API Call Metrics to Docker Source (#4552)
* Added instrumented transport to docker source api calls to include API call metric emissions

* removed once used variable assignment and setting with transport directly
2025-12-03 16:37:38 +05:00
Mustansir 21211a0e4c add response id and response name to postman metadata (#4555) 2025-12-02 14:59:57 +05:00
Cody Rose cb6aeefd6e shadow context (#4549) 2025-11-12 12:30:46 -08:00
Kashif Khan 20dccb6395 Scan all images under a namespace for Docker remote registries (#4514)
* Scan all images under a namespace for Docker remote registries

* improvements

* Resolved charlie's comment

* added logs

* formatted error messages
2025-11-06 15:08:28 +05:00
Kashif Khan daf7e5626b Implemented Graphql requests for Github PR's, Issues and comments scanning (#4431)
* Added graphql API for issues and PRs

* enhancements

* more cleanup

* more enhancements

* some final touches

* some more cleanup

* tweaked threads vars

* minor changes

* scan the markdown text not plain text

* ratelimit handling

* added ratelimit handling

* lint error fix

* refactored the thread review comments chunking

* final commit - probably

* refactored the rate limit handling

* adjusted comments

* resolved comments

* remove old camel case func

* renamed featureflag

* resolved martin's comments

* updated test cases
2025-11-04 10:13:53 +05:00
Jordan Tunstill 24c73b0cb6 Remove include repos (#4469)
* Removed redundant IncludeRepos mentions.

* removed proto for IncludeRepos and remade protos

* removed another instance of includeRepos

* reverted proto removal and

* actually deprecated the field

* ran make protos
2025-10-21 15:28:12 -07:00
Jordan TunstillandKashif Khan 0f60f6ecfe explicit repositories now bypass wantRepo() filtering entirely. added ctx to newConnector (#4507)
* explicit repositories now bypass wantRepo() filtering entirely.
added ctx to newConnector

* Added test that demonstrates this bypass

* simplified test and focused on enumeration

---------

Co-authored-by: Kashif Khan <70996046+kashifkhan0771@users.noreply.github.com>
2025-10-21 15:27:26 -07:00
joeleonjr fd007c74cc add ability to run github-experimental against private repos (#4508)
The existing implementation of github-experimental requires a github token for the --object-discovery subcommand (that's the only subcommand atm); however, it didn't properly use that token to clone private repos. I used the existing logic in the github/connector.go file to add enable cloning of private repositories.
2025-10-17 09:21:22 -04:00
Kashif Khan bef5eb6d39 Refactored circleci source test cases (#4506)
* Refactored circleci source test cases

* Refactored circleci source test cases
2025-10-17 10:54:53 +05:00
meredith 7ba7a0005d Fix "skipping binary file" logging to show actual file name (#4509)
This was intended to show path:fileName, but `path` in these scopes is
the repo path, not a file.  This section was moved in a refactor where
`path` was the file in the old scope, and since both scopes have `path
string`, it was not flagged and easy to miss.
2025-10-16 12:38:08 -05:00
trufflesteeeve 7d61a4b570 Comment out broken CircleCI integration test (#4505)
* Comment out broken CircleCI integration test

* fixup - set aside unused token variable
2025-10-16 11:04:28 +05:00