T09 · Insecure Skill Coding Practices
- Location
scripts/feishu_api/config.py:45- Finding
Unrestricted API and OAuth endpoints can receive application secrets and access tokens
- Content
View full analysis
Vulnerability Details
File Location:
scripts/feishu_api/config.py:45-52,scripts/feishu_api/token_store.py:109-126,scripts/feishu_openapi_tool.py:182-235, andscripts/feishu_oauth_tool.py:90-105, 148-158, 263-278
Vulnerability Type: Arbitrary credential destination and insufficient transport validation
Risk Level: HighVulnerable Code
scripts/feishu_api/config.py:45-52:python def env_value(name: str, default: str = "") -> str: return os.getenv(name, "").strip() or file_env.get(name, "").strip() or default app_id = env_value("FEISHU_APP_ID") app_secret = env_value("FEISHU_APP_SECRET") base_url = env_value("FEISHU_BASE_URL", "https://open.feishu.cn")scripts/feishu_api/token_store.py:109-126:python def tenant_access_token(settings: Any) -> str: url = settings.base_url.rstrip("/") + "/open-apis/auth/v3/tenant_access_token/internal" body = json.dumps({ "app_id": settings.app_id, "app_secret": settings.app_secret, }, ensure_ascii=False).encode("utf-8") request = urllib.request.Request( url, data=body, headers={"Content-Type": "application/json; charset=utf-8"}, method="POST", ) try: with urllib.request.urlopen(request, timeout=30) as response: payload = json.loads(response.read().decode("utf-8"))scripts/feishu_openapi_tool.py:182-235:python def base_url(env: dict[str, str]) -> str: return env.get("FEISHU_BASE_URL", "https://open.feishu.cn").rstrip("/") def http_json( env: dict[str, str], method: str, path: str, *, bearer: str | None = None, body: dict[str, Any] | None = None, params: dict[str, Any] | None = None, retry_user_token: bool = True, ) -> dict[str, Any]: query = "" if params: clean_params = {k: v for k, v in params.items() if v is not None and v != ""} ...[truncated 5282 chars]- Remediation
View remediation
Remediation Suggestions
- Require HTTPS for every endpoint that receives credentials or bearer tokens.
- Allow only explicitly approved Feishu/Lark hosts by default, such as the documented official API and account hosts.
- Parse URLs with
urllib.parse.urlsplitand reject:- Non-HTTPS schemes.
- Embedded usernames or passwords.
- Fragments.
- Unexpected ports.
- Missing or malformed hostnames.
- Loopback, link-local, private, reserved, or unspecified destination addresses.
- Do not permit separate token and authorization URL overrides in ordinary operation. If private deployments require custom endpoints, gate them behind an explicit option such as
--allow-custom-endpoint. - Require the user to confirm the exact custom hostname before transmitting credentials.
- Disable automatic redirects for credential-bearing requests, or validate every redirect target against the same allowlist before following it.
- Never forward an
Authorizationheader across a change of origin. - Add tests proving that HTTP, arbitrary domains, embedded credentials, and redirects to unapproved hosts are rejected.
- Document that
.envandFEISHU_ENV_FILEare security-sensitive inputs and must not be accepted from untrusted workspaces.
