A Segment Public API token lets whoever holds it manage a Segment workspace through the Public API. Depending on the role given to the token, that can mean creating and changing sources, destinations and tracking plans. Changing a destination can silently redirect your customers’ event data to a third party, which is why this token deserves prompt attention. Delete the token first, then check what changed in the workspace.
Check your GitHub account for leaked secrets — free
- Provider
- Segment
- Severity
- High
- Impact
- SaaS account access and billing
- Checked live by LeakWatch
- No
What a Segment Public API token looks like
Segment Public API tokens are two long strings of letters, digits, underscores and hyphens, joined by a dot. Each part is a fixed length, so the value has a recognisable shape even without a prefix:
<part one>.<part two> Segment Public API token (masked)
The rule therefore depends on the word segment being close to the value. Because that word is common in ordinary text, a hit needs a check. Segment separates this token from the write-key that a website uses to send events, and it is the Public API token that deserves the most care.
How Segment Public API tokens get leaked
- Automation committed to a repository. A script that manages sources or tracking plans, with the token written in the file.
- CI pipelines. A workflow that calls the Public API and prints its configuration, or stores the token where other jobs can read it.
- Infrastructure-as-code. A configuration file for a managed workspace that includes the token.
- Shared scripts. A snippet copied into a support request or a blog post, with the real token left in.
- Developer machines. A token saved in a local configuration file that is later copied to another device or backed up.
What to do in the first hour
- Delete the token. Open the account settings, go to the tokens area and delete the Public API token that leaked. Make sure you are in the right workspace before you do this.
- Create a new token only for the automation that needs it, and give it the smallest role that works. Store it in your secret manager.
- Review destinations and sources. This is the most important step. Look for destinations added, changed or enabled since the exposure, because a changed destination can send your event data elsewhere.
- Review tracking plans. Check for changed event schemas or new rules that you did not approve.
- Check workspace members. Remove anyone you do not recognise and review recent changes in the audit log.
- Clean the repository. Remove the token from files and history, and check the logs. See I accidentally pushed an API key to GitHub.
Not sure what else leaked from the same automation? Run a free scan.
Revoke it at Segment
Open the account settings of your Segment workspace, go to the access management section, and find the tokens list. Delete the Public API token that leaked, then create a replacement if the automation still needs one. Only a workspace owner can create Public API tokens, according to Segment’s documentation, so the same owner will usually be needed for the rotation. Segment’s public API documentation is the reference for the current steps, and this guide has not confirmed the menu names on the live page.
How LeakWatch detects it
The rule is called “Segment API Key”. It looks for the word segment within 40 characters of a value made of two dot-separated parts, each 43 characters long, using letters, digits, underscores and hyphens. The word must come before the value, with only a short gap between them. The severity is high. This type is not checked live: LeakWatch does not call Segment with the value it finds.
LeakWatch detects this format but does not check it live: it can tell you the key is exposed, not whether it still works. Assume it does until you have revoked it.
FAQ
Is a source write key the same as the Public API token?
No. A write key lets a website or app send events. The Public API token manages the workspace. A leak of the Public API token is the more serious one.
Can the token read my customers' data?
Its main power is to change the workspace. Treat any exposure as serious anyway, because changes to destinations can route data outward.
Do Segment tokens expire?
Third-party descriptions say they do not expire by default, so rotate them on a schedule you choose.