T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/google_finance.py:159
- Finding
- API Token Exposure Through Command-Line Arguments<![CDATA[ ## Vulnerability Details **File Location**: `scripts/google_finance.py`, lines 159 and 492–499; invocation at lines 549–550 **Vulnerability Type**: API credential exposure through process arguments **Risk Level**: Medium ### Vulnerable Code ```python parser.add_argument("--token", help="Dataify API token. Bearer prefix is optional.") ``` ```python def get_authorization(token_arg: str | None) -> str | None: token = clean_value(token_arg) or clean_value(os.environ.get("DATAIFY_API_TOKEN")) if not token: return None if not token.lower().startswith("bearer "): token = f"Bearer {token}" os.environ["DATAIFY_API_TOKEN"] = token return token ``` ```python authorization = get_authorization(args.token) if not authorization: print("缺少 Dataify API token,请提供 token,或前往 https://dashboard.dataify.com/login?utm_source=skill 注册获取;新账号注册即得 50 免费积分。", file=sys.stderr) return 2 ``` ### Technical Analysis The script accepts the Dataify API token through the `--token` command-line option. Secrets supplied in command-line arguments may become visible through process inspection interfaces, process-monitoring software, diagnostic telemetry, command histories, CI/CD logs, or Agent execution logs. The script already supports the comparatively safer `DATAIFY_API_TOKEN` environment variable, so accepting the same credential through a command-line argument is not necessary for the declared Google Finance functionality. The token is not sent to an arbitrary destination: it is used as the `Authorization` header for the fixed HTTPS endpoint `https://scraperapi.dataify.com/request`. Consequently, the identified vulnerability concerns local credential exposure rather than hidden network exfiltration. The assignment of the normalized bearer token back into `os.environ` also unnecessarily expands its availability to any child process launched later in the same process context, although this script currently does not launch subprocesses. ...[truncated 1339 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the `--token` command-line option and obtain the credential only from `DATAIFY_API_TOKEN` or an operating-system credential store. 2. If interactive credential entry is required, read it with a non-echoing prompt such as `getpass.getpass()` rather than placing it in the argument vector. 3. For automation, use the CI/CD platform's protected secret injection mechanism and ensure command tracing is disabled around credential handling. 4. Do not assign the normalized bearer value back to `os.environ`. Keep it in a local variable and pass it directly to the request-building function. 5. Ensure logs, diagnostics, and exception messages never include the `Authorization` header or token value. 6. Document that users must never place tokens directly in shell commands, scripts, chat messages, or checked-in configuration files. 7. Rotate any credential previously supplied through `--token` if command history, process telemetry, or execution logs may have recorded it. ]]>
