mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-09-30 01:51:28 +00:00
fix(tools): reject parent-directory segments in Claude memory paths
This commit is contained in:
parent
5258cb74c8
commit
6b7ba4af40
2 changed files with 35 additions and 5 deletions
|
|
@ -210,3 +210,29 @@ describe("ClaudeMemoryTool str_replace replacement literalness", () => {
|
|||
expect(stored).toContain(`price is ${dollarSequence} today`)
|
||||
})
|
||||
})
|
||||
|
||||
describe("ClaudeMemoryTool path traversal", () => {
|
||||
let tool: ClaudeMemoryTool
|
||||
|
||||
beforeEach(() => {
|
||||
documentsListMock.mockReset()
|
||||
documentsGetMock.mockReset()
|
||||
addMock.mockReset()
|
||||
mockDocument(FILE_CONTENT)
|
||||
tool = new ClaudeMemoryTool("test-api-key")
|
||||
})
|
||||
|
||||
it.each(["/memories/..", "/memories/foo/..", "/memories/../secrets.txt"])(
|
||||
"rejects parent-directory path %s",
|
||||
async (path) => {
|
||||
const result = await tool.handleCommand({
|
||||
command: "view",
|
||||
path,
|
||||
})
|
||||
|
||||
expect(result.success).toBe(false)
|
||||
expect(result.error).toContain("Invalid path")
|
||||
expect(documentsListMock).not.toHaveBeenCalled()
|
||||
},
|
||||
)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -805,11 +805,15 @@ export class ClaudeMemoryTool {
|
|||
* Validate that path starts with /memories for security
|
||||
*/
|
||||
private isValidPath(path: string): boolean {
|
||||
return (
|
||||
(path.startsWith("/memories/") || path === "/memories") &&
|
||||
!path.includes("../") &&
|
||||
!path.includes("..\\")
|
||||
)
|
||||
if (!(path.startsWith("/memories/") || path === "/memories")) {
|
||||
return false
|
||||
}
|
||||
if (path.includes("..\\")) {
|
||||
return false
|
||||
}
|
||||
// Reject any parent-directory segment, including trailing "/.." which
|
||||
// the previous "../" substring check missed (e.g. "/memories/..").
|
||||
return !path.split("/").some((segment) => segment === "..")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue