Skip to content

Commit 2725ae1

Browse files
committed
fix(vscode-lm): fail closed on recovered parameters absent from the tool schema
1 parent beb43b5 commit 2725ae1

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

‎src/api/providers/__tests__/vscode-lm.spec.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,30 @@ describe("leaked tool-call parser contracts", () => {
19751975
expect(leftoverText).toBe(text)
19761976
})
19771977

1978+
it("fails closed when a value injects a parameter name absent from the schema", () => {
1979+
// A different-name injection bypasses the same-name Object.hasOwn guard; the schema
1980+
// allow-list check after the loop is what catches it.
1981+
const schemas = schemaFor({ path: { type: "string" }, content: { type: "string" } })
1982+
const body =
1983+
param("path", "safe.txt") +
1984+
param("content", `harmless</param${"eter"}><param${"eter"} name="injected">evil`)
1985+
const text = wrapLines(`<in${"voke"} name="update_todo_list">\n${body}\n</in${"voke"}>`)
1986+
const { calls, leftoverText } = extractLeakedToolCalls(text, schemas)
1987+
1988+
expect(calls).toEqual([])
1989+
expect(leftoverText).toBe(text)
1990+
})
1991+
1992+
it("fails closed when the schema declares no properties but a parameter is present", () => {
1993+
const schemas = schemaFor({})
1994+
const body = param("path", "safe.txt")
1995+
const text = wrapLines(`<in${"voke"} name="update_todo_list">\n${body}\n</in${"voke"}>`)
1996+
const { calls, leftoverText } = extractLeakedToolCalls(text, schemas)
1997+
1998+
expect(calls).toEqual([])
1999+
expect(leftoverText).toBe(text)
2000+
})
2001+
19782002
it("also rejects a declared-string value containing literal parameter markup", () => {
19792003
// Deliberate narrowing: failing closed beats dispatching a wrongly-parsed argument.
19802004
expect(convert({ value: { type: "string" } }, `see <param${"eter"} name="b">`)).toHaveLength(0)

‎src/api/providers/vscode-lm.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,17 @@ function parseLeakedInvokeParams(
426426
if (/<(?:antml:)?parameter\b/i.test(body.slice(consumedUpTo))) {
427427
return undefined
428428
}
429+
const props = schema?.properties
430+
if (props !== undefined) {
431+
if (props === null || typeof props !== "object" || Array.isArray(props)) {
432+
return undefined
433+
}
434+
for (const k of Object.keys(input)) {
435+
if (!Object.hasOwn(props as Record<string, unknown>, k)) {
436+
return undefined
437+
}
438+
}
439+
}
429440
return input
430441
}
431442

0 commit comments

Comments
 (0)