T09 · Insecure Skill Coding Practices
- Location
scripts/get-token.py:43- Finding
Authentication Credentials Can Be Sent to an Untrusted or Insecure Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/get-token.py:43-64andscripts/get-token.py:113-128
Vulnerability Type: Insufficient validation of a credential-bearing network destination
Risk Level: HighVulnerable Code
python def get_token() -> str: """获取访问令牌""" base_url = get_env("EOFFICE_BASE_URL") agent_id = get_env("EOFFICE_AGENT_ID") secret = get_env("EOFFICE_SECRET") user = get_env("EOFFICE_USER") # 构建 token 获取 URL token_url = f"{base_url.rstrip('/')}/api/auth/openapi-token" # 构建请求 payload payload = { "user": user, "agent_id": agent_id, "secret": secret } try: response = requests.post( token_url, json=payload, headers={"Content-Type": "application/json"}, timeout=TIMEOUT )The refresh operation follows the same destination-handling pattern:
python def refresh_token(current_token: str, refresh_token: str) -> str: """刷新访问令牌""" base_url = get_env("EOFFICE_BASE_URL") refresh_url = f"{base_url.rstrip('/')}/api/auth/openapi-refresh-token" payload = { "token": current_token, "refresh_token": refresh_token } try: response = requests.post( refresh_url, json=payload, headers={"Content-Type": "application/json"}, timeout=TIMEOUT )Technical Analysis
The script sends the application secret, user identifier, agent ID, access token, and refresh token to a URL constructed directly from the operator-controlled
EOFFICE_BASE_URL. It does not validate that the scheme is HTTPS, reject embedded URL credentials, restrict the destination to an approved host, or disable HTTP redirects.Sending the request to an HTTP URL exposes its body to interception or modification by a network-positioned attacker ...[truncated 1887 chars]
- Remediation
View remediation
Remediation Suggestions
- Parse
EOFFICE_BASE_URLwithurllib.parse.urlsplitbefore using it. - Require the
httpsscheme and reject plaintext HTTP, URL fragments, embedded usernames or passwords, and malformed hostnames. - Maintain an explicit allowlist of trusted OA hostnames where deployment architecture permits it.
- Set
allow_redirects=Falseon authentication and refresh requests. If redirects are operationally required, process them manually and only permit same-origin HTTPS destinations. - Keep TLS certificate verification enabled and document that users must install the correct private certificate authority rather than disabling verification.
- Use narrowly scoped OA application credentials and an authorized non-administrator identity unless administrative operations are explicitly required.
- Rotate
EOFFICE_SECRETand revoke outstanding tokens if an insecure URL or unexpected redirect has previously been used.
- Parse
