From 8cf7731468f2afcfa03cbddefe90b57dff680d30 Mon Sep 17 00:00:00 2001 From: arturovt Date: Wed, 17 Jun 2026 18:53:02 +0300 Subject: [PATCH] fix(core): guard against DOM clobbering in declareExperimentalWebMcpTool Previously, the modelContext truthiness check could be bypassed via DOM clobbering (e.g. `
`), causing a truthy HTMLElement to pass the guard and then throw when `registerTool` was called on it. Replace the truthiness check with a duck-type check that asserts `registerTool` is a function, rejecting both absent and clobbered values. --- packages/core/src/webmcp/declare_tool.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/core/src/webmcp/declare_tool.ts b/packages/core/src/webmcp/declare_tool.ts index d5dc8f90cc1..a32d28f5d3b 100644 --- a/packages/core/src/webmcp/declare_tool.ts +++ b/packages/core/src/webmcp/declare_tool.ts @@ -41,8 +41,10 @@ export function declareExperimentalWebMcpTool), which would produce a truthy + // Element instead of a ModelContext object. + if (!modelContext || typeof modelContext.registerTool !== 'function') return; if (typeof ngDevMode !== 'undefined' && ngDevMode) { if (!injector) assertInInjectionContext(declareExperimentalWebMcpTool);