T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/tiktok_shop_product_detail.py:36
- Finding
- Credential Exfiltration Through Unvalidated Endpoint Overrides<![CDATA[ ## Vulnerability Details **File Location**: `scripts/tiktok_shop_product_detail.py:36-78`; `scripts/onboarding.py:72-85, 188-196, 228-246, 402-421, 454-462` **Vulnerability Type**: Unvalidated credential-bearing network destination **Risk Level**: High ### Vulnerable Code ```python def get_api_base() -> str: """Gateway base address: LINKFOX_TOOL_GATEWAY takes precedence.""" return (os.environ.get("LINKFOX_TOOL_GATEWAY") or "https://tool-gateway.linkfox.com").rstrip("/") def get_api_url(): sys.path.insert( 0, os.path.join( os.path.dirname(os.path.abspath(__file__)), "..", "..", "_shared", ), ) return get_api_base() + API_PATH def call_api(params): api_url = get_api_url() api_key = get_api_key() data = json.dumps(params).encode("utf-8") headers = { "Authorization": api_key, "Content-Type": "application/json", "User-Agent": "LinkFox-Skill/2.0", "SESSION_ID": os.environ.get("SESSION_ID", ""), "MODE_ID": os.environ.get("MODE_ID", ""), "APP_NAME": os.environ.get("APP_NAME", ""), } req = Request( api_url, data=data, headers=headers, method="POST", ) try: with urlopen(req, timeout=150) as response: return json.loads(response.read().decode("utf-8")) ``` The onboarding implementation similarly permits all authentication-related origins to be replaced: ```python def _agent_base() -> str: return _env_base( "LINKFOX_AGENT_API_URL", "https://tool-gateway.linkfox.com", "LINKFOX_TOOL_GATEWAY", ) def _login_base() -> str: return _env_base("LINKFOX_LOGIN_API_URL", "https://api.linkfox.com") def _agent_user_base() -> str: return _env_base( "LINKFOX_AGENT_USER_API_URL", "https://agent-api.linkfox.com", ) ``` Those configurable destinations receive sensitive requests: ```p ...[truncated 3774 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Pin production requests to an explicit allowlist: - `https://tool-gateway.linkfox.com` - `https://api.linkfox.com` - `https://agent-api.linkfox.com` 2. Parse endpoints with `urllib.parse.urlsplit` and require: - HTTPS - An exact approved hostname - No username or password - No unexpected port - No fragments 3. Disable endpoint overrides in production. If development overrides are necessary, require an explicit development-mode flag and prohibit use of production credentials in that mode. 4. Disable cross-origin redirects or validate the destination of every redirect before forwarding credentials. 5. Separate clients by trust domain so login tokens cannot accidentally be attached to gateway or feedback requests. 6. Add automated tests proving that HTTP URLs, unapproved hosts, absolute-path URL tricks, user-information components, and unexpected ports are rejected. ]]>
