Repository navigation
Conversation
| The [=origin wildcard=] opts into all [$is origin potentially trustworthy?|potentially trustworthy$] | ||
| origins in the document's tree, not only origins trusted by the author. Authors should prefer | ||
| explicit origin lists when possible. In particular, a consumer using the [=origin wildcard=] | ||
| accepts tools exposed to it by any eligible document in that tree, including tools with untrusted |
There was a problem hiding this comment.
*which may include
|
See this is why I would have preferred for the resolution to be "explore support". There was no consensus on this, and I would like to see concrete use cases and how we would mitigate any security risks before we can consider this. Additionally, note that exposedTo and fromOrigins have very different security considerations, so it would be unwise to bundle them into a single PR. |
|
@johannhof Just to clarify, is wildcard fromOrigins the one of lesser concern for you? For fromOrigins, is the main concern that the caller might accept tools from origins it hasn’t properly vetted? Or are there other risks you have in mind? The use case I can see more clearly is for exposedTo: an application deliberately allowing anybody embedding it to operate it without having to enumerate every possible host origin. For example, a chat app could embed a cooperating web app in an iframe and interact with its exposed tools. That seems useful for the composable web. which seems to be similar to the point brought up here: #188 (comment) I do agree there’s real risk here, since exposedTo: ["*"] would allow more than just the parent, so the scope is broader than the particular use case I mentioned above. |
Thanks for chiming in, Johann. I updated the PR to only include the wildcard for fromOrigins. |
Having thought about this and discussed with others more, I believe that the security concerns of fromOrigins are probably manageable, with one caveat: There are three possible attack targets here - deterministic scripts on a webpage, AI agents on a webpage, and "native" AI agents, say, in the browser. For deterministic scripts, having a wildcard value seems relatively low risk, unless the script performs risky operations such as iterating over all returned tools and calling them without trying to identify them. Native AI agents and web based agents, however, will usually be exposed to the entire list of tools and must choose the right tool to use via inference. If all subframes on the page were allowed to provide tools in such a scenario, malicious third parties could register tools like This should be prevented by the permissions policy. As such, we need to make sure that the permissions policy applies to exposure for any AI agent, including in-page ones. @domfarolino
Yeah exposedTo wildcard seems hard to get right - I understand the desire to expose tools to all embedders, but OTOH it seems like we'd be repeating a cardinal sin of postMessage here. 🤷 |
I saw wildcard Also, since |
Allow the special "*" string in exposedTo and fromOrigins while preserving explicit origin validation and existing policy checks. Update specification examples and related documentation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restrict origin wildcards to potentially trustworthy origins and share allowlist matching across discovery and exposure checks. Clarify discovery opt-in, notification timing, and wildcard risks; align documentation and track selective pattern matching. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restore explicit-origin-only exposedTo, simplify wildcard matching, and align examples and security documentation with the narrower scope. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restore contains prose in getTools and align wildcard documentation with secure-context eligibility while preserving provider exposure checks. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
72efc91 to
9963cba
Compare
| An <dfn>origin wildcard</dfn> is the [=string=] "`*`", used in | ||
| {{ModelContextGetToolOptions/fromOrigins}} to request discovery from all origins. | ||
|
|
||
| In {{ModelContextGetToolOptions/fromOrigins}}, | ||
| only the exact string "`*`" is an [=origin wildcard=]. All other entries are parsed and validated | ||
| as origins, even when the array also contains an [=origin wildcard=]. |
There was a problem hiding this comment.
These two paragraphs say the same thing twice. With the sole-entry rule (see below), I'd merge them into one:
| An <dfn>origin wildcard</dfn> is the [=string=] "`*`", used in | |
| {{ModelContextGetToolOptions/fromOrigins}} to request discovery from all origins. | |
| In {{ModelContextGetToolOptions/fromOrigins}}, | |
| only the exact string "`*`" is an [=origin wildcard=]. All other entries are parsed and validated | |
| as origins, even when the array also contains an [=origin wildcard=]. | |
| An <dfn>origin wildcard</dfn> is the [=string=] "`*`". When it is the only entry of | |
| {{ModelContextGetToolOptions/fromOrigins}}, it requests discovery from documents of any origin. | |
| Only the exact string "`*`" is an [=origin wildcard=]. |
| 1. Let |includeAllOrigins| be false. | ||
|
|
||
| 1. If |options|'s {{ModelContextGetToolOptions/fromOrigins}} [=map/exists=], then: | ||
|
|
||
| 1. [=list/For each=] |origin| of |options|'s {{ModelContextGetToolOptions/fromOrigins}}: | ||
|
|
||
| 1. If |origin| is the [=origin wildcard=], then: | ||
|
|
||
| 1. Set |includeAllOrigins| to true. | ||
|
|
||
| 1. [=iteration/continue=]. |
There was a problem hiding this comment.
Here's a suggested change that requires the wildcard to be the only entry. I used SecurityError to match the other invalid-entry failures in this step. TypeError would also be defensible.
1. Let |includeAllOrigins| be false.
1. If |options|'s {{ModelContextGetToolOptions/fromOrigins}} [=map/exists=], then:
+ 1. If |options|'s {{ModelContextGetToolOptions/fromOrigins}} [=list/contains=] the [=origin
+ wildcard=], then:
+
+ 1. If |options|'s {{ModelContextGetToolOptions/fromOrigins}}'s [=list/size=] is not 1, then
+ return [=a promise rejected with=] a "{{SecurityError}}" {{DOMException}}.
+
+ 1. Set |includeAllOrigins| to true.
+
+ 1. Otherwise, [=list/for each=] |origin| of |options|'s
+ {{ModelContextGetToolOptions/fromOrigins}}:
- 1. [=list/For each=] |origin| of |options|'s {{ModelContextGetToolOptions/fromOrigins}}:
-
- 1. If |origin| is the [=origin wildcard=], then:
-
- 1. Set |includeAllOrigins| to true.
-
- 1. [=iteration/continue=].
1. Let |parsedURL| be the result of running the [=URL parser=] on |origin|.
...| : <code><var ignore>options</var>["{{ModelContextGetToolOptions/fromOrigins}}"]</code> | ||
| :: An array of origins from which to query tools. Documents whose origin appears in this list, or | ||
| are same-origin with the caller, have their tools queried. An empty list only includes | ||
| same-origin documents. | ||
| same-origin documents. The [=origin wildcard=] queries documents regardless of their origin, | ||
| including [=opaque origins=], in the current document's tree. | ||
| Tools must still be exposed to the caller, and documents must be [=allowed to use=] the | ||
| "{{tools}}" feature. |
There was a problem hiding this comment.
Two things:
- Please mention the sole-entry requirement, e.g. "The [=origin wildcard=], which must be the only entry, queries documents…".
- Unless Allow
executeTool()to execute tools registered by opaque-origin documents #349 lands first, please add a note that opaque-origin tools found this way can't be executed yet:
Issue(#349): Tools discovered from documents with an [=opaque origin=] cannot currently be
executed with {{ModelContext/executeTool()}}.
| Once tools are registered, in-page agents can discover and invoke them using `getTools()` and `executeTool()`. | ||
|
|
||
| Calling `document.modelContext.getTools()` returns a promise that resolves with an array of [`Tool`](https://webmachinelearning.github.io/webmcp/#tool) objects. Each `Tool` exposes the tool's `name`, `title`, `description`, `inputSchema`, `outputSchema`, `annotations`, `origin`, and `source` (the owner window). By default, `getTools()` only returns tools registered by documents same-origin with the caller in the frame tree. To retrieve cross-origin tools, you must explicitly list their origins in the `fromOrigins` option. This array only supports secure origins. | ||
| Calling `document.modelContext.getTools()` returns a promise that resolves with an array of [`Tool`](https://webmachinelearning.github.io/webmcp/#tool) objects. Each `Tool` exposes the tool's `name`, `title`, `description`, `inputSchema`, `outputSchema`, `annotations`, `origin`, and `source` (the owner window). By default, `getTools()` only returns tools registered by documents same-origin with the caller in the frame tree. To retrieve cross-origin tools, you must explicitly list their origins in the `fromOrigins` option, or use `{ fromOrigins: ["*"] }` to query all origins in that tree, including opaque origins. The API's secure-context restriction still applies. |
There was a problem hiding this comment.
"The API's secure-context restriction still applies." reads oddly right after "including opaque origins". Either explain the connection (secure contexts can still have opaque origins) or drop the sentence. Also, please mention that "*" must be the only entry.
| Calling `document.modelContext.getTools()` returns a promise that resolves with an array of [`Tool`](https://webmachinelearning.github.io/webmcp/#tool) objects. Each `Tool` exposes the tool's `name`, `title`, `description`, `inputSchema`, `outputSchema`, `annotations`, `origin`, and `source` (the owner window). By default, `getTools()` only returns tools registered by documents same-origin with the caller in the frame tree. To retrieve cross-origin tools, you must explicitly list their origins in the `fromOrigins` option. This array only supports secure origins. | ||
| Calling `document.modelContext.getTools()` returns a promise that resolves with an array of [`Tool`](https://webmachinelearning.github.io/webmcp/#tool) objects. Each `Tool` exposes the tool's `name`, `title`, `description`, `inputSchema`, `outputSchema`, `annotations`, `origin`, and `source` (the owner window). By default, `getTools()` only returns tools registered by documents same-origin with the caller in the frame tree. To retrieve cross-origin tools, you must explicitly list their origins in the `fromOrigins` option, or use `{ fromOrigins: ["*"] }` to query all origins in that tree, including opaque origins. The API's secure-context restriction still applies. | ||
|
|
||
| In `fromOrigins`, only the exact `"*"` string is special. It does not bypass Permissions Policy or execution checks. Discovery still requires the provider's explicit `exposedTo` origin list to allow the caller. A wildcard opts into any eligible origin, not just origins trusted by the author; wildcard consumers may discover tools with untrusted descriptions. Prefer explicit origin lists when possible. Other entries are still validated even when `"*"` is present. |
There was a problem hiding this comment.
With the sole-entry rule, "Other entries are still validated even when "*" is present." becomes something like ""*" must be the only entry; combining it with origins rejects with SecurityError."
Also, "Discovery still requires the provider's explicit exposedTo origin list to allow the caller" is only true across origins. Suggest "Cross-origin discovery still requires…".
| > 20. Does your spec define when and how new kinds of errors should be raised? | ||
|
|
||
| Yes. `registerTool()` throws `InvalidStateError` for inactive documents, duplicate names, or invalid name/description; `NotAllowedError` when the `"tools"` Permissions Policy is disallowed; `SecurityError` for non-trustworthy [`exposedTo`](https://webmachinelearning.github.io/webmcp/#dom-modelcontextregistertooloptions-exposedto) origins; and `TypeError` when `inputSchema` or `outputSchema` serialization fails. These errors only reflect the page's own state and inputs, so they do not leak new information. | ||
| Yes. `registerTool()` throws `InvalidStateError` for inactive documents, duplicate names, or invalid name/description; `NotAllowedError` when the `"tools"` Permissions Policy is disallowed; `SecurityError` for invalid or non-trustworthy [`exposedTo`](https://webmachinelearning.github.io/webmcp/#dom-modelcontextregistertooloptions-exposedto) entries; and `TypeError` when `inputSchema` or `outputSchema` serialization fails. `getTools()` likewise rejects with `SecurityError` for invalid or non-trustworthy `fromOrigins` entries other than `"*"`. All non-wildcard `fromOrigins` entries are validated even when `"*"` is present. These errors only reflect the page's own state and inputs, so they do not leak new information. |
There was a problem hiding this comment.
Needs the same update for the sole-entry rule: replace "All non-wildcard fromOrigins entries are validated even when "*" is present." with ""*" must be the only entry; mixing it with origins rejects with SecurityError."
Summary
Adds the explicit
"*"origin wildcard togetTools()'sfromOriginsoption, implementing the discovery portion of the resolution in #317.fromOrigins: ["*"]to discover tools from potentially trustworthy origins in the current document's tree.Toolinterface #348 lands, the wildcard language should be updated to match its new guidance for opaque origins."*"is present.Scope
exposedToremains an explicit-origin string list, without wildcard support. Broader provider exposure requires separate consideration of its security implications.This change does not add URLPattern or subdomain-pattern support.
Related to #317.
Tests: web-platform-tests/wpt#64960.
Preview | Diff