Skip to content

feat(tooling): warn about unmarked catalog URL props and add an agent pre-send URL check - #4116

Draft
nan-yu wants to merge 16 commits into
feat/url-security-web-corefrom
feat/url-security-tooling
Draft

nan-yu wants to merge 16 commits into
feat/url-security-web-corefrom
feat/url-security-tooling

Conversation

@nan-yu

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

Copy link
Copy Markdown
Collaborator

Summary

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

This PR adds two optional safety nets around the URL security policy:

  1. A catalog tooling warning for component properties whose names look like URLs but carry no x-a2ui-url-context, plus a CI check that fails for the catalogs in this repository.
  2. checkPayloadUrls in @a2ui/agent, which lets an agent check a payload's URLs against a policy before sending it, and report or strip blocked values.

Reviewer focus

  1. The name heuristic (url, uri, href, src, or ending in Url, URL, Uri, URI, _url, _uri) and the "may hold a string" rule, which skips properties typed only as object, array, number, boolean, or null.
  2. Catalog.fromJson now calls console.warn once per catalog ID when it finds problems in a v0.9+ catalog. Is a console warning the right channel for the TS loader?
  3. checkPayloadUrls strips by replacing a blocked value with an empty string rather than deleting the property, so required URL props (such as Image.url) still validate and the renderer's baseline resolves them to unset.
  4. The assembler writes the basic catalog's built-in marks into assembled catalogs, since an assembled catalog has a new ID and renderers only recognize those props by the basic catalog IDs.

Changes

  1. tools/build_catalog/url_annotations.py (new, standard library only): find_url_annotation_problems(catalog) walks component properties (local $refs, allOf/anyOf/oneOf, nested properties, array items) and reports unmarked URL-like properties and unknown mark values. The basic catalogs' Image.url, Video.url, Video.posterUrl, and AudioPlayer.url count as marked through the same built-in list the SDKs use. Run as a script, it exits 1 on any problem.
  2. assemble_catalog.py logs a warning per problem in the assembled catalog and writes the basic catalog's built-in marks into it.
  3. .github/workflows/validate_specifications.yml runs the check on catalogs/. It passes today: the only URL-like component properties are the basic catalog's built-in ones, so no catalog file changes. The check also reports unknown mark values and marks under additionalProperties, patternProperties, or unevaluatedProperties, which catalog loaders reject, and follows each shared $ref once per component, so deeply shared definitions can't make it slow.
  4. @a2ui/web_core: Catalog.fromJson warns through console.warn with the same rules (security/url_annotation_check.ts, package-internal).
  5. @a2ui/agent: checkPayloadUrls(catalogs, payload, {policy, onBlocked}) returns {messages, blocked}. It reads URL props from catalog marks, the basic built-in list, and the policy's urlProperties map, and replays the messages in order on the renderer's DataModel, the way the renderer applies them: literal values, data bindings to values the same payload sets (rechecked after each update that changes them, through a path index), the basic catalogs' theme.iconUrl, and the literal URL of an openUrl call as navigation (reported with functionName: 'openUrl'). Each v1.0 component is read with the catalog it names. A createSurface that follows updates to its surface is checked too, since the renderer applies it when the surface is new. An unknown onBlocked throws a TypeError. Reports carry only redactUrl output. The SDK re-exports AllowlistUrlSecurityPolicy, PermissiveUrlSecurityPolicy, and the policy types. The Python agent SDK has the same check in feat(python): add an optional pre-send URL check to the Python agent SDK #4122.
  6. READMEs for tools/build_catalog and @a2ui/agent; CHANGELOG entries for @a2ui/web_core and @a2ui/agent.

Impact & risks

  1. Additive. Agents that don't call checkPayloadUrls behave as before.
  2. Apps that load custom catalogs with unmarked URL-like props through Catalog.fromJson see one console warning per catalog.
  3. The agent check can't resolve function calls such as formatString, relative bindings inside list templates, or data set by earlier payloads. The renderer still checks those, and the README says so.

Testing

  1. tools/build_catalog: pytest tools/build_catalog/tests (new test_url_annotations.py, assembler warning and basic-mark tests); pyink --check.
  2. @a2ui/web_core: new url_annotation_check.test.ts (heuristic, nesting, recursion, built-in list, published basic catalogs, fromJson warning once per ID); every dist/**/*.test.js passes.
  3. @a2ui/agent: new tests/unit/utils/url-check.test.ts (baseline default, allowlist, custom marks, nested props, none, data bindings and update order, strip copies, v1.0 inline components and @catalogId, v0.9 theme.iconUrl, host urlProperties override, list templates, surface lifetimes, openUrl literals, recheck order, throwing policy); full vitest run passes.
  4. python3 tools/build_catalog/url_annotations.py catalogs exits 0.
  5. test_assemble_catalog.py::test_circular_dependency fails locally when the repository sits fewer than four directories below /, on the base branch too; it is unrelated to this PR.

🤖 Agent-generated

@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 introduces a mechanism to validate and annotate URL properties in catalogs and payloads. It adds url_annotations.py to check for missing x-a2ui-url-context marks, integrates these checks into catalog assembly and loading, and implements checkPayloadUrls in the agent to validate payload URLs before sending. The review feedback highlights two main improvements: ensuring applyDataUpdate correctly initializes nested arrays when encountering numeric path segments, and safely validating ASCII-only digits in Python's isdigit() check to avoid potential conversion errors.

Comment on lines +473 to +477
const next = (current as JsonObject)[segment];
if (!isJsonObject(next) && !Array.isArray(next)) (current as JsonObject)[segment] = {};
current = (current as JsonObject)[segment] as JsonObject | unknown[];
}
const last = segments[segments.length - 1];

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.

high

In applyDataUpdate, when a nested path does not exist, it is always initialized as an empty object {}. If the next segment in the path is a numeric index (e.g., /arr/0/prop), the parent should be initialized as an empty array [] instead of {} to prevent data model corruption and type mismatch errors in the renderer.

  for (let i = 0; i < segments.length - 1; i++) {
    const segment = segments[i];
    const next = (current as JsonObject)[segment];
    if (!isJsonObject(next) && !Array.isArray(next)) {
      const nextSegment = segments[i + 1];
      (current as JsonObject)[segment] = /^\d+$/.test(nextSegment) ? [] : {};
    }
    current = (current as JsonObject)[segment] as JsonObject | unknown[];
  }

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 6f0b812: a missing container is created as a list when the next segment is an index. The mirror is local (it's only read to resolve bindings, never sent), so this was about reading paths like /fresh/0/url the same way the renderer would; added a test for indexed paths in existing and new lists. The Python port in #4122 had the same gap plus one that replaced existing lists, fixed there in 775d639.

🤖 Agent-generated

Comment thread tools/build_catalog/url_annotations.py Outdated
part = part.replace("~1", "/").replace("~0", "~")
if isinstance(current, dict) and part in current:
current = current[part]
elif isinstance(current, list) and part.isdigit() and int(part) < len(current):

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.

medium

In Python, str.isdigit() returns True for various Unicode digit characters (such as superscript numbers like ²), but calling int() on some of these characters will raise a ValueError. To safely ensure the segment is a valid ASCII non-negative integer before converting it, check part.isascii() as well.

Suggested change
elif isinstance(current, list) and part.isdigit() and int(part) < len(current):
elif isinstance(current, list) and part.isascii() and part.isdigit() and int(part) < len(current):

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 6f0b812: the list index check now requires isascii() too. Same change in the Python agent check (#4122).

🤖 Agent-generated

@nan-yu
nan-yu force-pushed the feat/url-security-web-core branch 2 times, most recently from 423385e to cde736f Compare December 3, 2026 00:49
@nan-yu
nan-yu force-pushed the feat/url-security-tooling branch from 3baf1e6 to 69cc45b Compare December 3, 2026 00:52
@nan-yu
nan-yu force-pushed the feat/url-security-web-core branch from cde736f to 76b0957 Compare December 3, 2026 00:55
@nan-yu
nan-yu force-pushed the feat/url-security-tooling branch 3 times, most recently from 4cbd15f to 2ac631c 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
@nan-yu
nan-yu force-pushed the feat/url-security-tooling branch from 6e5f961 to b25529b Compare December 3, 2026 19:13
@nan-yu
nan-yu force-pushed the feat/url-security-web-core branch from 9ea092a to eb519a5 Compare December 3, 2026 19:29
nan-yu added 15 commits December 3, 2026 19:31
…ontext (#4045)

assemble_catalog.py and Catalog.fromJson warn when a component property whose
name looks like a URL has no x-a2ui-url-context mark, and a CI step fails for
the catalogs in this repository. The assembler writes the basic catalog's
built-in URL marks into assembled catalogs.
…nt SDK (#4045)

checkPayloadUrls checks a payload's URL properties against a URL security
policy before the agent sends it, and reports or strips blocked values.
…ma in the URL check (#4045)

Ignore an updateDataModel whose list index is above the renderer's
MAX_ARRAY_INDEX, as the renderer rejects it. When the surface's named
catalog isn't among the agent's catalogs, check only the built-in list and
the policy's urlProperties for it instead of another catalog's schema.
…n catalog in the URL check (#4045)

The URL check replayed updateDataModel with its own pointer code, which
wrote through __proto__ onto Object.prototype and differed from the
renderer on empty segments, primitives and relative paths. It now
replays on web_core's DataModel and skips the updates the renderer
rejects. A v1.0 component that names its catalog in @CatalogId (or a
bare catalogId its schema doesn't declare) is checked against that
catalog, as the renderer resolves it.
The check now applies messages the way the renderer does: it skips a
createSurface for a live surface and messages after deleteSurface,
checks each component when it arrives and each bound URL again after
every data update that changes it, recognizes bindings by the
renderer's rule (version-specific key, extra keys allowed), resolves
top-level relative bindings against the root, and walks schema
catchalls. A blocked bound URL is reported and stripped in the message
that set the value, so the secret doesn't stay in the data.
…4045)

A non-string mark such as ["media"] crashed the Python check, a null
mark read as missing, and a name ending in a newline counted as a URL
name. Both checks now report the same problems.
…RL check (#4045)

Any componentId in a component's props, such as one in an action
context, marked a component as a template child and left its relative
bindings unchecked. The check now reads templates only where the
component's schema declares a child list, as the renderer does.
…checks (#4045)

Catalog loaders now reject x-a2ui-url-context under
additionalProperties, patternProperties, and unevaluatedProperties, so
the Python and TypeScript checks report such marks too, in components
and in shared definitions.
…and map-keyword parity (#4045)

1. checkPayloadUrls now follows web_core 6c95201 on ARRAY urlContext,
   array values (literal and data-bound), and host overrides on array
   or catchall properties, re-checking when a child write updates a
   bound array.
2. collectTemplateChildren tracks deleted surfaces and surface
   lifetimes, so deleted components are skipped and template child IDs
   never leak across deleteSurface and recreate.
3. Both annotation checks skip data keywords (const, enum, default,
   examples), treat patternProperties as a pattern map, and allow
   x-a2ui-url-context: none under map keywords, matching schema_loader.
…n check (#4045)

A catalog whose definitions reference each other several times made the
check walk every path, taking time exponential in their depth (a 1 KB
document with 20 levels took 4 s in Catalog.fromJson). Each $ref is now
followed once per component, in both the TypeScript and Python checks.
…#4045)

An updateDataModel or updateComponents before a createSurface for the
same surface made the URL check treat the createSurface as a duplicate
and skip it. A renderer that gets the messages one at a time rejects the
updates to the unknown surface and applies the createSurface, so its
theme and component URLs went unchecked. Such a createSurface now starts
a new surface lifetime in both the check and the template scan.
…URL check (#4045)

- Check the literal URL of an openUrl call as navigation, with
  functionName 'openUrl' on the report, as the Python check does.
- Recheck only the bindings a data update can change, found through a
  path trie, instead of every binding on the surface (5k bound images
  with 5k updates: 1.9 s before, about 0.3 s now).
- Throw a TypeError for an unknown onBlocked value.
- Add tests for list items, repeated writes, replaced components, the
  basic-only theme check, and fix a test that a deleteSurface made vacuous.
- Drop the unused MAX_ARRAY_INDEX re-export.
… and pass openUrl's info as the renderer does (#4045)

- A createSurface after updates to its surface no longer drops the
  bindings of the components those updates set: if an earlier payload
  created the surface, the renderer rejects the createSurface and keeps
  them, so later writes recheck both readings.
- For a literal openUrl URL, the policy gets only surfaceId and
  functionName, as the renderer's openUrl passes; the report keeps the
  component fields.
- Add tests for v0.9 openUrl, recheck order, and template children of a
  surface created after updates.
…ndex writes by path (#4045)

- A createSurface after updates to its surface keeps the data those
  updates set, for the reading where an earlier payload created the
  surface and the renderer rejects the createSurface.
- A write to list items below a binding rechecks only those items, and
  the latest write to a path is found through a path trie, so per-item
  updates of a bound list no longer take cubic time.
@nan-yu
nan-yu force-pushed the feat/url-security-tooling branch from 2dead3f to f424d28 Compare December 3, 2026 19:31

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