T09 · Insecure Skill Coding Practices
- Location
scripts/test_all_premium_apis.py:12- Finding
Hardcoded GM Authentication Token in Executable Scripts
- Content
View full analysis
Vulnerability Details
File Locations:
scripts/test_account_apis.py:12scripts/test_all_apis.py:19-21scripts/test_all_premium_apis.py:12-16scripts/test_financial_apis.py:22
Vulnerability Type: Hardcoded authentication credential
Risk Level: HighVulnerable Code
scripts/test_account_apis.py:12python TOKEN = 'c2a347464c31056c84165dff766750fbf2ec67b4'scripts/test_all_apis.py:19-21python # ============================ # !! 运行前请修改此 Token !! # ============================ TOKEN = 'c2a347464c31056c84165dff766750fbf2ec67b4'scripts/test_all_premium_apis.py:12-16python TOKEN = os.environ.get('GM_TOKEN', '') if not TOKEN: TOKEN = 'c2a347464c31056c84165dff766750fbf2ec67b4' set_token(TOKEN)scripts/test_financial_apis.py:22python TOKEN = 'c2a347464c31056c84165dff766750fbf2ec67b4'The scripts pass this value to authenticated SDK entry points:
python if __name__ == '__main__': set_token(TOKEN)Technical Analysis
The same 40-character GM token is embedded in four executable scripts. It is not merely presented as inert documentation: the scripts supply it to
set_token()orrun(), allowing it to be used for authenticated GM SDK requests.The premium API test is particularly unsafe because it silently falls back to the embedded credential whenever
GM_TOKENis not set. As a result, executing the script may use another account's credential without the operator realizing it.Secrets committed to source code can be recovered from distributed packages, source archives, caches, backups, forks, and repository history even after the current files are edited.
Attack Path
- An attacker obtains a copy of the project or reads its repository history.
- The attacker searches the source for token-like strings and extracts the embedded value.
- The a ...[truncated 945 chars]
- Remediation
View remediation
Remediation Suggestions
-
Revoke and rotate the exposed token immediately; deleting it from the current files is insufficient.
-
Purge the credential from repository history, release archives, build artifacts, caches, and published packages.
-
Replace every hardcoded value with mandatory runtime retrieval:
python import os TOKEN = os.environ.get('GM_TOKEN') if not TOKEN: raise RuntimeError('GM_TOKEN must be set securely before execution') -
Remove all fallback credentials. Scripts must fail closed when authentication is unavailable.
-
Store long-lived credentials in an operating-system credential manager or dedicated secret-management service rather than source files.
-
Add secret scanning to pre-commit hooks and CI, using tools capable of detecting high-entropy strings and known token formats.
-
Restrict tokens to the minimum required API permissions and use separate credentials for testing and live trading.
-
Avoid printing any token content, including prefixes, because partial values can assist correlation and accidental disclosure investigations.
-
