Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements URL security policy enforcement for MCP applications and Vega charts. For MCP apps, it caps CSP domain lists and sanitizes 'ui/open-link' requests. For Vega charts, it introduces a custom loader wrapper to validate data, image, and navigation URLs against the surface's security policy. The feedback highlights a critical security bypass in the Vega chart loader where relative URLs resolved against a custom 'baseURL' could evade validation; resolving the URL via the base loader before applying the security policy check is recommended to mitigate this vulnerability.
| async sanitize(uri, options) { | ||
| const context: UrlContext = options?.context === 'href' ? 'navigation' : 'media'; | ||
| const allowed = typeof uri === 'string' ? sanitizeUrl(uri, context) : undefined; | ||
| if (allowed === undefined) { | ||
| throw new Error(BLOCKED_CHART_URL_MESSAGE); | ||
| } | ||
| return (await ready).sanitize(allowed, options); | ||
| }, |
There was a problem hiding this comment.
There is a potential security bypass when handling relative URLs or specs with a custom baseURL. If sanitizeUrl is called on the raw relative uri (e.g., 'data.csv'), it will likely be allowed by the policy or baseline checks. However, when it is subsequently passed to (await ready).sanitize(allowed, options), the base Vega loader will resolve it against the configured baseURL (which could point to an untrusted external domain), fetching the resource from the resolved absolute URL without ever validating it against the security policy.
To prevent this bypass, we should first resolve the URL using the base loader's sanitize method, and then apply the security policy check on the fully resolved absolute URL.
async sanitize(uri, options) {
const resolved = await ready;
const sanitized = await resolved.sanitize(uri, options);
const context: UrlContext = options?.context === 'href' ? 'navigation' : 'media';
const allowed = sanitizeUrl(sanitized.href, context);
if (allowed === undefined) {
throw new Error(BLOCKED_CHART_URL_MESSAGE);
}
sanitized.href = allowed;
return sanitized;
},There was a problem hiding this comment.
Thanks. In this component the base loader is a plain vega.loader() with no baseURL, and the loader we pass as options.loader takes precedence over a spec's usermeta.embedOptions.loader, so a spec can't set one today. Still, the check shouldn't depend on that. Fixed in a7dcb8a: the policy still checks the raw URI first (so relative-URL rules and rewrites apply to what the spec wrote), and when the base loader changes the URL, for example by resolving it against baseURL, the resolved URL is checked again before Vega fetches or opens it. An unchanged URL is checked once, so a rewritten proxy URL isn't re-checked. Covered by a new test in url_policy_loader.test.ts.
🤖 Agent-generated
cde736f to
76b0957
Compare
44347f9 to
8894707
Compare
b813633 to
e38ab5e
Compare
…L security policy McpApp checks each _meta.ui.csp source against the surface's URL security policy (connect/resource domains as media, frame domains as iframe, base URI domains as navigation) and drops the ones it doesn't allow before the CSP is built. ui/open-link URLs are checked as navigation. VegaChart passes Vega a loader that checks data URLs and image marks as media and href links as navigation before Vega fetches or opens them. Part of #4045.
…4045) vega-tooltip renders the image field of an object tooltip as an <img> without the Vega loader, and vega-embed merges usermeta.embedOptions from the spec into the embed options, so a spec could turn the actions menu back on with its own editorUrl. The chart now passes tooltip options whose formatter checks the image as media, and removes usermeta.embedOptions in transformSpec.
…4045) - Scrub external CSS url()/image-set() references (cursor signals and SVG paint attributes) via MutationObserver on the Vega chart container while preserving local same-document #id gradient and clip-path refs. - Check upgraded http/https and scheme-less variants for MCP CSP host/scheme sources (*, http:, ws:, http://h, ws://h, and scheme-less hosts). - Stop logging raw malformed URLs in McpAppBridge ui/open-link and pass {functionName: 'ui/open-link'} to surface warnings.
… inputs (#4045) - Force config.events/eventConfig globalCursor: false and bind: 'container', and strip element/src/formaction/style/input:'image' from Vega/VL bindings. - Watch document.body.style.cursor and form src/formaction/type=image attributes in observeCssUrls, preserve valid same-document url(#...) inside style, and clean up observer on embed errors. - Update mcp README CSP scheme matching description.
…der's CSS guard (#4045)
0385508 to
e092412
Compare
Summary
Part of #4045. Stacked on #4104 (base
feat/url-security-web-core).This PR puts the two interactive catalog packages through the URL security policy from #4104:
McpAppcaps the_meta.ui.cspdomain allowlists before sending them to the sandbox proxy.McpAppBridgechecksui/open-linkURLs asnavigationbefore opening them, reporting blocked requests with{functionName: 'ui/open-link'}and without logging raw malformed URLs.VegaChartchecks every URL path in a spec: data/image/hrefvia a Vega loader, tooltipimagefields via a tooltip formatter wrapper, strippedusermeta.embedOptions, disabledglobalCursor, an allowlist for parameter bindings (knowninputtypes and keys only, applied to the spec and again to the compiled Vega spec throughpatch), and a DOMMutationObserverscrubbing CSSurl(...)/image-set(...), form image/action attributes, andon*handler attributes on form elements while preserving same-document#idpaint references. This covers both v0.9 and v1.0 entry points, which share the element.@a2ui/sandboxdocuments onSandboxResource.urlthat hosts usingurlsandbox mode must mark the property withiframeUrl()or callcontext.sanitizeUrl(url, 'iframe').The TypeScript core API is unchanged.
Reviewer focus
mcp_app_csp.ts). The policy API takes URLs, not source expressions, so each source becomes one or more probe URLs:https://andwss://sources checkhttps;http://,ws://, and scheme-less hosts check bothhttpandhttps, because CSP allows scheme upgrades and scheme-less hosts follow the frame origin.*.example.comcheckshttp://*.example.com/andhttps://*.example.com/. The URL parser accepts*as a host label, andAllowlistUrlSecurityPolicycompares it literally, so a wildcard source passes only a wildcard entry that covers it (*.example.com,*.com), never an exact entry such ascdn.example.com.*,http:, andws:checkhttp://*/andhttps://*/;https:andwss:checkhttps://*/.:*) is checked with the default port and port 1 per scheme, so it passes only when the policy allows any port.data:andblob:load nothing from a server and are kept, as the allowlist policy does for host-less URLs.'self', other schemes) is dropped; the sandbox already dropped quoted keywords.VegaChartloader, tooltip, binding, and DOM CSS coverage (url_policy_loader.ts,url_policy_tooltip.ts,url_policy_dom_css.ts,vegaChart.ts):createUrlPolicyLoaderchecks the input URL and re-checks any URL resolved by the base loader (such as viabaseURL), rejecting with a constant message that never leaks the URL.createUrlPolicyTooltipFormatterwrapsvega-tooltip'sformatValueto checkvalue.imageasmedia(omitting blocked images, replacing rewritten ones).transformSpecremovesusermeta.embedOptionsand disablesglobalCursorand externalbindselectors (config.events/eventConfig). Parameter bindings go through an allowlist, because Vega's generic input generator copies every binding key onto the<input>as an attribute (soonfocus/autofocuswould run script):'scales','legend', legend bindings, input bindings with a knowninputtype keeping onlyinput,name,options,labels,min,max,step,debounce,placeholder,autocomplete, and Vega-Lite per-field maps of those. Anything else (includingelementtargets andinput: 'image') removes the binding. The walk coversparams,signals, and the deprecatedselectionat any depth, includingconfig, and skips data.patchembed option, which catches every binding form Vega-Lite compiles intosignals/config.signals.observeCssUrlswatcheswrapper(anddocument.body.style.cursor) viaMutationObserverbeforeembed(...)runs, resettingcursorwithurl(/image-set(and removing external or backslash-escapedurl(...)values from SVG paint attributes and formsrc/formaction/type=image, while keeping same-document#idand<location>#...gradient and clip-path refs.Changes
@a2ui/catalog-mcpmcp_app_csp.ts:cspSourceToUrls,isCspSourceAllowed,capCspByUrlPolicy(package-internal).McpApp.resolveResourcecapscspbefore the resource goes to the sandbox proxy (connectDomains/resourceDomainsasmedia,frameDomainsasiframe,baseUriDomainsasnavigation). An element without a component context usesPermissiveUrlSecurityPolicy.McpAppBridgetakessanitizeUrl(ui/open-linkchecked asnavigation,{functionName: 'ui/open-link'}fromMcpApp, and malformed URL warnings omit the raw URL).FrameTestHarnesstakesMessageProcessorOptionsfor tests.@a2ui/catalog-vegacharturl_policy_loader.ts,url_policy_tooltip.ts, andurl_policy_dom_css.ts; loader types exported from rootsrc/index.ts.vega-tooltipdependency (^0.35.2, matchingvega-embed).A2uiVegaChartElement,transformSpec,VegaEmbedOptions, README, and CHANGELOG.@a2ui/sandboxSandboxResource.url.Impact & risks
McpAppkeeps every CSP source it kept before except sources with schemes other thanhttp(s),ws(s),data, andblob.VegaChartnow applies the shared baseline to spec URLs even without a policy: protocol-relative URLs (//host/data.csv) anddata:URLs that aren't images, audio, or video (such asdata:text/csv,...) are blocked,usermeta.embedOptionsand external CSSurl(...)values incursor/SVG paint attributes are stripped, andglobalCursor/image/externalbindinputs are disabled. Inlinedata.valuesis the replacement. Hosts should still keep animg-srcCSP as defense in depth.VegaEmbedFnthat doesn't forwardoptions.loader,options.tooltip, andoptions.patchtovega-embedbypasses those checks (the spec pre-pass still removes unsafe bindings). The README says so.URL_BLOCKEDwarning on the surface, once per dedupe entry.input: 'image',submit, ...) or extra attributes lose those bindings.Testing
@a2ui/catalog-mcp: Karma suite (102/102) and Node suite (196/196) pass, coveringmcp_app_csp.test.ts(scheme upgrades, scheme-less hosts,*, port wildcards, rewrites, unmappable sources),mcp_app.test.ts(capped CSP and redactedURL_BLOCKEDwarning withfunctionName: 'ui/open-link'), andmcp_app_bridge.test.ts(navigationchecks, rewrites, non-http(s)skip, redacted malformed-URL warnings).@a2ui/catalog-vegachart: all 54 Node tests pass (new: binding allowlist, bindings inconfig/selection/nested views with inline data untouched, thepatchoption on a compiled Vega spec,on*attribute scrubbing, and both superseded-render races; each fails on the previous code) (url_policy_loader.test.ts,url_policy_dom_css.test.ts,vegaChart.test.tswith realvega-embedtests for loader, tooltip,usermeta.embedOptions, CSS cursor/fill scrubbing,globalCursor,bind, and preserved local clip-path/gradient refs, plusv0_9/v1).@a2ui/sandbox:yarn testand ESLint pass.tsc, ESLint (0 errors), and Prettier pass across all modified packages.🤖 Agent-generated