Slack Scanner Plugin
Relevant source files
The following files were used as context for generating this wiki page:
The Slack Scanner Plugin is a core component of the 2ms (Too Many Secrets) CLI tool designed to identify sensitive information within Slack workspace histories. It enables organizations to scan messages across various channels for unencrypted secrets, authentication keys, and passwords.
As part of the broader 2ms ecosystem, this plugin integrates with the central detection engine to apply regular expression rules against Slack message content. It supports targeted scanning by team, specific channels, message volume, and historical timeframes.
Sources: README.md:12-16, plugins/slack.go:28-32
Plugin Architecture and Command Definition
The Slack plugin is implemented as a Go struct that satisfies the IPlugin interface. It manages its own CLI command definition using the Cobra library and handles the concurrent fetching of message data through Go routines and channels.
Command Configuration
The plugin defines a slack sub-command with several flags for authentication and scan scoping.
| Flag | Argument | Description | Required |
|---|---|---|---|
--token | tokenArg | Slack API token for authentication | Yes |
--team | teamArg | Slack team name or ID | Yes |
--channel | channelsArg | Specific Slack channel IDs to scan | No |
--duration | backwardDurationArg | Look-back period (default: 14 days) | No |
--messages-count | messagesCountArg | Maximum number of messages to scan per channel | No |
Sources: plugins/slack.go:49-74, README.md:231-238
Execution Flow
When the command is executed, the plugin initializes a Slack API client and begins a multi-stage retrieval process:
- Identity Resolution: Resolves the provided Team Name/ID to a specific Slack Team ID.
- Channel Discovery: Fetches all available channels for that team (or filters by provided IDs).
- Concurrent Scanning: Spawns a goroutine for each channel to fetch message history.
Data Retrieval Logic
The plugin utilizes the slack-go/slack library to communicate with the Slack Web API. The core logic resides in getItemsFromChannel, which manages pagination and boundary checks.
Message Filtering
The plugin applies two primary filters to determine if a message should be processed:
- Time Range: Messages older than the
backwardDurationArg(defaulting to 336h or 14 days) are skipped. - Message Count: If a limit is set via
messages-count, the scan stops once the threshold is reached for that channel.
Source Item Mapping
Each Slack message is converted into a standard ISourceItem (specifically an item struct) before being sent to the detection engine. This mapping ensures the engine can report exactly where a secret was found.
- Content: The raw text of the Slack message (
message.Text). - ID: A unique string formatted as
slack-[ChannelID]-[Timestamp]. - Source: A permanent link (permalink) to the message. If the API fails to retrieve a permalink, a fallback string containing the Channel Name and Timestamp is used.
Sources: plugins/slack.go:124-135
Integration with Detection Engine
The Slack Scanner Plugin is registered in the main application entry point alongside other plugins. Once message items are produced, they are processed by the detection engine using specific Slack-related rules.
Relevant Detection Rules
The engine includes specific rules tailored for Slack's ecosystem, as defined in the rules repository:
slack-bot-tokenslack-app-level-tokenslack-user-tokenslack-webhook-urlslack-configuration-token
Sources: cmd/main.go:56-62, engine/rules/rules.go:189-197
Conclusion
The Slack Scanner Plugin provides a robust mechanism for auditing internal communications within Slack workspaces. By leveraging concurrent processing and flexible scoping flags, it allows security teams to efficiently scan vast message histories for leaked credentials while providing precise location data for remediation via permalinks.