Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/core/protect/RooProtectedController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ export class RooProtectedController {
const absolutePath = path.resolve(this.cwd, filePath)
const relativePath = path.relative(this.cwd, absolutePath).toPosix()

// Check if the path goes outside the cwd (starts with ..)
if (relativePath.startsWith("..")) {
// Paths outside the cwd are not protected
return false
}

// Use ignore library to check if file matches any protected pattern
return this.ignoreInstance.ignores(relativePath)
} catch (error) {
Expand Down
13 changes: 13 additions & 0 deletions src/core/protect/__tests__/RooProtectedController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ describe("RooProtectedController", () => {
expect(controller.isWriteProtected(".roo\\config.json")).toBe(true)
expect(controller.isWriteProtected(".roo/config.json")).toBe(true)
})

it("should handle paths outside the cwd gracefully", () => {
// Paths that go outside the cwd should not be protected
expect(controller.isWriteProtected("../../.roo/rules")).toBe(false)
expect(controller.isWriteProtected("../../../.rooignore")).toBe(false)
expect(controller.isWriteProtected("../.roo/config.json")).toBe(false)
})

it("should not throw error for paths outside cwd", () => {
// This should not throw an error
expect(() => controller.isWriteProtected("../../.roo/rules")).not.toThrow()
expect(() => controller.isWriteProtected("../outside/path/.rooignore")).not.toThrow()
})
})

describe("getProtectedFiles", () => {
Expand Down
Loading