The vulnerability is a classic Cross-Site Scripting (XSS) issue located in the ha-mcp package, specifically within the OAuth consent form generation logic. The root cause is the use of Python f-strings to construct HTML without proper escaping of user-controlled data.
The analysis of the security patch dc8eaa16a8550f885614655f14b6fd9fe429b278 clearly indicates the vulnerable functions and the fix. The patch primarily modifies src/ha_mcp/auth/consent_form.py.
Two functions were identified as vulnerable:
-
ha_mcp.auth.consent_form.create_consent_html: This function builds the main consent page. The patch shows that variables like client_id, client_name, redirect_uri, and state were previously embedded directly into the HTML. An attacker could provide malicious values for these parameters (e.g., during the OAuth client registration process) to inject scripts. The fix involves removing the use of some parameters and applying html.escape() to all remaining user-controlled data before rendering.
-
ha_mcp.auth.consent_form.create_error_html: This function generates an error page. The error and error_description parameters, which could be populated from URL query parameters in certain error scenarios, were also rendered unescaped. The patch applies html.escape() to these variables to mitigate the XSS risk.
These functions would be present in a runtime profile or stack trace when the OAuth consent form is displayed or when an error in the OAuth flow occurs. An attacker would trigger this by having a victim (the server operator) visit a specially crafted URL that initiates the OAuth flow with a malicious client or that directly leads to an error page with a malicious error message.
The fix in version 7.0.0 addresses this by consistently applying HTML escaping to all dynamic data rendered in the HTML, preventing the browser from interpreting user-supplied input as code.