T09 · Insecure Skill Coding Practices
- Location
- scripts/damai_mercado_market_intelligence.py:36
- Finding
- Credentials and personal data can be transmitted to environment-controlled endpoints<![CDATA[ ## Vulnerability Details **File Location**: `scripts/damai_mercado_market_intelligence.py:36-78`; `scripts/upload_image.py:21-73`; `scripts/onboarding.py:68-85, 209-246` **Vulnerability Type**: Unrestricted endpoint override for authenticated requests **Risk Level**: High ### Relevant Code ```python def get_api_base() -> str: """Gateway base address: environment variable first, production fallback.""" return ( os.environ.get("LINKFOX_TOOL_GATEWAY") or "https://tool-gateway.linkfox.com" ).rstrip("/") ``` ```python 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", ""), "MESSAGE_ID": os.environ.get("MESSAGE_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") with urlopen(req, timeout=150) as response: return json.loads(response.read().decode("utf-8")) ``` The onboarding client separately permits authentication endpoints 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", ) ``` ### Technical Analysis The code treats environment variables as trusted network destinations and attaches sensitive authentication material without validating the resulting scheme or host. Depending on the operation, transmitted data can include: - LinkFox API keys - Acc ...[truncated 1669 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Hardcode or strictly allowlist the documented LinkFox hosts for authenticated traffic. 2. Require `https` and reject HTTP, IP-literal destinations, user-info components, unexpected ports, and unapproved subdomains. 3. Disable automatic cross-origin redirects for requests carrying credentials, or revalidate every redirect target and remove authentication headers on origin changes. 4. Separate test endpoint support from production builds. Require an explicit development mode and never use production credentials with test overrides. 5. Validate the presigned upload URL against the expected object-storage hostname before reading and uploading the local file. 6. Send only metadata required by the specific API. Remove `MESSAGE_ID`, `MODE_ID`, `APP_NAME`, and similar headers unless each is demonstrably necessary. 7. Add automated tests confirming that malformed and unapproved endpoint overrides are rejected before any credential-bearing request is issued. ]]>
