feat: add host, db and username to ExtraData for database detectors#4849
feat: add host, db and username to ExtraData for database detectors#4849mariocj89 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR enhances database connection string detectors by surfacing parsed connection metadata (host, username, database) via Result.ExtraData, improving downstream triage and identification of detected credentials.
Changes:
- Redis: populate
ExtraDatafrom the parsed Redis URL. - Postgres: add
host,username, anddatabaseintoExtraDatawhile preserving existingsslmode. - MongoDB + JDBC: expose parsed connection fields in
ExtraDataand add focused tests validating the new metadata.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/detectors/redis/redis.go | Adds ExtraData population from parsed Redis URLs via a helper. |
| pkg/detectors/redis/redis_test.go | Adds test coverage asserting host/username in ExtraData. |
| pkg/detectors/postgres/postgres.go | Extends existing ExtraData to include host/username/database alongside sslmode. |
| pkg/detectors/postgres/postgres_test.go | Adds tests validating new Postgres ExtraData fields and preserving sslmode. |
| pkg/detectors/mongodb/mongodb.go | Preserves rotation_guide and adds host/user/database fields into ExtraData. |
| pkg/detectors/mongodb/mongodb_test.go | Adds tests verifying MongoDB ExtraData fields are populated. |
| pkg/detectors/jdbc/jdbc.go | Parses JDBC connection info to populate ExtraData even when verify=false. |
| pkg/detectors/jdbc/jdbc_test.go | Adds tests covering ExtraData extraction and unsupported subprotocol behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2ee0783 to
252be3e
Compare
MuneebUllahKhan222
left a comment
There was a problem hiding this comment.
Hi @mariocj89,
Thank you for the contribution. This looks good to me, please update the integration tests to align with the changes in ExtraData.
|
@MuneebUllahKhan222 does this still make sense given the recent addition of Happy to go either direction: |
I believe option (a) makes more sense. |
252be3e to
6ef0047
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 6ef0047. Configure here.
cdaaa82 to
c5dc121
Compare
|
@MuneebUllahKhan222 makes total sense! Everything in |
MuneebUllahKhan222
left a comment
There was a problem hiding this comment.
I’ve added a few comments.
Additionally, we should account for changes in ExtraData within the integration tests. These fields can be safely excluded from comparisons by updating the test configuration as follows:
ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "SecretParts", "ExtraData")
c5dc121 to
7cc5bc3
Compare
MuneebUllahKhan222
left a comment
There was a problem hiding this comment.
This looks good to me. Just one non-blocking comment after that we will need a quick product-eng review before we can merge.
7cc5bc3 to
2f3b64d
Compare
|
Hi @mariocj89, |
Populate ExtraData with parsed fields for all database connection string detectors (MongoDB, PostgreSQL, Redis, JDBC). This surfaces useful metadata about detected credentials. The parsing logic already existed in each detector — this change exposes the extracted values in the result's ExtraData map alongside any pre-existing fields (rotation_guide, sslmode, etc.).
2f3b64d to
ed0e490
Compare
|
@MuneebUllahKhan222 rebased! |

First time contributing to trufflehog, let me know if I should do anything differently. Thanks for your work ^^.
Fixes #4754 and helps with general triaging and identification for other database connection types :).
Description:
Populate ExtraData with parsed fields for all database connection string detectors (MongoDB, PostgreSQL, Redis, JDBC). This surfaces useful metadata about detected credentials.
The parsing logic already existed in each detector — this change exposes the extracted values in the result's ExtraData map alongside any pre-existing fields (rotation_guide, sslmode, etc.).
Checklist:
make test-community)?make lintthis requires golangci-lint)?Manual test
Example file
Example output
Note
Low Risk
Low risk: changes only add parsed metadata to
Result.ExtraDatafor several database detectors and adjust tests accordingly, without altering matching patterns or verification logic.Overview
Adds parsed connection metadata to findings for the JDBC, MongoDB, Postgres, and Redis detectors by populating
Result.ExtraDatawithhost,username, and (where applicable)databasealongside existing fields likesslmode/rotation_guide.For JDBC, parsing is now attempted even when
verify=falseso ExtraData is available for unverified results, while verification behavior remains the same (parse failures still skip only whenverify=true). Tests are updated to ignore the new fields in integration diffs and new unit tests are added to assert the populated ExtraData for each detector.Reviewed by Cursor Bugbot for commit ed0e490. Bugbot is set up for automated code reviews on this repo. Configure here.