Data Flow: From Discovery to Report
Relevant source files
The following files were used as context for generating this wiki page:
The 2ms data flow is a multi-stage pipeline designed to discover, analyze, validate, and report sensitive information stored in unencrypted text across various platforms. The process begins with plugin-driven discovery, moves through a centralized detection engine, undergoes optional validity and scoring assessments, and concludes with the generation of structured reports in multiple formats.
The architecture relies on Go's concurrency primitives, specifically channels and wait groups, to handle data asynchronously. This ensures that as plugins fetch content from sources like Confluence or local filesystems, the detection engine can simultaneously process that content without blocking further discovery.
Sources: README.md:14-22, engine/engine.go:102-140, cmd/workers_test.go:50-65
Discovery and Itemization
The discovery phase is handled by specialized plugins (e.g., Confluence, Discord, Slack, Filesystem). Each plugin implements a discovery logic that traverses the target source, identifies content containers (like pages, channels, or files), and converts them into a standardized ISourceItem.
For example, the Confluence plugin iterates through spaces and pages, even optionally traversing historical versions of pages if configured. This raw content is then wrapped into an internal item structure containing the content body, a unique ID, and the source URI.
Discovery Workflow
The following diagram illustrates how a plugin (using Confluence as an example) discovers and dispatches items for processing.
Detection and Secret Extraction
Once an ISourceItem is pushed onto the items channel, the Engine picks it up for detection. The Engine uses a Detector (powered by gitleaks framework) and a set of filtered rules to scan the raw content.
The detection process involves:
- Filtering Rules: Rules are selected based on inclusion, exclusion, or special tags.
- Regex Matching: The detector runs the content against the compiled regex patterns of the selected rules.
- Secret Construction: For every match (finding), the engine calculates line numbers, extracts the secret value, and retrieves the surrounding context (line content).
- ID Generation: A unique finding ID is generated by hashing the item ID, rule ID, and the secret value itself to ensure traceability.
| Component | Functionality |
|---|---|
Engine.Init | Filters rules and initializes the gitleaks detector. |
Engine.Detect | Processes a single ISourceItem and identifies potential secrets. |
getFindingId | Generates a SHA1 hash of item.GetID(), finding.RuleID, and finding.Secret. |
Sources: engine/engine.go:54-90, engine/engine.go:102-140, engine/engine.go:173-177
Validation and Scoring
Discovered secrets undergo further processing to determine their impact and authenticity. This stage is critical for prioritizing remediation efforts through the Common Vulnerability Scoring System (CVSS).
Validity Checking
If the --validate flag is enabled, the secret is registered with a Validator. The validator attempts to check if the secret is still active (e.g., calling a GitHub API for a discovered PAT). The result is categorized as valid, invalid, or unknown.
Risk Scoring
The final score of a secret is derived from:
- Base Risk Score: Determined by the rule's category (e.g., IoT platform vs. Authentication) and rule type.
- Validation Status: Validated secrets receive higher scores than those that are invalid or have an unknown status.
Reporting and Output Generation
The final stage is the aggregation of all discovered Secret objects into a Report. The report includes metadata such as the total items scanned and total secrets found, alongside a map of results indexed by the source of the finding.
Report Formats
The system supports multiple output formats, determined by either the --stdout-format flag or the file extension provided in --report-path.
| Format | File Extension | Implementation |
|---|---|---|
| JSON | .json | writeJson(*r) |
| YAML | .yaml, .yml | writeYaml(*r) |
| SARIF | .sarif | writeSarif(*r, cfg) |
The WriteFile function handles the creation of necessary directories and the writing of the formatted output to the specified filesystem paths.
Sources: lib/reporting/report.go:27-41, lib/reporting/report.go:44-71, README.md:214-222
Summary of Logic Flow
The end-to-end flow is orchestrated through concurrent workers that manage the transition of data between these states: