Architecture Overview
Relevant source files
The following files were used as context for generating this wiki page:
Too many secrets (2ms) is an open-source CLI tool designed to identify sensitive data such as authentication keys, passwords, and tokens stored in unencrypted text across various platforms. The application is written in Go and leverages the Gitleaks framework for its core detection capabilities.
The architecture is modular, separating the logic for data acquisition (Plugins), detection logic (Engine), and output generation (Reporting). This design allows the tool to support diverse sources including internal communication platforms (Slack, Discord), content management systems (Confluence, Paligo), and source code repositories (Git, local directories).
Sources: README.md:15-20, README.md:200-210
Core Component Structure
The system is organized into three primary layers:
- Plugin Layer: Responsible for authenticating and fetching content from specific platforms.
- Engine Layer: Handles rule filtering, regex-based detection, and secret validation.
- Reporting Layer: Aggregates findings and formats them into JSON, YAML, or SARIF reports.
High-Level Data Flow
The following diagram illustrates how data flows from a target platform through the 2ms engine to the final report.
Plugin Subsystem
Plugins implement the logic required to traverse specific data sources. Each plugin must define a command for the CLI and produce ISourceItem objects, which contain the raw content and metadata for scanning.
Supported Plugins and Logic
| Plugin | Description | Key Functions/Logic |
|---|---|---|
| Filesystem | Scans local directories. | Uses filepath.Walk to traverse paths; ignores .git and user-defined patterns. |
| Git | Scans local Git repositories. | Utilizes git log and gitdiff to scan commit history and text fragments. |
| Confluence | Scans Confluence spaces. | Authenticates via API tokens; traverses spaces and pages, including historical revisions if requested. |
Sources: plugins/filesystem.go:68-85, plugins/git.go:73-100, plugins/confluence.go:88-100
Content Acquisition Flow (Confluence Example)
The Confluence plugin demonstrates complex acquisition, involving paginated requests for spaces, then pages, and finally content versions.
Detection Engine
The Engine is the central processing unit. It is initialized with an EngineConfig that determines which rules are active.
Rule Initialization and Filtering
Rules are categorized (e.g., "API Access", "Cloud Platform") and tagged. The engine filters rules based on:
- SelectedList: Rules explicitly requested by name or tag.
- IgnoreList: Rules to be excluded.
- SpecialList: Noisy or specific rules (like
hardcoded-password) that are not run by default.
Sources: engine/rules/rules.go:12-51, engine/engine.go:50-70
The Detection Loop
The Detect function processes ISourceItem fragments.
- Gitleaks Integration: Uses
detect.NewDetector(cfg)to find matches. - Finding ID Generation: A SHA1 hash is created from the item ID, Rule ID, and the secret value to uniquely identify findings.
- Line Mapping: For filesystem scans, line numbers are adjusted (startLine + 1).
func (e *Engine) Detect(item plugins.ISourceItem, secretsChannel chan *secrets.Secret, wg *sync.WaitGroup, pluginName string, errors chan error) {
defer wg.Done()
fragment := detect.Fragment{
Raw: *item.GetContent(),
FilePath: item.GetSource(),
}
for _, value := range e.detector.Detect(fragment) {
itemId := getFindingId(item, value)
// ... secret object construction ...
if !isSecretIgnored(secret, &e.ignoredIds, &e.allowedValues) {
secretsChannel <- secret
}
}
}
Sources: engine/engine.go:88-120
Secret Validation and Scoring
2ms incorporates a mechanism to verify if a discovered secret is actually active and provides a risk score based on CVSS.
Validation Logic
If the --validate flag is enabled, the tool attempts to verify secrets against the respective service API (e.g., checking a GitHub PAT via GitHub's API).
- Valid: Secret is active.
- Invalid: Secret is inactive/expired.
- Unknown: Validation failed or is not supported for that rule.
Sources: README.md:273-285, engine/engine.go:153-160
Scoring System
The final CvssScore is calculated based on the rule's base risk and its validation status. A valid secret receives a significantly higher score than an invalid or unknown one.
| Rule Category Example | Base Risk | Valid Score | Unknown Score | Invalid Score |
|---|---|---|---|---|
| AWS | 10.0 | 10.0 | 10.0 | 7.0 |
| GitHub PAT | 8.2 | 10.0 | 8.2 | 5.2 |
| Discord Client ID | 1.0 | 4.0 | 1.0 | 1.0 |
Sources: engine/score/score_test.go:20-60, engine/engine.go:153-160
Reporting and Concurrency
The system uses Go channels and sync.WaitGroup to handle high-volume scans concurrently.
Worker Model
- Items Channel: Plugins stream
ISourceItemobjects. - Secrets Channel: The Engine streams discovered
Secretobjects. - Processors: Separate goroutines handle validation, extra detail extraction (like JWT decoding), and scoring.
Sources: cmd/workers_test.go:42-55, cmd/workers_test.go:75-100
Output Formats
The Report structure aggregates results into a map keyed by the secret ID. It supports three primary formats:
- JSON: Machine-readable findings.
- YAML: Default human-readable stdout format.
- SARIF: Static Analysis Results Interchange Format for integration with tools like GitHub Advanced Security.
Sources: lib/reporting/report.go:21-30, lib/reporting/sarif.go:15-30
Conclusion
The 2ms architecture provides a scalable and extensible framework for secret detection. By decoupling content acquisition via plugins from a centralized detection engine based on Gitleaks, it maintains high performance while supporting a wide array of enterprise platforms. Its unique integration of CVSS scoring and active validation helps security teams prioritize remediation of actual leaked credentials over false positives.