Commit Graph
170 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
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
Mustansir daf5bf1e94 [INS-280] Fix Github "repostories" filter does not respect GHES endpoint (#4677) 2026-02-04 11:17:55 +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
Cody Rose cb6aeefd6e shadow context (#4549) 2025-11-12 12:30:46 -08: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
jordanTunstill a66d9e75c2 Changes to fix Enterprise UI filtering of Github Hosted Scanner Repositories to Include (#4430)
* Changes to fix Enterprise UI filtering of Github Hosted Scanner Repositories to Include

* trying to pass linting isssues

* trying to solve linting errors

* Added upstream repo filtering, improvements to normalizeRepo, and unit tests for both.

* Fixing tests impacted by PR 4426
2025-09-03 13:16:39 -07:00
Shahzad Haider 2114e77d56 Fix legacy json flag for Github and Gitlab private repos (#4386)
* fix legacy json flag for gitlab private repos

* some code

* incorporated code from main

* remove cloned repositories after the scan is complete

* enhanced the code

* comment addressed

* changed the approach for persisting the repositories for legacy json printing

* addressed comments; updated the variable names
2025-09-03 11:19:28 +05:00
Kashif Khan 000d748651 Scan Github Private Repositories With Token (#4426)
* Scan Github private repositories with Authenticated user

* readded some old comments

* resolved comments

* resolved linter

* Added comment
2025-09-01 18:30:08 +05:00
Richard GomezandKashif Khan bb899f20dc [GitHub] Add a GraphQL client to the connector (#3837)
* feat(github): add graphql client

* Update connector.go

* Update connector.go

* Update connector_basicauth.go

* Update connector_token.go

* Update connector_unauthenticated.go

* Update connector_app.go

---------

Co-authored-by: Kashif Khan <70996046+kashifkhan0771@users.noreply.github.com>
2025-08-26 11:25:38 +05:00
Kashif Khan 6f36a477c6 Added a dedicated optional flag to ignore gists during scan (#4423)
* Added a dedicated optional flag to ignore gists during scan

* added test case
2025-08-25 16:07:05 +05:00
Kashif Khan 07c16636eb Enable cloning repository to a specified location with retention option (#4408)
* Enabled cloning repositories to a specified path with retention option

* Fixes after testing

* resolved lint issue

* resolved comments

* enabled clone path for github basic auth
2025-08-20 18:10:02 +05:00
Kashif Khan b630944eea Fixed Gist URL Detection (#4284)
* Fixed Gist URL Detection

* eased the condition

* updated comment

* added another example in comment
2025-07-04 11:29:31 +05:00
Kashif Khan b4e1b59a6f Wrap errors when fail to fetch repo or gist (#4259) 2025-06-24 19:34:43 +05:00
Kashif Khan 957ece98f3 Added support to scan github commit metadata for targeted scans (#4189)
* Added support to scan github commit metadata for targeted scans

* added log

* add commit hash in context

* move context value adding to scanTarget

* added v2 log
2025-06-02 10:06:59 +05:00
Kashif Khan 92e9157267 Github and Gitlab Authentication via http.extraHeader for cloning Repositories (#4139)
* initial code changes

* move args before clone command

* add comments

* added flag for github source to support backward compatibility

* added flag for gitlab source to support backward compatibility

* inverse the logic for enterprise

* remove print statement

* remove flag defaults

* updated comments and removed CloneRepoUsingTokenInHeader function

* false->true
2025-05-27 11:24:43 +05:00
Kashif Khan 33f46b1236 Updated Github Source Validate method (#4144)
* updated Validate method to use rate limit API

* check new connector error
2025-05-19 10:48:08 +05:00
Cody Rose ae793d7030 Enable GitHub Realtime authentication (#3929)
GitHub Realtime needs to be able to authenticate. This PR adds relevant fields to the relevant protobuf message, and exports/tweaks some stuff from the github source package to permit its (eventual) use by the GitHub Realtime implementation:

The Connector interface and its constructors are now exported
Connector.Clone now accepts additional clone arguments
The github-specific connection construction has been moved into github.go
The injected rate limit handler no longer accepts error reporters that it never uses
I also added an API endpoint field to the GitHub Realtime proto message, because we need that too and I was here.
2025-02-26 10:20:05 -05:00
Eng Zer Jun 52ae3c343c Replace golang.org/x/exp with stdlib (#3916)
These experimental packages are now available in the Go standard
library.

	1. golang.org/x/exp/slices -> slices [1]
	2. golang.org/x/exp/rand -> math/rand/v2 [2]

[1]: https://go.dev/doc/go1.21#slices
[2]: https://go.dev/doc/go1.22#math_rand_v2

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2025-02-15 18:04:24 -08:00
0x1 3ee9c2f1af [SCAN-165] Use Err Reporting (#3862)
* nit

* update rate limit handler to use reporter

* update process repos to use rate limit handler with unit reporter

* update getReposByOrgOrUser to report err

* update dedupreporter to report err

* add errReporter interface to handle both types of reporters

* convert to error reporter types

* update handleRateLimit signature

* use reporters for all rate limit handlers in github

* get repo url before err check

* use iterator

* remove err log

* nit

* pluralize

* remove err log

* update tests

* make linter happy
2025-02-04 13:44:37 -05:00
ahrav e2f5e0e4bc upgrade Github dep (#3699) 2024-12-02 12:34:47 -08:00
trufflesteeeve 3c69bbc74f Separate org listing error from finding 0 members error cases (#3654) 2024-11-22 11:29:32 -05:00
Bob Idleandahrav 409beeb18b golangci-lint: replace exportloopref with copyloopvar and remove the copy of the 'for' variables (#3591)
* fix: replace golangci-lint exportloopref with copyloopvar

* fix: remove copy of the 'for' variables

---------

Co-authored-by: ahrav <ahravdutta02@gmail.com>
2024-11-13 12:52:04 -08:00
JonZeollaandZachary Rice 4ea311dea9 feat: add github comments timeframe filtering (fixes #3388) (#3390)
* feat: add github comments timeframe filtering

* fixup and generate protos

* Cleanup

---------

Co-authored-by: Zachary Rice <zachary.rice@trufflesec.com>
2024-10-15 15:13:36 -04:00
Richard Gomez 34e443adcf feat: propagate file info in log context (#3405) 2024-10-14 17:13:39 -07:00
ahrav e57c712998 Manually upgrade github dep (#3387) 2024-10-10 06:16:40 -07:00
Richard Gomez 23afcd77ee Log skipped files on debug level (#3383) 2024-10-07 20:39:06 -07:00
ahrav b63d6c02a7 [chore] - Rename memory cache package to 'simple' for clarity (#3352)
* rename memory to cache

* Update

* fix imports
2024-10-02 07:48:26 -07:00
Miccah 2f3a410e38 Implement SourceUnitEnumChunker for GitHub (#3298)
* Implement SourceUnitEnumChunker for GitHub

This change refactors the internal scan method to introduce a scanRepo
method to perform the actual scan.

* Export unit fields so the values are captured in the report

* Add comment for scanRepo

* Break out ensureRepoInfoCache into a method

* Update comments and check errors

* Ensure that the repoInfoCache contains the repo during ChunkUnit

* Add integration test for ChunkUnit

* Move s.scanOptions initialization to Init()
2024-09-23 10:56:55 -07:00
Miccah 77dc2720a8 Update GitHub enumeration to report unique filtered values (#3292)
The reported values should match the values populated in s.repos.
2024-09-18 14:30:10 -07:00
Miccah 401bc4687b Instrument GitHub source with a ChunkReporter (#3296) 2024-09-16 09:57:09 -07:00
Miccah e89190f3ed Instrument GitHub source with a UnitReporter (#3284)
* Fix GitHub integration test

* Instrument GitHub source with a UnitReporter

The reporter is currently unused, but is the first step to support
scanning while enumerating.

* Update GitHub unit tests
2024-09-12 10:28:37 -07:00
Nash 17f6c98119 GitHub source logger clean up (#3269)
* GitHub source logger clean up

* applied pr comments

* applied pr comments

* applied pr comments

* applied PR review comments
2024-09-09 15:44:56 -04:00
Cody Rose dbc1464c63 Download files when reverifying (#3252)
The previous implementation of targeted file scanning pulled patches out of commit data, which didn't work for binary files (because GitHub doesn't return patches for them). This PR changes the system to always just download the requested file and scan it, which means we get binary file support.
2024-08-29 16:10:11 -04:00
Cody Rose 3b0b2909ca Strip leading +/- from github target diffs (#3244)
The GitHub source generates chunks for targeted scans differently than it does for "normal" scans. One difference was the presence of leading + and - characters, which can interfere with detection in some cases.
2024-08-23 15:21:58 -04:00
Cody Rose f26b502c2e Auth GitHub in Init (#3131)
The GitHub source currently applies its authentication configuration as the first step of enumeration. This is incompatible with both targeted scans and scan job reports, and also means that authentication logic has to be duplicated into the validation flow. This PR moves it into Init so that it's available to targeted scans and, eventually, unit-specific scans. This also allows us to remove the copy of the old logic that was in Validate.

As part of the work I've also cleaned up the integration test suite. (Several of them were apparently disabled back when they ran on every push, but now that we're not doing that, we can re-enable them.)
2024-08-05 15:13:29 -04:00
joeleonjrandJoe Leon 7d606e2480 CFOR Commit Scanner (#3145)
* alpha feature for scanning hidden commits on github

* improvements re: git operations

* lint updates

* updating with exec block due to no gh token

* reworked logic into new source

* fixed collisions threshold flag input

* fixed IOutil issues

* removed additions from GH config

---------

Co-authored-by: Joe Leon <joe.leon@trufflesec.com>
2024-08-01 23:04:20 -04:00
ahrav 55fe05d0b4 fix dep versions (#3106) 2024-07-26 17:44:23 -07:00
Cody Rose de19a39f2c Return targeted scan errors (#2995)
Targeted scans should return their errors so that consumers can process them. By creating a type that combines an error with a targeted secret ID, we can return these errors without having to modify the Source interface.
2024-06-21 13:50:56 -04:00
Richard Gomez 5216142960 refactor(cache): use generics (#2930) 2024-06-06 13:08:00 -04:00
Richard Gomez 4d2c8c6e11 refactor(github): improve wiki err handling (#2917) 2024-06-05 08:06:01 -04:00
Richard Gomez 9053d8f4de refactor(github): enumerateWithToken flow & tests (#2880) 2024-05-31 15:53:44 -05:00
Richard Gomez e53f5bd5c5 Improve handling of Gist URLs (#2653)
* feat(github): handle ghes gists

* fix(github): handle all gist URLs

* refactor(github): helper func to check gist urls
2024-05-24 08:36:30 -07:00
Richard Gomez 1441289d41 fix(github): scan user repos (#2814) 2024-05-23 09:40:40 -05:00
ahrav 896e6e7c66 upgrade github dep (#2858) 2024-05-16 14:35:08 -07:00
ahrav a8132839f8 [chore] - update go-github dep manually (#2664)
* update go-github dep

* remove commented out line
2024-04-03 19:19:14 -07:00