Skip to content

Support "*" in getTools fromOrigins - #378

Draft
sjdallst2 wants to merge 5 commits into
webmachinelearning:mainfrom
sjdallst2:add-origin-wildcard
Draft

sjdallst2 wants to merge 5 commits into
webmachinelearning:mainfrom
sjdallst2:add-origin-wildcard

Conversation

@sjdallst2

@sjdallst2 sjdallst2 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds the explicit "*" origin wildcard to getTools()'s fromOrigins option, implementing the discovery portion of the resolution in #317.

  • Allow fromOrigins: ["*"] to discover tools from potentially trustworthy origins in the current document's tree.
  • Exclude opaque origins from wildcard matching. Once Introduce the Tool interface #348 lands, the wildcard language should be updated to match its new guidance for opaque origins.
  • Preserve existing origin-string inputs, same-origin defaults, provider exposure checks, and Permissions Policy checks.
  • Validate all other entries even when "*" is present.
  • Update examples and related documentation.

Scope

exposedTo remains 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

Comment thread index.bs Outdated
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

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.

*which may include

@johannhof

Copy link
Copy Markdown
Contributor

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.

@victorhuangwq

Copy link
Copy Markdown
Contributor

@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.

@sjdallst2 sjdallst2 changed the title Support "*" in exposedTo and fromOrigins Support "*" in getTools fromOrigins Nov 10, 2026
@sjdallst2

Copy link
Copy Markdown
Collaborator Author

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.

Thanks for chiming in, Johann. I updated the PR to only include the wildcard for fromOrigins.

Comment thread index.bs Resolved
Comment thread index.bs Resolved
@johannhof

Copy link
Copy Markdown
Contributor

@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?

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 new_send_email_use_this_instead to convince the model to choose their tool.

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

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.

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. 🤷

@victorhuangwq

Copy link
Copy Markdown
Contributor

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 new_send_email_use_this_instead to convince the model to choose their tool.

I saw wildcard fromOrigins as lower risk mainly because I'd expect agents to already be managing tool trust per origin, rather than treating every returned tool as equal. Though, I could see how origin will just be aa soft signal once a model is already allowed access to tools from that origin.

Also, since fromOrigins only applies to getTools(), native agents already effectively see tools from every frame that's been delegated allow="tools" (via the observation path). So, isn't fromOrigins: ["*"] just bringing in-page agents to parity with that, perhaps under the same Permissions Policy gate?

Sam Dallstream and others added 5 commits November 24, 2026 09:21
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>
Comment thread index.bs
Comment on lines +178 to +183
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=].

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These two paragraphs say the same thing twice. With the sole-entry rule (see below), I'd merge them into one:

Suggested change
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=].

Comment thread index.bs
Comment on lines +1078 to +1088
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=].

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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|.
       ...

Comment thread index.bs
Comment on lines 1513 to +1519
: <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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Two things:

Issue(#349): Tools discovered from documents with an [=opaque origin=] cannot currently be
executed with {{ModelContext/executeTool()}}.

Comment thread README.md
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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

"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.

Comment thread README.md
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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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."

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.

5 participants