Repository navigation
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
/gemini review 🤖 Agent-generated |
There was a problem hiding this comment.
Code Review
This pull request introduces a new URL security checking utility, check_payload_urls, in a2ui.utils to validate payload URLs against a security policy before sending. It includes updates to the changelog, documentation, and a comprehensive suite of unit tests. The review identified two important security improvements: first, in _set_child, calling container.extend with an arbitrary index from untrusted payloads can cause memory exhaustion, so a limit on the list index should be enforced; second, in _find_catalog, the fallback behavior when a specified catalog_id is not found could lead to a security bypass, and the function should instead return None immediately.
| def _set_child(container: Any, segment: str, value: Any) -> None: | ||
| if isinstance(container, list): | ||
| index = int(segment) | ||
| container.extend([None] * (index + 1 - len(container))) | ||
| container[index] = value | ||
| else: | ||
| container[segment] = value |
There was a problem hiding this comment.
Calling container.extend with an arbitrary index parsed from an untrusted payload can lead to memory exhaustion and Denial of Service (DoS). If a payload contains a very large list index (e.g., /items/999999999/url), this will attempt to allocate a massive list, causing a MemoryError and crashing the agent. We should enforce a reasonable upper bound on the list index before extending the container.
| def _set_child(container: Any, segment: str, value: Any) -> None: | |
| if isinstance(container, list): | |
| index = int(segment) | |
| container.extend([None] * (index + 1 - len(container))) | |
| container[index] = value | |
| else: | |
| container[segment] = value | |
| def _set_child(container: Any, segment: str, value: Any) -> None: | |
| if isinstance(container, list): | |
| index = int(segment) | |
| if index > 10000: | |
| return | |
| container.extend([None] * (index + 1 - len(container))) | |
| container[index] = value | |
| else: | |
| container[segment] = value |
There was a problem hiding this comment.
Fixed in 00cdfe1. The renderer's data model (Python and TS) rejects any list index above MAX_ARRAY_INDEX (10,000), so such an update never reaches the surface. The mirror now ignores an updateDataModel with any index segment above that bound, which caps list growth and keeps bindings resolving as the renderer would (a binding to the rejected path reads nothing in both). Same fix in the TS port in #4116 (3baf1e6), with tests in both for index 10000 (applied), 1000000000 on an existing list, and on a newly created one (ignored).
🤖 Agent-generated
| def _find_catalog( | ||
| catalogs: Sequence[CatalogApi], catalog_id: str | None, component_type: str | ||
| ) -> CatalogApi | None: | ||
| if catalog_id is not None: | ||
| for catalog in catalogs: | ||
| if catalog.id == catalog_id: | ||
| return catalog if catalog.get_component(component_type) else None | ||
| for catalog in catalogs: | ||
| if catalog.get_component(component_type) is not None: | ||
| return catalog | ||
| return None |
There was a problem hiding this comment.
If catalog_id is specified but not found in catalogs, the function currently falls back to searching all catalogs for the first one that defines the component type. This fallback can lead to checking the component against the wrong catalog schema, potentially bypassing URL security checks if the fallback catalog does not mark the property as a URL. We should return None immediately if the specified catalog_id is not found.
| def _find_catalog( | |
| catalogs: Sequence[CatalogApi], catalog_id: str | None, component_type: str | |
| ) -> CatalogApi | None: | |
| if catalog_id is not None: | |
| for catalog in catalogs: | |
| if catalog.id == catalog_id: | |
| return catalog if catalog.get_component(component_type) else None | |
| for catalog in catalogs: | |
| if catalog.get_component(component_type) is not None: | |
| return catalog | |
| return None | |
| def _find_catalog( | |
| catalogs: Sequence[CatalogApi], catalog_id: str | None, component_type: str | |
| ) -> CatalogApi | None: | |
| if catalog_id is not None: | |
| for catalog in catalogs: | |
| if catalog.id == catalog_id: | |
| return catalog if catalog.get_component(component_type) else None | |
| return None | |
| for catalog in catalogs: | |
| if catalog.get_component(component_type) is not None: | |
| return catalog | |
| return None |
There was a problem hiding this comment.
Fixed in 00cdfe1. When createSurface names a catalog that the agent's catalogs don't include, the check no longer falls back to another catalog that defines the same type. It checks only the top-level properties that the built-in list (for a basic catalog ID) or the policy's url_properties name for that catalog ID, without a schema; anything else is left to the renderer. A surface the payload only updates (no catalog ID known) still uses the first catalog with the type, as documented. Same behavior in the TS checkPayloadUrls in #4116 (3baf1e6), with tests in both.
🤖 Agent-generated
775d639 to
00cdfe1
Compare
013e65a to
8c9862a
Compare
00cdfe1 to
d21e261
Compare
be5a99b to
b987053
Compare
d21e261 to
0dcdc11
Compare
14f301b to
0f6cc36
Compare
0dcdc11 to
4572caa
Compare
4572caa to
1c072c6
Compare
4adc937 to
37ba2f7
Compare
1828474 to
abb593e
Compare
d71aac4 to
68dce69
Compare
abb593e to
7e43cc3
Compare
68dce69 to
99ea6eb
Compare
…SDK (#4045) check_payload_urls checks a payload's URL properties against a URL security policy before the agent sends it, and reports or strips blocked values, matching checkPayloadUrls in the TypeScript agent SDK.
…ema 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 url_properties for it instead of another catalog's schema.
… at the first rejected key in the URL check (#4045)
…ed basic components and array overrides, and respect allOf properties in the URL check (#4045)
…dates to its surface, and literal openUrl URLs, and cache catalog schemas in the URL check (#4045)
… data update re-check (#4045)
…and pass openUrl's policy only the renderer's info in the URL check (#4045)
… written items of a bound list in the URL check (#4045)
7e43cc3 to
aa66240
Compare
Summary
Part of #4045 (plan Wave 4). Stacked on #4119 (
feat/url-security-python-core).Adds
check_payload_urlsto the Python agent SDK (a2ui.utils), the same opt-in pre-send check ascheckPayloadUrlsin the TypeScript agent SDK (#4116). An agent can check a payload's URLs against a URL security policy before sending it, and report or strip blocked values. The renderer still enforces its own policy; this is an earlier, optional line.Reviewer focus
url_check.py: replayscreateSurface,updateComponents,updateDataModel, anddeleteSurfaceusinga2ui.core.DataModel, skips a secondcreateSurfaceon a surface the payload created and messages afterdeleteSurfaceuntil recreated, checks acreateSurfacethat follows updates to its surface as a new surface while keeping the data and components those updates sent (both renderer readings), checks components against their v1.0@catalogId(or surface catalog), and re-checks live bound properties whenever anupdateDataModelwrites at, above, or below their resolved path. Bindings and data writes are indexed by path, so a re-check costs the depth of the path, and a write under a bound list checks only the written items.(surface_id, epoch)lifetime and collectscomponentIdvalues only at child-list schema positions (ChildList,ComponentId,Child,TemplateChildList, or{componentId, path|dataBinding}/explicitList/template), so decoycomponentIdkeys elsewhere cannot silence top-level relative bindings.x-a2ui-url-contextthrough$defsrefs,allOf/anyOf/oneOf, nestedproperties, arrayitems, list-level marks, and code-definedadditionalProperties(skipping envelope keys and siblingallOfproperties), applies the strictest mark on conflict, keeps built-in basic marks on derived basic catalogs, and applies hosturl_propertiesoverrides (including arrays). Strip mode replaces blocked values with""at their source (createSurface.dataModel,updateDataModel.value, or the component property).Changes
a2ui.utils.check_payload_urls(catalogs, payload, *, policy=None, on_blocked="report")returns aPayloadUrlCheckResult(messages,blocked). EachBlockedPayloadUrlcarries the message index (of the component or the data write), surface, catalog, component, property path (items[].imageUrl,theme.iconUrl), context,redact_urloutput, the bound data path, if any, andfunction_name("openUrl") for anopenUrlURL.openUrlURLs in actions (asnavigation, with the same policyinfothe renderer passes), bindings (@pathin v1.0,pathin v0.9) to values the same payload sets (bound lists item by item, including root relative paths on non-template children), components inlined increateSurface, and the basic catalogs'theme.iconUrl. Each value goes throughapply_url_security_policyfroma2ui.core.Impact & risks
formatString), relative bindings inside list templates, and data from earlier payloads aren't resolved here; the renderer checks those. The README says so.Testing
python/a2ui_agent/tests/utils/test_url_check.py(53 tests): baseline default, allowlist, redaction, custom marks, nested props,none, policyinfo, data bindings and update order,DataModelparity (forbidden keys, empty segments, out-of-range indexes), strip at component/data sources (caller's payload unchanged), v1.0 inline components and@catalogId, v0.9theme.iconUrl, surface lifecycle (deleteSurface, recreated surfaces, template-child position and lifetime isolation), derived basic components,allOf/ list marks / code-defined maps, hosturl_propertiesoverrides, unknown messages, throwing policy, bound lists and item writes,createSurfaceafter updates, literalopenUrlURLs (v0.9 and v1.0), re-check order, and a policy-call count for item writes.uv run --all-packages pytest(6652 passed, 412 skipped, 13 deselected, 3 xfailed, 33 subtests passed),mypy(0 issues),pyink --check(0 changes), isolateda2ui-agent-sdkimport check, and license check on all touched files.🤖 Agent-generated