Ignoring Rules and Results
Relevant source files
The following files were used as context for generating this wiki page:
The 2ms tool provides a robust mechanism for filtering scan outputs by ignoring specific detection rules, individual result findings, or specific secret values. This functionality is essential for reducing noise from false positives, excluding known-safe credentials, and focusing security audits on relevant threats.
These ignore mechanisms are implemented through a combination of CLI flags, configuration files, and engine-level filtering logic that applies both during rule initialization and after secret detection.
Rule-Based Ignoring
Rule-based ignoring allows users to exclude entire categories of secrets or specific detection patterns from the scan. This is handled during the engine initialization phase by filtering the available ruleset before the detector begins processing items.
Selection and Exclusion Logic
The engine uses three primary lists to determine which rules are active:
- Selected List: Specific rules or tags to include.
- Ignore List: Rules or tags to explicitly exclude.
- Special List: Non-default rules that must be explicitly enabled.
If both rule and ignore-rule flags are provided, the system first takes all rules in the selection list and then removes those found in the ignore list.
Sources: engine/rules/rules.go:264-266, engine/engine.go:46-48
The diagram shows the logical flow of rule filtering during the engine initialization process. Sources: engine/rules/rules.go:261-285
Implementation Details
The filtering is performed by FilterRules, which identifies matches based on Rule IDs or associated tags (e.g., api-key, password).
| Feature | Description | File Reference |
|---|---|---|
isRuleMatch | Checks if a rule matches a string by ID or Tag (case-insensitive) | engine/rules/rules.go:229-242 |
selectRules | Returns a subset of rules matching provided tags | engine/rules/rules.go:244-253 |
ignoreRules | Returns all rules except those matching provided tags | engine/rules/rules.go:255-262 |
Result and Value Ignoring
While rule ignoring prevents checks from running, result ignoring filters specific findings after they have been detected by the engine. This is useful for suppressing permanent false positives or "allowed" secrets.
Ignore Mechanisms
The Engine struct maintains two lists for post-detection filtering:
- Ignored IDs: A list of unique finding IDs (SHA1 hashes) to be skipped.
- Allowed Values: A list of specific secret strings (e.g., "dummy_password") that should never be reported.
Sources: engine/engine.go:28-29, engine/engine.go:132-143
The Detection Filter Flow
After the detector identifies a fragment as a potential secret, the engine generates a finding ID using getFindingId and passes the secret through isSecretIgnored before sending it to the results channel.
This sequence illustrates the late-stage filtering of findings within the Detect function. Sources: engine/engine.go:101-110
Configuration and CLI Flags
Users can control ignore behavior through the command line or a configuration file. The tool supports "Hybrid Configuration Mode," where CLI flags merge with and override file-based settings.
Ignore Configuration Options
| Flag | Description | Type |
|---|---|---|
--ignore-rule | Ignore rules by name or tag (e.g., github-pat or api-key). | String Slice |
--ignore-result | Ignore a specific result by its unique ID. | String Slice |
--allowed-values | Ignore specific secret values (e.g., EXAMPLE_TOKEN). | String Slice |
--ignore-pattern | (Filesystem Plugin only) Ignore files matching specific patterns. | String Slice |
--ignore-on-exit | Defines if non-zero exit codes (results/errors) should be ignored. | Enum |
Sources: README.md:214-230, cmd/main.go:94-100
ID Generation for Ignoring
The ignore-result flag requires the specific finding ID. This ID is calculated as a SHA1 hash of the source item ID, the rule ID, and the secret value itself.
func getFindingId(item plugins.ISourceItem, finding report.Finding) string {
idParts := []string{item.GetID(), finding.RuleID, finding.Secret}
sha := sha1.Sum([]byte(strings.Join(idParts, "-")))
return fmt.Sprintf("%x", sha)
}
Sources: engine/engine.go:126-130
Plugin-Specific Ignoring
Individual plugins may implement additional ignore logic relevant to their source types.
Filesystem and Git
- Automatic Ignoring: The filesystem plugin and engine tests show that specific files like
go.sumare often excluded from scans to prevent noise from dependency hashes. - Pattern Ignoring: Users can provide
--ignore-patternto skip specific files or directories during the recursive walk.
Sources: engine/engine_test.go:73-77, plugins/filesystem_test.go:154-167
Confluence
The Confluence plugin allows ignoring non-relevant spaces by providing a specific list of --spaces. If provided, the plugin filters the list of detected spaces before iterating through pages.
Sources: plugins/confluence.go:137-148
Summary
Ignoring in 2ms is a multi-layered system. It starts with Rule Filtering (pre-scan) to define what patterns to look for, followed by Plugin Filtering to define what files or locations to skip, and concludes with Result Filtering (post-scan) to suppress specific findings by ID or content. This granular control allows the tool to be integrated into CI/CD pipelines with high signal-to-noise ratios.