T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/poi_fetch.py:10
- Finding
- Hard-Coded Amap API Credential Exposed in Source Code<![CDATA[ ## Vulnerability Details **File Location**: `scripts/poi_fetch.py:10-11` **Vulnerability Type**: Hard-coded API credential **Risk Level**: High ### Vulnerable Code ```python DEFAULT_KEY = "0c166a2bf61c1e4e6c96e3b645233e54" # 默认key(主人已创建) KEY = os.environ.get("AMAP_KEY", DEFAULT_KEY) ``` The credential is also disclosed in `SKILL.md:59`: ```markdown | KEY | 默认使用主人已申请的KEY(`0c166a2bf61c1e4e6c96e3b645233e54`) | ``` It is subsequently included in Amap request URLs: ```python url = f"https://restapi.amap.com/v3/config/district?keywords={urllib.parse.quote(city_name)}&subdistrict=1&key={KEY}" ``` ```python url_base = (f"https://restapi.amap.com/v3/place/text?key={KEY}" f"&keywords={kw_enc}&city={adcode}&citylimit=true&offset=20&extensions=all") ``` ### Technical Analysis An owner-created API key is embedded directly in the distributed source code and repeated in the documentation. Environment-variable support does not protect the embedded credential because the hard-coded value is automatically used whenever `AMAP_KEY` is absent. The script also transmits the key as a URL query parameter. HTTPS protects the request in transit, but query strings may still be retained by application telemetry, proxy logs, exception reporting, browser-like tooling, or API-provider access logs. Embedding the key in the package gives every recipient the same credential and prevents effective per-user attribution or revocation. Network access to `restapi.amap.com` is consistent with the declared POI-fetching functionality. The security issue is not the use of the Amap API itself, but distributing a reusable owner credential rather than requiring callers to supply their own. ### Attack Path 1. An attacker downloads, receives, or otherwise reads the Skill package. 2. The attacker extracts the API key from `scripts/poi_fetch.py` or `SKILL.md`. 3. The attacker submits independent requests to supported Amap API endpoints using that key. 4. Requests consume the ...[truncated 677 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Revoke and rotate the exposed API key immediately. 2. Remove the key from source code, documentation, release archives, and version-control history. 3. Require a credential through `AMAP_KEY` or `--key` and terminate safely if neither is supplied: ```python KEY = os.environ.get("AMAP_KEY") if not KEY: raise SystemExit( "An Amap API key is required. Set AMAP_KEY or provide --key." ) ``` 4. Avoid including secrets in diagnostic output and sanitize request URLs before logging. 5. Apply provider-side restrictions where available, including allowed API products, source IP ranges, referrers, quotas, and usage alerts. 6. Prefer separate, revocable credentials for each user or deployment rather than a shared package-wide credential. 7. Add automated secret scanning to the release and source-control workflow. ]]>
