T09 · Insecure Skill Coding Practices
Error
- Location
- ui/server.py:846
- Finding
- Unauthenticated cross-origin access to credential and configuration APIs<![CDATA[ ## Vulnerability Details **File Location**: `ui/server.py:846-927, 1139-1177, 1400-1427` **Vulnerability Type**: Unauthenticated privileged localhost API with wildcard CORS **Risk Level**: High The dashboard backend exposes credential-management and OpenClaw configuration endpoints without authentication. It also permits requests from every browser origin. ### Vulnerable Code ```python def do_POST(self): parsed = urllib.parse.urlparse(self.path) payload = self._read_json_body() if payload is None: return routes = { "/api/key": self._route_save_key, "/api/key/delete": self._route_delete_key, "/api/config/set-role": self._route_set_role, "/api/config/add-fallback": self._route_add_fallback, "/api/config/add-image-fallback": self._route_add_image_fallback, "/api/config/remove-fallback": self._route_remove_fallback, "/api/config/add-allowlist": self._route_add_allowlist, "/api/config/remove-allowlist": self._route_remove_allowlist, "/api/config/set-primary": self._route_set_primary, "/api/config/set-image-model": self._route_set_image, "/api/config/auto-fix": self._route_auto_fix, "/api/config/backup": self._route_backup, "/api/config/rollback": self._route_rollback, "/api/config/validate": self._route_validate, "/api/channels/telegram": self._route_set_telegram, "/api/channels/telegram/add-user": self._route_tg_add_user, "/api/channels/telegram/remove-user": self._route_tg_remove_user, } handler = routes.get(parsed.path) if not handler: self._json({"ok": False, "error": "Route not found"}, 404) return try: res = handler(payload) except ValueError as exc: self._json({"ok": False, "error": str(exc)}, 400) return except Exception as exc: self._json({"ok": False, "error": f"Internal error: {exc}"}, 500) return s ...[truncated 5148 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. **Remove wildcard CORS** - Do not emit `Access-Control-Allow-Origin: *`. - If cross-origin operation is necessary, maintain an exact allowlist of trusted origins. - Return no CORS headers to all other origins. 2. **Require a per-launch authentication capability** - Generate a cryptographically random token when the server starts. - Deliver it only to the locally launched dashboard. - Require it in a custom header on every API request. - Compare tokens using a constant-time comparison. 3. **Validate browser request context** - Reject state-changing requests whose `Origin` is absent or not explicitly trusted. - Validate the `Host` header against the expected loopback host and port. - Add CSRF protection for every POST endpoint. - Use strict response headers, including an appropriate Content Security Policy. 4. **Restrict credential operations** - Replace the generic environment-variable API with provider-specific operations. - Permit only names listed in the registry's `authEnv` fields and explicitly supported keys such as `TELEGRAM_BOT_TOKEN`. - Reject all other environment-variable names. - Consider separating Switchboard-managed credentials from the shared workspace `.env`. 5. **Reduce exposed functionality** - Separate read-only status endpoints from privileged mutation endpoints. - Require explicit reauthentication or confirmation for credential deletion, Telegram policy changes, and rollback. - Avoid returning unnecessary filesystem paths and backup metadata. 6. **Harden request processing** - Enforce a small maximum `Content-Length` before reading request bodies. - Reject unexpected content types. - Add rate limiting and security event logging. - Preserve atomic writes and ensure all credential and backup directories remain owner-only. 7. **Prefer a stronger local transport** - Where supported, use a Unix-domain socket with filesystem permissions. ...[truncated 122 chars]
