mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-10-10 03:28:14 +00:00
fix(tools): reject parent-directory segments in Claude memory paths
This commit is contained in:
parent
76470610ff
commit
b8b95112af
2 changed files with 35 additions and 5 deletions
|
|
@ -284,3 +284,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()
|
||||
},
|
||||
)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -807,11 +807,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