Skip to content

feat(renderers): route web renderer and catalog URLs through the URL security policy - #4115

Draft
nan-yu wants to merge 2 commits into
feat/url-security-web-corefrom
feat/url-security-web-renderers
Draft

nan-yu wants to merge 2 commits into
feat/url-security-web-corefrom
feat/url-security-web-renderers

Conversation

@nan-yu

@nan-yu nan-yu commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Part of #4045. Stacked on #4104 (base feat/url-security-web-core).

This PR sends the URLs that web renderers use outside the resolver through the URL security policy from #4104, and makes @a2ui/markdown-it follow the A2UI Markdown subset by default. MCP app CSP capping and Vega chart URLs are in #4117.

Reviewer focus

  1. @a2ui/markdown-it default change: renderMarkdown now renders links as their text and images as their alt text. Links and images are opt-in through createMarkdownRenderer({allowLinks, allowImages}), and each URL goes through MarkdownRendererOptions.sanitizeUrl (added in feat(web_core): add URL security policy and plumb it to components and functions #4104). MarkdownItRenderer sets validateLink = () => true so schemes markdown-it previously dropped as raw syntax (such as javascript: links and SVG data images) pass through the URL rules and render as text or alt text too. This is a breaking change for apps that relied on links.
  2. Angular ComponentApiToProps: URL props (Image.url, Video.url, AudioPlayer.url, and any prop marked with mediaUrl() and friends) are now typed BoundProperty<string | undefined>, since the policy can block them.
  3. The deprecated Angular ComponentBinder.bind(context) path filters both top-level URL props (matching GenericBinder precedence: host urlProperties, schema mark, built-in basic list) and nested URL properties (NestedUrlProperties delegating to GenericBinder).
  4. Angular v0.9 ImageComponent, VideoComponent, and AudioPlayerComponent keep a defense-in-depth media baseline check (BasicCatalogComponent.checkedMediaUrl, respecting surface.urlSecurityPolicy.allowSvgDataUrls), matching @a2ui/web_core universal components.

Changes

  1. @a2ui/markdown-it
    1. Default follows conformance/adapter/markdown_subset.yaml; the two xfailed cases (link_rendered_as_text_without_target, image_syntax_not_rendered_as_image) now pass and are no longer marked as known gaps.
    2. New createMarkdownRenderer(options?) and MarkdownItRendererOptions. validateLink stays open so registerUrlRules handles every scheme uniformly: enabled links are checked as navigation URLs and images as media URLs, a blocked or throwing URL renders as its text or alt text, and without a sanitizeUrl, the built-in baseline checks apply.
  2. @a2ui/angular
    1. (v0.9) BasicCatalogComponent.checkedMediaUrl runs the media baseline on resolved URLs in ImageComponent, VideoComponent (url and posterUrl), and AudioPlayerComponent, and ImageComponent binds [attr.src]="url() || null" so a blocked URL leaves out src instead of loading undefined as a relative URL.
    2. (v0.9) TextComponent passes sanitizeUrl (the surface's sanitizeUrl with component info) to MarkdownRenderer.render.
    3. (v0.9) ComponentBinder.bind(context) filters top-level and nested URL props; bindNode already gets filtered values from GenericBinder.
    4. (v0.8) Image, Video, and AudioPlayer apply the built-in media baseline (v0.8 has no policy). AudioPlayer uses [attr.src], so a blocked or missing URL leaves out src.
  3. @a2ui/react
    1. (v0.8) Image, Video (including the YouTube embed path), and AudioPlayer apply the built-in media baseline.
    2. The component in MarkdownComponentContext receives sanitizeUrl(url, context), bound to the surface of the Text it renders. The check can't travel in the host element's attribute, so renderMarkdownHost keeps it in a bounded table under an ID the element carries until the element connects. A host rendered without a check gets the baseline; a host whose check was pushed out of the table blocks every URL.
  4. @a2ui/lit (v0.8): Surface (styles.logoUrl), Image, Video, and AudioPlayer now share a local checkMediaUrl helper backed by PermissiveUrlSecurityPolicy instead of the deprecated sanitizeMediaUrl (so surrounding whitespace is blocked rather than trimmed, matching Angular and React v0.8).
  5. CHANGELOG entries for each package (including default subset notes for Angular DefaultMarkdownRenderer and Lit markdown directive) and an updated "Links and images" section in the markdown-it README.

React and Lit v0.9/v1.0 use the universal basic catalog elements from @a2ui/web_core, which #4104 already covers.

Impact & risks

  1. Apps using renderMarkdown (including Angular DefaultMarkdownRenderer and Lit's markdown directive fallback) lose rendered links and images until they switch to createMarkdownRenderer. This matches the documented Markdown subset that Flutter and SwiftUI already follow.
  2. React apps that render Markdown through MarkdownComponentContext need to call the new sanitizeUrl prop for links and images; components that ignore it still render URLs without the policy.
  3. Custom Angular components that read a URL prop as string get a type error until they handle undefined.

Testing

  1. @a2ui/markdown-it: 27 unit tests (subset default, opt-in links and images, javascript: / vbscript: / file: / SVG data links rendered as text/alt, autolinks, reference links, nested links/images, attribute breakout escaping, throwing sanitizers, baseline fallback, tag classes) and 7/7 Markdown subset conformance cases pass.
  2. @a2ui/angular: yarn test passes (bind/bindNode URL filtering including nested schemas and urlProperties overrides, v0.9 Image baseline + allowSvgDataUrls, Text passing sanitizeUrl, v0.9 integration with AllowlistUrlSecurityPolicy, v0.8 Image/Video/AudioPlayer baseline rejections), plus angular-explorer passes locally (yarn test).
  3. @a2ui/react: vitest run (555 passed, 1 skipped, including a MarkdownComponentContext test with an AllowlistUrlSecurityPolicy) and explorer Karma (278/278) pass.
  4. @a2ui/lit: full yarn test and ESLint pass.

🤖 Agent-generated

@github-project-automation github-project-automation Bot moved this to Todo in A2UI Nov 10, 2026
@nan-yu
nan-yu force-pushed the feat/url-security-web-renderers branch from 56f7367 to c536a18 Compare November 10, 2026 05:24

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements URL security policies and baseline URL checks across Angular, Lit, React, and Markdown-it renderers. It applies the surface's URL security policy to URL properties in the Angular renderer (v0.9), introduces built-in baseline checks for media URLs in v0.8 renderers (Angular, Lit, React), and updates the Markdown-it renderer to follow the A2UI Markdown subset by default. As there are no review comments, I have no feedback to provide.

@nan-yu
nan-yu force-pushed the feat/url-security-web-renderers branch from c536a18 to 9dbe2d7 Compare November 10, 2026 05:55
@nan-yu
nan-yu force-pushed the feat/url-security-web-core branch 3 times, most recently from cde736f to 76b0957 Compare December 3, 2026 00:55
@nan-yu
nan-yu force-pushed the feat/url-security-web-renderers branch 4 times, most recently from be34779 to dbde12a Compare December 3, 2026 01:19
@nan-yu
nan-yu force-pushed the feat/url-security-web-core branch from b813633 to e38ab5e Compare December 3, 2026 19:12
…icy (#4045)

- @a2ui/markdown-it follows the Markdown subset by default; createMarkdownRenderer
  opts in to links and images, whose URLs go through
  MarkdownRendererOptions.sanitizeUrl (navigation for links, media for images).
- Angular v0.9: ImageComponent leaves out src when the policy blocks url, the
  deprecated ComponentBinder.bind(context) filters URL props like bindNode,
  TextComponent passes the surface policy to the MarkdownRenderer, and
  ComponentApiToProps types URL props as possibly undefined.
- v0.8 React/Angular Image, Video, AudioPlayer and the Lit surface logo apply
  the built-in media URL baseline.
@nan-yu
nan-yu force-pushed the feat/url-security-web-renderers branch from acf7421 to e5d6ebc Compare December 3, 2026 19:13

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant