T09 · Insecure Skill Coding Practices
- Location
auth.py:159- Finding
OAuth authorization flow lacks state validation
- Content
View full analysis
None: # noqa: N802 parsed = urllib.parse.urlparse(self.path) params = urllib.parse.parse_qs(parsed.query) code = params.get("code", [None])[0] error = params.get("error", [None])[0] self.send_response(200) self.send_header("Content-Type", "text/html; charset=utf-8") self.end_headers() msg = "Authorization successful
Return to the terminal.
" if error: self.server.auth_result = {"error": error} msg = f"Authorization failed
Reason: {error}
" elif code: self.server.auth_result = {"code": code} else: self.server.auth_result = {"error": "missing_code"} msg = "Error
No authorization code was received.
" self.wfile.write(msg.encode("utf-8")) ``` The corresponding authorization request is constructed without a `state` parameter: ```python def run_oauth_flow(authorization_code: str | None = None) -> None: """Run the complete OAuth authorization flow.""" client_id, client_secret = _require_oauth_client() port = int(os.environ.get("DIDA_CALLBACK_PORT", str(DEFAULT_CALLBACK_PORT))) redirect_uri = f"http://localhost:{port}/callback" if authorization_code: code = authorization_code else: auth_url = ( f"{OAUTH_BASE}/authorize?" + urllib.parse.urlencode({ "client_id": client_id, "scope": "tasks:write tasks:read", "redirect_uri": redirect_uri, "response_type": "code", }) ) print(f"\nOpen th ...[truncated 2446 chars]- Remediation
View remediation
