Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated custom detector setup docs #3913

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

kashifkhan0771
Copy link
Contributor

@kashifkhan0771 kashifkhan0771 commented Feb 14, 2025

Description:

This PR separate out the custom regex detectors documentation from main README.md to CUSTOM_DETECTOR.md in custom_detectors package with more details. Also add golang verification server example.

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

Comment on lines +133 to +135
### Go
```go
package main
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this only makes the concept of a "verification server" more confusing. The documentation needs to explain what it does and why you need it; examples in different languages doesn't provide clarity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The explanation is provided above in verify section where we link verification server examples. Shall I add more details there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's any benefit in having multiple bare-bones examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, providing the example in the language TruffleHog is written in is beneficial.

Comment on lines 21 to 24
keywords:
- custom
regex:
token: 'token-[a-zA-Z0-9]{16}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example doesn't do a good job of relating keyword and regex.

unsafe: true
headers:
- "Authorization: super secret authorization header"
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if we could cover the features demonstrated in the generic_with_filter.yml config: https://github.com/trufflesecurity/trufflehog/blob/main/examples/generic_with_filters.yml

  • exclude_regexes_capture
  • entropy
  • exclude_regexes_match
  • exclude_words

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I explained these parameters as per my understanding. If I added a wrong explanation for any of these do let me know.

**Explanation**:
- **`name`**: A unique identifier for your custom detector.
- **`keywords`**: An array of strings that, when found, trigger the regex search. If multiple keywords are specified, the presence of any one of them will initiate the regex search.
- **`regex`**: Defines the patterns to identify potential secrets. You can specify one or more named regular expressions. For a detection to be successful, each named regex must find a match.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should include a sentence or two about how capture groups function here

- **`keywords`**: An array of strings that, when found, trigger the regex search. If multiple keywords are specified, the presence of any one of them will initiate the regex search.
- **`regex`**: Defines the patterns to identify potential secrets. You can specify one or more named regular expressions. For a detection to be successful, each named regex must find a match.
- **`verify`**: An optional section to validate detected secrets. If you want to verify or unverify detected secrets, this section needs to be configured. If not configured, all detected secrets will be marked as unverified. Read [verification server examples](#verification-server-examples)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add explanations of the missing features:
exclude_regexes_capture
entropy
exclude_regexes_match
exclude_words

@kashifkhan0771 kashifkhan0771 force-pushed the update/custom-detector-docs branch from 3f1aa4e to a410e76 Compare February 17, 2025 07:24
keywords:
- hog
regex:
token: '[^A-Za-z0-9+\/]{0,1}([A-Za-z0-9+\/]{40})[^A-Za-z0-9+\/]{0,1}'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose to use a single regular expression to keep the example straightforward for beginners learning about custom detectors. Using two regexps makes the basic example complex to understand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants