Repository navigation
Conversation
There was a problem hiding this comment.
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.
| 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]; |
There was a problem hiding this comment.
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[];
}There was a problem hiding this comment.
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
| 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): |
There was a problem hiding this comment.
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.
| 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): |
423385e to
cde736f
Compare
3baf1e6 to
69cc45b
Compare
cde736f to
76b0957
Compare
4cbd15f to
2ac631c
Compare
b813633 to
e38ab5e
Compare
6e5f961 to
b25529b
Compare
9ea092a to
eb519a5
Compare
…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.
2dead3f to
f424d28
Compare
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:
x-a2ui-url-context, plus a CI check that fails for the catalogs in this repository.checkPayloadUrlsin@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
url,uri,href,src, or ending inUrl,URL,Uri,URI,_url,_uri) and the "may hold a string" rule, which skips properties typed only as object, array, number, boolean, or null.Catalog.fromJsonnow callsconsole.warnonce per catalog ID when it finds problems in a v0.9+ catalog. Is a console warning the right channel for the TS loader?checkPayloadUrlsstrips by replacing a blocked value with an empty string rather than deleting the property, so required URL props (such asImage.url) still validate and the renderer's baseline resolves them to unset.Changes
tools/build_catalog/url_annotations.py(new, standard library only):find_url_annotation_problems(catalog)walks component properties (local$refs,allOf/anyOf/oneOf, nestedproperties, arrayitems) and reports unmarked URL-like properties and unknown mark values. The basic catalogs'Image.url,Video.url,Video.posterUrl, andAudioPlayer.urlcount as marked through the same built-in list the SDKs use. Run as a script, it exits 1 on any problem.assemble_catalog.pylogs a warning per problem in the assembled catalog and writes the basic catalog's built-in marks into it..github/workflows/validate_specifications.ymlruns the check oncatalogs/. 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 underadditionalProperties,patternProperties, orunevaluatedProperties, which catalog loaders reject, and follows each shared$refonce per component, so deeply shared definitions can't make it slow.@a2ui/web_core:Catalog.fromJsonwarns throughconsole.warnwith the same rules (security/url_annotation_check.ts, package-internal).@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'surlPropertiesmap, and replays the messages in order on the renderer'sDataModel, 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 anopenUrlcall asnavigation(reported withfunctionName: 'openUrl'). Each v1.0 component is read with the catalog it names. AcreateSurfacethat follows updates to its surface is checked too, since the renderer applies it when the surface is new. An unknownonBlockedthrows aTypeError. Reports carry onlyredactUrloutput. The SDK re-exportsAllowlistUrlSecurityPolicy,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.tools/build_catalogand@a2ui/agent; CHANGELOG entries for@a2ui/web_coreand@a2ui/agent.Impact & risks
checkPayloadUrlsbehave as before.Catalog.fromJsonsee one console warning per catalog.formatString, relative bindings inside list templates, or data set by earlier payloads. The renderer still checks those, and the README says so.Testing
tools/build_catalog:pytest tools/build_catalog/tests(newtest_url_annotations.py, assembler warning and basic-mark tests);pyink --check.@a2ui/web_core: newurl_annotation_check.test.ts(heuristic, nesting, recursion, built-in list, published basic catalogs,fromJsonwarning once per ID); everydist/**/*.test.jspasses.@a2ui/agent: newtests/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.9theme.iconUrl, hosturlPropertiesoverride, list templates, surface lifetimes,openUrlliterals, recheck order, throwing policy); fullvitest runpasses.python3 tools/build_catalog/url_annotations.py catalogsexits 0.test_assemble_catalog.py::test_circular_dependencyfails locally when the repository sits fewer than four directories below/, on the base branch too; it is unrelated to this PR.🤖 Agent-generated