T09 · Insecure Skill Coding Practices
- Location
greetings.py:17- Finding
Broken and Misleading API Credential Handling
- Content
View full analysis
Vulnerability Details
File Location:
greetings.py, lines 17–18, 26–27, 35–36, 52–53, 89–94, and 123–127
Vulnerability Type: Insecure credential handling and undocumented environment dependency
Risk Level: MediumVulnerable Code
The DashScope agents contain a literal placeholder instead of loading a credential securely:
python "api_key": "TODO_REPLACE_WITH_ENV", "base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1",The placeholder is placed directly in the HTTP authorization header:
python req = urllib.request.Request( url, data=data, headers={ 'Content-Type': 'application/json', 'Authorization': f"Bearer {agent['api_key']}" } )An unrelated environment variable is read only after
main()has finished, and its value is never used:python if __name__ == '__main__': main() import os API_KEY = os.getenv("DEEPSEEK_API_KEY") if not API_KEY: raise ValueError("DEEPSEEK_API_KEY 环境变量未配置")Technical Analysis
Four DashScope agent definitions use the literal value
TODO_REPLACE_WITH_ENVas their API key.call_dashscope()places that value in anAuthorization: Bearerheader and sends it to the official DashScope HTTPS endpoint.The script later reads
DEEPSEEK_API_KEY, but this occurs aftermain()and all API calls. The value is not assigned to the agent definitions and is never consumed bycall_dashscope(). Consequently:- DashScope requests are sent with an invalid placeholder credential.
- Setting
DEEPSEEK_API_KEYdoes not authenticate the DashScope requests. - Omitting that unrelated variable causes the program to raise an exception after its main processing.
- The placeholder design may encourage users to insert a real API key directly into source code, exposing it through source distribution, backups, or version-control history.
The audited data flow does not show envi ...[truncated 1791 chars]
- Remediation
View remediation
Remediation Suggestions
-
Read the correct DashScope credential from a clearly named environment variable before invoking
main():python import os DASHSCOPE_API_KEY = os.environ.get("DASHSCOPE_API_KEY") if not DASHSCOPE_API_KEY: raise RuntimeError("DASHSCOPE_API_KEY is not configured") -
Remove
api_keyvalues from the staticAGENTSconfiguration and pass the credential explicitly to the request function:python def call_dashscope(agent: dict, api_key: str) -> str: req = urllib.request.Request( url, data=data, headers={ "Content-Type": "application/json", "Authorization": f"Bearer {api_key}", }, ) -
Validate credentials before making any network request. Reject empty values and known placeholders such as
TODO_REPLACE_WITH_ENV. -
Remove the trailing
DEEPSEEK_API_KEYblock because it is unrelated to DashScope and does not affect authentication. -
Never instruct users to place API keys directly in source files. Add secret files, if any are introduced, to
.gitignore, and recommend environment variables or an operating-system secret manager. -
Document
greetings.py, its DashScope network destination, the information sent, and the required environment variable inSKILL.md. -
Make greeting-related network access explicitly user-triggered and fail before transmission when configuration is invalid.
-
Avoid exposing authorization headers or credential values in exceptions, logs, or debug output.
-
