Skip to content

Validate exposedTo before registering AbortSignal algorithm - #240

Merged
domfarolino merged 2 commits into
webmachinelearning:mainfrom
beaufortfrancois:move-abort-signal
Aug 14, 2026
Merged

Validate exposedTo before registering AbortSignal algorithm#240
domfarolino merged 2 commits into
webmachinelearning:mainfrom
beaufortfrancois:move-abort-signal

Conversation

@beaufortfrancois

@beaufortfrancois beaufortfrancois commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Move the validation of options.exposedTo origins before attaching the unregister algorithm to options.signal in registerTool().

Previously, the abort algorithm was attached to the signal before origin validation. If exposedTo contained an invalid or untrustworthy origin, the promise was rejected with a SecurityError, but the abort algorithm remained attached to the signal and could inadvertently unregister a subsequently registered tool of the same name upon aborting.

Also reorder ModelContextRegisterToolOptions dictionary members and domintro definitions to match the processing order of options.

Fixed in Chromium: https://chromium-review.googlesource.com/c/chromium/src/+/8236351


Preview | Diff

Move the validation of `options.exposedTo` origins before attaching the
unregister algorithm to `options.signal` in `registerTool()`.

Previously, the abort algorithm was attached to the signal before origin
validation. If `exposedTo` contained an invalid or untrustworthy origin,
the promise was rejected with a `SecurityError`, but the abort algorithm
remained attached to the signal and could inadvertently unregister a
subsequently registered tool of the same name upon aborting.

Also reorder `ModelContextRegisterToolOptions` dictionary members and
domintro definitions to match the processing order of options.
@domfarolino

Copy link
Copy Markdown
Collaborator

So the only observable with this change is the buggy ability to unregister a later-registered, valid tool by the abort algorithm hanging around, right?

(I think this will be fixed regardless, once we end up with a UUID-keyed tool registry and Tool interface, but this is probably fine in the meantime).

@beaufortfrancois

Copy link
Copy Markdown
Collaborator Author

So the only observable with this change is the buggy ability to unregister a later-registered, valid tool by the abort algorithm hanging around, right?

Yes.

Comment thread index.bs
@domfarolino
domfarolino merged commit 7aa8235 into webmachinelearning:main Aug 14, 2026
2 checks passed
github-actions Bot added a commit that referenced this pull request Aug 14, 2026
SHA: 7aa8235
Reason: push, by domfarolino

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Comment thread index.bs
1. [=model context/Unregister a tool=] given [=this=] and |tool name|.

1. [=Reject=] |promise| with |signal|'s [=AbortSignal/abort reason=].
1. If |options|'s {{ModelContextRegisterToolOptions/signal}} [=map/exists=] and is

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.

I'd argue we could make it nicer by moving this below the exposed origins check so that we check first all things related to exposed origins, then and only then signal aborted + registering algo. Here, we're mixing both.
I'm happy to send a spec PR and Chromium CL if accepted.

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.

I think while this is a little strange, we should avoid doing as much work as possible (aside from environment checks like at the very beginning of this method) if the developer passes in an aborted signal. IMO if the signal is already aborted, the Promise shouldn't abort due to any other invalid input (that WebIDL doesn't already catch), since we shouldn't even process them. If you can think of a way to preserve that invariant while rearranging this, I'm all ears. Otherwise, I think the semantics here are at least worth preserving.

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.

3 participants