Secrets Data Models
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The Secrets Data Models in the 2ms project provide a structured framework for identifying, validating, and reporting sensitive information discovered across various platforms like Slack, Discord, and Confluence. At the core of this system is the Secret struct, which encapsulates the metadata, location, and risk assessment of a detected finding.
This module ensures consistency between the detection engine and the reporting sub-systems, allowing for standardized output formats such as JSON, YAML, and SARIF. It also facilitates a scoring mechanism based on the Common Vulnerability Scoring System (CVSS) and tracks the validation status of discovered secrets to prioritize remediation.
Core Data Structures
The Secret Struct
The Secret struct is the primary data model used throughout the application to represent a single finding of sensitive data. It contains detailed information about the location of the secret within the source and its risk profile.
| Field | Type | Description |
|---|---|---|
ID | string | A unique identifier for the finding, typically a SHA1 hash of the item ID, Rule ID, and the secret value. |
Source | string | The origin of the secret (e.g., file path or URL). |
RuleID | string | The identifier of the rule that triggered the detection. |
StartLine | int | The line number where the secret begins. |
EndLine | int | The line number where the secret ends. |
LineContent | string | The actual text of the line containing the secret. |
StartColumn | int | The starting column position of the secret. |
EndColumn | int | The ending column position of the secret. |
Value | string | The sensitive string discovered. |
ValidationStatus | ValidationResult | The current validity state (Valid, Invalid, Unknown). |
RuleDescription | string | A description of why this rule was triggered. |
ExtraDetails | map[string]interface{} | Additional metadata extracted (e.g., JWT sub or name). |
CvssScore | float64 | The calculated risk score for the finding. |
Sources: lib/secrets/secret.go:34-48, engine/engine.go:174-178
Validation and Risk Models
Secrets are categorized by their validation state and risk parameters. The system uses a ValidationResult type to define the state of a secret after a validity check.
The validity status influences the final CvssScore. For example, a "Valid" result increases the risk score compared to an "Invalid" or "Unknown" result.
Sources: lib/secrets/secret.go:5-11, engine/engine.go:146-154
Engine and Rules Models
Detection Engine Configuration
The Engine utilizes an EngineConfig to determine which rules to apply during a scan. This configuration manages inclusions, exclusions, and resource limits.
| Option | Type | Description |
|---|---|---|
SelectedList | []string | List of rule names or tags to explicitly include. |
IgnoreList | []string | List of rule names or tags to exclude. |
SpecialList | []string | Rules that are non-default/noisy (e.g., hardcoded passwords). |
MaxTargetMegabytes | int | Maximum file size allowed for scanning. |
IgnoredIds | []string | Specific finding IDs to skip. |
AllowedValues | []string | Specific secret values that should be ignored globally. |
Sources: engine/engine.go:33-42, engine/rules/rules.go:210-236
Rule and Category Mapping
Rules are grouped into logical categories to better describe the type of service or platform they protect. This is defined in the RuleCategory type.
Categories include CategoryAuthenticationAndAuthorization, CategoryCloudPlatform, CategoryFinancialServices, and many others.
Sources: engine/rules/rules.go:10-50
Reporting and Output Models
The Report Struct
The Report struct aggregates all findings from a scan session. It tracks global statistics and maps results by their source ID.
Sources: lib/reporting/report.go:20-24
Output Formats (SARIF)
For integration with security tools, 2ms supports the SARIF format. The data model is transformed into a structured JSON schema including Runs, Tool definitions, and PhysicalLocation details for each finding.
| SARIF Component | Description |
|---|---|
Driver | Contains tool name and version. |
SarifRule | Describes the rule ID and description for a set of findings. |
Region | Maps to the line and column data from the Secret struct. |
Snippet | Contains the actual sensitive value found. |
Sources: lib/reporting/sarif.go:110-176
Data Flow Logic
The following sequence diagram illustrates how a detected item is transformed into a Secret model and eventually added to a Report.
Sources: cmd/workers.go:11-40, engine/engine.go:100-128
Conclusion
The Secrets Data Models form the backbone of the 2ms architecture, enabling a seamless transition from raw detection to actionable security reports. By encapsulating detailed location data, risk scoring parameters, and validation statuses within the Secret and Report models, the system provides a robust platform for managing secrets at scale across diverse enterprise environments.