T09 · Insecure Skill Coding Practices
- Location
scripts/video_subtitle.py:150- Finding
Hard-Coded Coze API Bearer Token
- Content
View full analysis
Vulnerability Details
File Location:
scripts/video_subtitle.py, lines 150–154
Vulnerability Type: Hard-coded authentication credential
Risk Level: HighVulnerable Code
python # Credential environment variable name: COZE_SKILL_{SKILL_ID}_TOKEN #credential = os.getenv(f"COZE_SKILL_{SKILL_ID}_TOKEN") credential="sat_OtJcareEHqNnrVVZJ9RFk0bCfD3wI4fVzGID9bqXcofEw9nyecAT9EhRr9nFyInR" if credential: headers["Authorization"] = f"Bearer {credential}"Technical Analysis
The script embeds a Coze bearer token directly in source code while disabling the safer environment-variable lookup. Any party with access to the source package, repository history, build artifacts, logs containing source, or redistributed copies can recover the credential without authentication.
The script attaches the exposed token to the
Authorizationheader when calling the Coze workflow endpoint. If the token remains valid, an attacker can replay it outside this application. Bearer credentials generally grant access based solely on possession, so exploitation does not require knowledge of another secret.Attack Path
- An attacker downloads, clones, or otherwise obtains a copy of the project.
- The attacker opens
scripts/video_subtitle.pyand extracts the token from line 152. - The attacker constructs requests containing:
http Authorization: Bearer <extracted-token> - The attacker sends authenticated requests to the configured Coze API endpoint, such as
https://api.coze.cn/v1/workflow/run. - Subject to the token's actual validity and permissions, the attacker invokes accessible workflows or consumes associated resources and quotas.
Impact Assessment
If the credential is active, an attacker may gain the same Coze API privileges assigned to that token. The concrete scope depends on server-side token permissions, but potential consequences include:
- Unauthorized execution of the configured or otherwise accessible work ...[truncated 455 chars]
- Remediation
View remediation
Remediation Suggestions
- Immediately revoke and rotate the exposed token. Treat it as compromised even if there is no known abuse.
- Remove the credential from the current source and repository history. Use an appropriate history-rewriting tool if it was committed, then invalidate all affected clones and artifacts where practical.
- Restore external secret loading, for example:
python credential = os.getenv(f"COZE_SKILL_{SKILL_ID}_TOKEN") if not credential: raise RuntimeError("Required Coze API credential is not configured") headers["Authorization"] = f"Bearer {credential}" - Use a managed secret store in production rather than embedding secrets in source, configuration committed to version control, or command-line arguments.
- Apply least privilege. Limit the replacement credential to only the required workflow and operations.
- Prefer short-lived credentials and automated rotation where the provider supports them.
- Add secret scanning to pre-commit hooks and CI pipelines to prevent future credential commits.
- Review Coze audit and billing logs for unauthorized requests made with the exposed token.
- Avoid logging authorization headers or credentials in application and HTTP diagnostic logs.
