TeamCity API Token
A TeamCity API Token is a credential used to authenticate and authorize access to the TeamCity Continuous Integration (CI) server. This token allows users and applications to interact with TeamCity's REST API, enabling automation of build processes, retrieval of build statuses, and management of projects and configurations. Exposure of this token is a significant security concern as it can lead to unauthorized access to build pipelines, potentially compromising the integrity of software releases and exposing sensitive information.
How Does It Look
TeamCity API Tokens can appear in various contexts, such as:
-
Environment variables:
export TEAMCITY_API_TOKEN="abcd1234efgh5678ijkl" -
Configuration files (JSON, YAML, .env):
{
"teamcity": {
"apiToken": "abcd1234efgh5678ijkl"
}
} -
Code snippets:
headers = {
"Authorization": "Bearer abcd1234efgh5678ijkl"
} -
Connection strings (if applicable):
https://teamcity.example.com/app/rest/builds?locator=running:true&token=abcd1234efgh5678ijkl
Severity
🟠 High
The severity of a TeamCity API Token exposure is high because it grants access to the CI server's API, which can be used to manipulate build configurations, trigger builds, and access sensitive build logs. The blast radius includes potential unauthorized changes to build pipelines and exposure of sensitive data within build logs.
What Can an Attacker Do?
With immediate access to a TeamCity API Token, an attacker can interact with the TeamCity server's API, potentially leading to:
- Modify build configurations: Change build steps or parameters (if the token has write permissions).
- Access build logs: Retrieve logs that may contain sensitive information (if the token has read access).
- Trigger unauthorized builds: Initiate builds that could deploy malicious code (if build permissions are granted).
- Access project settings: View or alter project configurations (if not restricted by permission scope).
An attacker could escalate their access by leveraging the token to introduce vulnerabilities into the build process or move laterally to other connected systems, potentially compromising the entire CI/CD pipeline.
Real-World Impact
The exposure of a TeamCity API Token poses significant business risks, including:
- Data Exposure: Access to sensitive build logs and configurations (if the credential has read access to sensitive data).
- Financial Loss: Costs associated with unauthorized resource usage or downtime (if billing/resource creation is permitted).
- Operational Disruption: Compromised build processes leading to faulty software releases (if the attacker has modify permissions).
- Reputational Damage: Loss of trust from stakeholders due to compromised software integrity.
In the worst-case scenario, an attacker could introduce malicious code into production systems, leading to widespread security breaches and operational failures.
Prerequisites for Exploitation
To exploit a TeamCity API Token, an attacker needs:
- Network access: Ability to reach the TeamCity server's API endpoint.
- Additional context: Knowledge of specific project IDs or build configurations.
- Rate limits: Awareness of any API rate limits or restrictions that might impede exploitation.
How to Verify If It's Active
To verify if a TeamCity API Token is active, use the following command:
curl -H "Authorization: Bearer [TOKEN]" https://teamcity.example.com/app/rest/projects
Valid credential response: A successful response will return a list of projects in JSON format.
Invalid/expired credential response: An error message indicating unauthorized access or token expiration.
Detection Patterns
Common Variable Names:
- TEAMCITY_API_TOKEN
- TC_API_KEY
- TEAMCITY_TOKEN
- TC_TOKEN
- TEAMCITY_AUTH
- TC_AUTH_TOKEN
File Locations:
.envconfig.jsonsettings.yamlbuild.gradlepom.xml
Regex Pattern:
teamcity.*(api|token|key)[\s]*[:=][\s]*["']?[a-zA-Z0-9]{20,40}["']?
Remediation Steps
- Revoke immediately - Go to TeamCity > Administration > User Management and delete the compromised token.
- Audit access logs - Review TeamCity server logs for unauthorized API requests during the exposure window.
- Assess blast radius - Identify all systems, applications, and environments that used the exposed credential.
- Rotate credential - Generate a new API token in TeamCity with least-privilege permissions.
- Update dependent systems - Deploy the new credential to all applications and update CI/CD pipelines securely.
- Harden access controls - Enable IP allowlisting in TeamCity and require TLS connections.
- Implement secrets management - Migrate credentials to a secrets manager (HashiCorp Vault, AWS Secrets Manager) to prevent hardcoding.
- Add detection controls - Set up pre-commit hooks and repository scanning to catch credential leaks before they reach production.
Credential exposures often go undetected for extended periods, increasing the window for exploitation. As a long-term strategy, plan to establish an internal process or engage an external vendor for continuous external exposure monitoring. This helps identify leaked secrets across public repositories, paste sites, dark web forums, and other external sources before attackers can leverage them. Proactive detection and rapid response are essential to minimizing the impact of credential leaks.