Introduction to 2ms
Relevant source files
The following files were used as context for generating this wiki page:
Too many secrets (2ms) is an open-source Command Line Interface (CLI) tool developed by Checkmarx. Its primary purpose is to identify sensitive data—such as secrets, authentication keys, and passwords—stored in unencrypted plain text across various platforms. The tool is written in Go and leverages the gitleaks framework for robust detection capabilities.
2ms supports scanning multiple environments, including internal communication platforms (Slack, Discord), content management systems (Confluence, Paligo), and source code storage (Git repositories, local filesystems). It utilizes a comprehensive ruleset and a scoring system based on the Common Vulnerability Scoring System (CVSS) to help users prioritize remediation efforts.
Sources: README.md:12-25, cmd/main.go:42-47
Core Architecture and Data Flow
The architecture of 2ms is built around a plugin-based system that feeds data into a centralized detection engine. The process begins with the CLI receiving user commands and flags, which initialize the relevant plugins and the scanning engine.
System Overview Diagram
The following diagram illustrates the high-level flow from user input through plugin execution to the final report generation.
Sources: cmd/main.go:102-155, engine/engine.go:61-105
Plugins System
2ms employs a plugin architecture to interface with different data sources. Each plugin is responsible for authenticating with the target service, crawling or listing resources, and extracting content for the engine to analyze.
Supported Plugins
| Plugin | Scope | Key Configuration Flags |
|---|---|---|
| Confluence | Pages and history revisions | --url, --spaces, --token, --history |
| Discord | Chat application history | --token, --server, --channel, --duration |
| FileSystem | Local directories | --path, --ignore-pattern |
| Git | Local Git repositories | --all-branches, --depth |
| Slack | Workspace chat history | --token, --team, --channel |
| Paligo | CMS instance content | --instance, --token, --folder |
Sources: README.md:162-286, cmd/main.go:55-62
Data Extraction Logic
Plugins convert platform-specific data into a standardized ISourceItem interface, which includes the raw content, a unique ID, and the source path or URL. For example, the Confluence plugin recursively fetches spaces, then pages, and finally the storage format of page bodies.
Sources: plugins/confluence.go:88-144
Detection Engine and Rules
The engine is the core component that applies security rules to the items collected by plugins. It is initialized with a filtered list of rules based on user selection or defaults.
Engine Components
- Detector: Utilizes the Gitleaks framework to match content against regex patterns and keywords.
- Ruleset: A collection of predefined rules (e.g., AWS Access Token, GitHub PAT) categorized by service types.
- Validator: Optionally checks if a discovered secret is active by making a request to the provider's API.
Sources: engine/engine.go:28-52, engine/rules/rules.go:61-180
Rule Categories and Scoring
Rules are organized into categories such as CategoryAuthenticationAndAuthorization, CategoryCloudPlatform, and CategoryDatabaseAsAService. Each rule has an associated RuleType (1-4) that influences its base risk score.
| Rule ID Example | Category | Tags |
|---|---|---|
aws-access-token | Authentication and Authorization | access-token |
github-pat | Development Platform | access-token |
slack-webhook-url | Social Media | webhook |
hardcoded-password | General or Unknown | password |
Sources: engine/rules/rules.go:21-59, engine/rules/rules.go:61-180
Validation and Prioritization
When the --validate flag is used, 2ms attempts to verify the legitimacy of found secrets. This validation impacts the final CVSS score.
Scoring Logic
The final CvssScore is calculated based on the rule's base risk and the validation result:
- Valid: Highest score, indicating a confirmed, actionable leak.
- Invalid: Lower score, indicating a pattern match that is not currently active.
- Unknown: Default score when validation is not performed or supported.
Sources: README.md:323-345, engine/engine.go:138-146
Reporting and Output
After scanning, 2ms aggregates findings into a Report structure. It tracks total items scanned, total secrets found, and a map of results indexed by finding IDs.
Output Formats
The tool supports multiple output formats for both standard output (stdout) and file-based reporting:
- JSON: Structured data for machine processing.
- YAML: Default human-readable format.
- SARIF: Standardized format for static analysis results, often used in CI/CD integrations like GitHub Actions.
Sources: lib/reporting/report.go:23-27, cmd/main.go:174-192
Summary
2ms provides a unified interface for detecting secrets across diverse communication and storage platforms. By integrating a plugin-based architecture with a centralized detection engine and CVSS-based scoring, it enables security teams to efficiently identify and prioritize the remediation of exposed credentials. Its support for CI/CD integrations and multiple report formats makes it suitable for both ad-hoc scans and automated security pipelines.
Sources: README.md:12-25, cmd/main.go:157-195