fix(tools): reject out-of-scope containerTag in documentDelete - #1758
Open
Atharvsinh-codez wants to merge 1 commit into
Open
Atharvsinh-codez wants to merge 1 commit into
Atharvsinh-codez wants to merge 1 commit into
Conversation
documentDelete takes an optional containerTag from the model and uses it as the scope for the delete. getProfile, documentList and memoryForget only accept tags the developer configured, but documentDelete never checked, so the model could name any tag and delete documents in it. This is the same gap in both tool surfaces (ai-sdk documentDeleteTool and the OpenAI createDocumentDeleteFunction). Both now reject a tag that is not in the configured container tags before making any request, with the same "outside the configured scope" error the other tools use. Added tests for both surfaces, the implicit projectId scope, selecting another configured tag, and the default no-tag path.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
documentDeleteaccepts an optionalcontainerTagfrom the model and uses it as the scope for the delete. The other tools that take acontainerTag(getProfile,documentList,memoryForget) only allow tags the developer configured.documentDeletenever checked, so a model (or a prompt-injected input) could pass any tag and delete documents scoped to it.deleteDocumentByIdentifierstill refuses documents whose tags fall outside the scope it is given. But the scope itself came straight from the model, so that check wasn't protecting anything.It happens in both tool surfaces:
documentDeleteToolinpackages/tools/src/ai-sdk.ts(also re-exported bypackages/ai-sdk)createDocumentDeleteFunctioninpackages/tools/src/openai/tools.tsRepro
With
containerTags: ["tenant-a"]configured and a document that only lives intenant-b:On
mainthis callsdocuments.deleteBulkand succeeds. With this change it returnssuccess: falsewithContainer tag "tenant-b" is outside the configured scope.and makes no SDK calls.The fix
Both tools now check the supplied tag against the configured container tags before doing anything else, and return the same "outside the configured scope" error the other tools use. If no tag is passed, behavior is unchanged (the configured union is used). Passing another tag that is configured still works.
Relation to #1504 / #1755
This is the same class of bug as #1504, which #1755 bundles. As far as I can tell, that work covers
getProfile,documentListandmemoryForgetbut notdocumentDelete, and its scope test doesn't include it either. I used a small inline check so this applies cleanly onmainwithout depending on #1755. Once #1755 lands, it can be switched toresolveConfiguredContainerTagin a one-line change. Happy to rebase if you'd rather have it that way.Tests
New file
packages/tools/src/document-delete-scope.test.ts(mocked SDK, no network):get/list/deleteBulkcallsprojectIdconfig rejects an outside tagbiome checkis clean on the changed files.tsc --noEmitreports the same errors asmain(none new).src/tools.test.tsneeds a realSUPERMEMORY_API_KEY, so I didn't run it.