Contributing to 2ms
Relevant source files
The following files were used as context for generating this wiki page:
2ms (Too Many Secrets) is an open-source CLI tool written in Go, designed to identify sensitive data like secrets and passwords in unencrypted text across various platforms. The project is built with extensibility in mind, utilizing a plugin-based architecture that allows developers to add support for new content management systems, communication platforms, or source code locations.
Contributing to the project involves several areas, including core engine development, creating or improving plugins, and updating detection rules. The tool leverages the gitleaks framework and incorporates a CVSS-based scoring system to prioritize remediation.
Sources: README.md:10-25, CONTRIBUTING.md:1-2
Project Architecture Overview
The 2ms architecture is divided into a core engine and a set of modular plugins. The engine handles the orchestration of scans, rule application, and reporting, while plugins are responsible for fetching content from specific sources.
Plugin System
Plugins implement a standard interface to provide content to the engine. This modularity allows the tool to support diverse platforms such as Confluence, Slack, Discord, and local filesystems.
The diagram shows how the main execution flow initializes the engine and various plugins, which then feed data items into the engine for secret detection.
Sources: cmd/main.go:50-60, plugins/confluence.go:40-60
Development Workflow
Compiling from Source
To contribute code, you should be able to build the project locally. 2ms requires a Go environment for compilation.
git clone https://github.com/checkmarx/2ms.git
cd 2ms
go build -o dist/2ms main.go
Sources: README.md:55-60
Testing Standards
2ms maintains a multi-layered testing strategy to ensure reliability and prevent regressions.
| Test Type | Location | Description |
|---|---|---|
| Unit Tests | _test.go files | Testing individual functions and logic within packages. |
| CLI E2E Tests | tests/cli | Builds the CLI, executes it, and verifies output against expected results. |
| Linting | tests/lint | Verifies coding standards (e.g., ensuring log.Info is used instead of fmt.Print). |
| Rule Consistency | .ci/check_new_rules.go | Compares internal rules against the latest Gitleaks releases. |
To skip long-running E2E tests during development, use: go test -short ./....
Sources: CONTRIBUTING.md:7-15
Adding and Modifying Rules
Rules are the heart of the detection engine. They are categorized by the type of service they target (e.g., Cloud Platform, Payment Processing) and assigned tags.
Rule Structure
Each rule is defined with specific score parameters, including its Category and RuleType, which influence the final CVSS score.
{
Rule: *rules.GitHubPat(),
Tags: []string{TagAccessToken},
ScoreParameters: ScoreParameters{
Category: CategoryDevelopmentPlatform,
RuleType: 4
}
}
Sources: engine/rules/rules.go:95-99
Custom Regex Rules
Users and contributors can also define custom regex rules via the --regex flag. These are compiled at runtime and added to the detection engine's rule set.
Sources: cmd/main.go:145-150, README.md:275-285
Creating a New Plugin
To add support for a new platform, a developer must implement the IPlugin interface. Key responsibilities of a plugin include:
- Defining Commands: Setting up the Cobra command and flags for the specific source.
- Authentication: Handling API tokens or usernames/passwords.
- Data Retrieval: Fetching content (e.g., page history in Confluence or commit history in Git) and converting it into
ISourceItem.
Confluence Plugin Example
The Confluence plugin demonstrates complex logic like handling pagination for spaces and pages, and scanning historical versions if requested.
The sequence shows the nested retrieval logic used to exhaustively scan a Confluence instance.
Sources: plugins/confluence.go:88-125, plugins/confluence.go:150-175
Scoring System (CVSS)
2ms uses a scoring system based on CVSS to help prioritize findings. The score is calculated based on the rule category and the validation status of the secret.
- Valid: Secret confirmed to work with the target service.
- Invalid: Secret confirmed to be inactive.
- Unknown: Secret found but not validated (default).
The validity check is triggered by the --validate flag, which executes service-specific logic to verify the finding.
Sources: README.md:238-250, engine/rules/rules.go:60-90
Conclusion
Contributing to 2ms provides an opportunity to improve the security posture of various platforms by expanding its detection capabilities. By adhering to the plugin architecture and maintaining the comprehensive test suite, contributors ensure that the tool remains a reliable solution for secret detection.
Sources: CONTRIBUTING.md:1-5, README.md:295-300