T09 · Insecure Skill Coding Practices
- Location
- scripts/call_sls_data_agent.py:227
- Finding
- Arbitrary API Endpoint Receives Signed Requests and Sensitive SLS Context<![CDATA[ ## Vulnerability Details **File Location**: `scripts/call_sls_data_agent.py:227, 312-324, 349-352, 398-405` **Vulnerability Type**: Unrestricted authenticated endpoint override **Risk Level**: High ### Complete Code Snippet ```python endpoint = os.environ.get("SLS_DATA_AGENT_ENDPOINT") or DEFAULT_ENDPOINT ``` ```python def sign_request(self, request: SignatureRequest) -> SignatureRequest: credential = self._get_current_credential() access_key_id = call_or_none(credential, "get_access_key_id") access_key_secret = call_or_none(credential, "get_access_key_secret") security_token = call_or_none(credential, "get_security_token") if security_token: request.headers["x-acs-security-token"] = security_token canonical_request, signed_headers = build_canonical_request(request) hashed_canonical_request = sha256_hex(canonical_request.encode("utf-8")) string_to_sign = f"{ALGORITHM}\n{hashed_canonical_request}" signature = hmac.new( str(access_key_secret).encode("utf-8"), string_to_sign.encode("utf-8"), hashlib.sha256, ).hexdigest().lower() request.headers["Authorization"] = ( f"{ALGORITHM} Credential={access_key_id}," f"SignedHeaders={signed_headers},Signature={signature}" ) return request ``` ```python query_string = canonicalize_query(request.query) url = f"https://{self.host}{path}" + (f"?{query_string}" if query_string else "") try: response = self.transport( request.method, url, headers=dict(request.headers), data=request.body if request.method != "GET" else None, timeout=30, ) ``` ```python url = f"https://{self.host}{path}" try: try: response = self.transport( request.method, url, headers=dict(request.headers), data=request.body, timeout=self._request_timeout(), stream=True, ) ``` ### Technical Analysis The API en ...[truncated 2707 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Restrict production endpoints to exact approved service hostnames, such as `starops.<region>.aliyuncs.com`. 2. Normalize and validate the hostname before credential resolution or request signing: - Reject schemes, paths, query strings, ports, user-information components, IP literals, and malformed DNS names. - Do not rely on a simple suffix check that could accept names such as `aliyuncs.com.attacker.example`. 3. Maintain an explicit allowlist of supported Alibaba Cloud endpoints or derive the endpoint from a validated region. 4. If custom endpoints are required for testing, require an explicit unsafe-development flag and refuse to attach production credentials by default. 5. Separate endpoint configuration from credential policy so arbitrary endpoints can only use dedicated test credentials. 6. Warn users before transmitting project, logstore, or question content to a nonstandard endpoint. 7. Avoid returning raw untrusted endpoint responses as authoritative analysis without recording and clearly displaying the endpoint identity. ]]>
