T09 · Insecure Skill Coding Practices
- Location
scripts/fetch_weibo_hot.py:82- Finding
API Key Exposure Through URL Query Parameters, Command-Line Arguments, and Plaintext Storage
- Content
View full analysis
str: if cli_key: return cli_key.strip() # 1. Environment variable env_val = os.environ.get(ENV_KEY_NAME, "").strip() if env_val: return env_val # 2. .env file env_file = Path(__file__).parent / ".env" if env_file.exists(): try: content = env_file.read_text(encoding="utf-8") for line in content.splitlines(): line = line.strip() if line.startswith(f"{ENV_KEY_NAME}="): return line.split("=", 1)[1].strip().strip('"\'') except Exception: pass return "" ``` From `scripts/fetch_weibo_hot.py:82-84`: ```python params = {"key": self.api_key} query_string = urllib.parse.urlencode(params) url = f"{API_ENDPOINT}?{query_string}" ``` Related instructions from `SKILL.md:26-29, 43`: ```bash # Method 2: .env file created in the scripts directory echo "TIANAPI_WEIBO_HOT_KEY=YOUR_API_KEY" > scripts/.env # Method 3: pass it on the command line python3 scripts/fetch_weibo_hot.py YOUR_API_KEY ``` ```bash python3 scripts/fetch_weibo_hot.py ``` The direct API example at `SKILL.md:65` also places the credential in the URL: ```text GET https://apis.tianapi.com/weibohot/index?key=YOUR_API_KEY ``` ### Technical Analysis The Skill legitimately needs to authenticate to the declared TianAPI endpoint to retrieve Weibo hot-search data. Transmitting the API key to `https://apis.tianapi.com/weibohot/index` is therefore necessary for the declared functionality and does not indicate transmission to an unrelated party. However, the key is placed in the URL query string. Although HTTPS encrypts the reque ...[truncated 2270 chars]- Remediation
View remediation
