Skip to main content
Menu
Advisories

Reflected XSS in FrontMCP placeholder widgets via crafted resources/read URI

GHSA-XP6R-GGXC-J7Q8Published Updated GitHub

Description

FrontMCP reflects an attacker-controlled tool name from a resources/read widget URI into generated MCP widget HTML without HTML escaping.

The SDK accepts widget URIs using:

const match = uri.match(
  /^ui:\/\/widget\/([^.]+)\.(\w+)$/
);

The [^.]+ capture accepts HTML markup such as <script>...</script> as the tool name.

When no static widget exists for the parsed name, FrontMCP falls back to the placeholder widget generated by @frontmcp/uipack. The placeholder interpolates the parsed value directly into HTML:

<p style="color:#9ca3af;font-size:0.75rem;">
  Tool: <code>${toolName}</code>
</p>

A crafted URI such as:

ui://widget/<script>window["__frontmcp_xss"]=42</script>.html

therefore causes the server to return a text/html;profile=mcp-app resource containing the injected <script> element verbatim.

This was reproduced end-to-end over HTTP against released @frontmcp/sdk@1.7.2 and @frontmcp/uipack@1.7.2.

The exact HTML returned by the server was executed in an HTML execution environment and set:

window.__frontmcp_xss = 42

The generated widget CSP also includes 'unsafe-inline', so the injected inline script is permitted by the document's own policy.

Details

The attacker-controlled source is the URI parameter of an MCP resources/read request:

{
  "method": "resources/read",
  "params": {
    "uri": "ui://widget/<payload>.html"
  }
}

The widget URI parser extracts the tool name using:

/^ui:\/\/widget\/([^.]+)\.(\w+)$/

This performs no identifier validation or HTML escaping.

For example:

ui://widget/<script>window["__frontmcp_xss"]=42</script>.html

is parsed with:

toolName =
<script>window["__frontmcp_xss"]=42</script>

The resource handler then attempts to retrieve a pre-generated widget for that name.

For an unknown name, execution reaches the built-in placeholder path:

resources/read
  -> parseWidgetUri()
  -> attacker-controlled toolName
  -> static widget lookup misses
  -> generatePlaceholderWidget(toolName)
  -> createDefaultBaseTemplate({ toolName })
  -> raw interpolation into HTML

The affected placeholder body contains:

Tool: <code>${toolName}</code>

without escaping.

Consequently the generated response contains:

Tool: <code><script>window["__frontmcp_xss"]=42</script></code>

The same generated document correctly escapes this value in its <title>, demonstrating inconsistent output encoding:

<title>
Widget: &lt;script&gt;window["__frontmcp_xss"]=42&lt;/script&gt;
</title>

while the body still contains the raw executable element.

The returned document is explicitly identified as:

text/html;profile=mcp-app

and its generated CSP contains an inline-script allowance:

script-src 'self' 'unsafe-inline' ...

The injected inline script is therefore not blocked by the widget's own CSP.

This issue is distinct from tool-output rendering XSS because the malicious input originates directly from the resources/read URI and reaches a different rendering sink.

PoC

Install the released packages:

npm install \
  @frontmcp/sdk@1.7.2 \
  @frontmcp/uipack@1.7.2

Start a normal FrontMCP server with an ordinary tool. No custom widget configuration is necessary.

Initialize an MCP session and send the following request:

{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "resources/read",
  "params": {
    "uri": "ui://widget/<script>window[\"__frontmcp_xss\"]=42</script>.html"
  }
}

The server responds successfully:

HTTP 200
mimeType = text/html;profile=mcp-app

The returned HTML contains the payload verbatim:

Tool: <code><script>window["__frontmcp_xss"]=42</script></code>

The response also contains the escaped version in the title:

<title>
Widget: &lt;script&gt;window["__frontmcp_xss"]=42&lt;/script&gt;
</title>

and the generated CSP includes:

script-src 'self' 'unsafe-inline' ...

Executing the exact HTML returned by the server produced:

window.__frontmcp_xss = 42

A benign control request:

{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "resources/read",
  "params": {
    "uri": "ui://widget/ping.html"
  }
}

returns the expected placeholder:

Tool: <code>ping</code>

with no injected script.

The reproduced behavior is therefore:

ATTACK

resources/read
ui://widget/<script>window["__frontmcp_xss"]=42</script>.html

-> HTTP 200
-> text/html;profile=mcp-app
-> raw attacker-controlled <script> returned
-> exact returned HTML executes the script


CONTROL

resources/read
ui://widget/ping.html

-> HTTP 200
-> normal placeholder
-> no injected script

The server-side source-to-sink path and executable returned widget HTML are confirmed.

The current PoC does not yet demonstrate an independent victim MCP host being induced by a separate attacker to request and automatically render the crafted ui://widget/... URI. This delivery prerequisite should be considered when evaluating exploitability and severity.

Suggested fix

HTML-escape the tool name before inserting it into the placeholder document.

For example:

--- a/libs/uipack/src/adapters/base-template.ts
+++ b/libs/uipack/src/adapters/base-template.ts
@@
-<p style="color:#9ca3af;font-size:0.75rem;">
-  Tool: <code>${toolName}</code>
-</p>
+<p style="color:#9ca3af;font-size:0.75rem;">
+  Tool: <code>${escapeHtml(toolName)}</code>
+</p>

The SDK should additionally restrict widget URIs to valid tool-name characters.

For example:

-const match = uri.match(
-  /^ui:\/\/widget\/([^.]+)\.(\w+)$/
-);
+const match = uri.match(
+  /^ui:\/\/widget\/([A-Za-z0-9_-]+)\.(html|js)$/
+);

Both protections should be applied:

  1. HTML escaping prevents injection at the rendering sink.
  2. Strict identifier validation prevents markup from reaching the widget generator.

Regression tests should include payloads such as:

ui://widget/<script>alert(1)</script>.html

and:

ui://widget/<img src=x onerror=alert(1)>.html

and verify that no executable DOM elements are generated.

As defense in depth, removing 'unsafe-inline' from the default widget CSP would reduce the impact of future HTML-injection vulnerabilities.

Impact

A client-controlled resources/read URI can cause FrontMCP to generate and return an MCP widget containing attacker-controlled executable JavaScript.

The response is served as:

text/html;profile=mcp-app

and includes the normal FrontMCP widget runtime together with a CSP that permits inline scripts.

The confirmed impact is an executable HTML/script injection primitive in the server-generated MCP widget document.

If an attacker can induce a compatible victim MCP host to request and render the crafted widget URI, the injected JavaScript would execute in that widget's rendering context.

Potential consequences then depend on the consuming host's widget isolation and bridge permissions and may include manipulation or impersonation of trusted widget UI and access to information or capabilities exposed to the widget context.

The current proof confirms the vulnerable server response and script execution from the exact returned HTML. It does not yet establish the independent victim-host delivery step, so downstream host/session impact should not be assumed beyond what the consuming host permits.

Affected versions

References

GitHub · agentfront/frontmcp