Skip to content

Commit 09df135

Browse files
committed
fix(core): validate policyDir is an absolute path in loadPolicyEngine
1 parent 64bf1e8 commit 09df135

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

packages/aurora/src/server/policyEngineLoader.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ vi.mock("fs", () => ({
99
existsSync: vi.fn(),
1010
}))
1111
vi.mock("path", () => ({
12-
default: { join: vi.fn() },
12+
default: { join: vi.fn(), isAbsolute: vi.fn() },
1313
join: vi.fn(),
14+
isAbsolute: vi.fn(),
1415
}))
1516
vi.mock("@cobaltcore-dev/policy-engine")
1617

@@ -24,6 +25,7 @@ describe("loadPolicyEngine", () => {
2425
beforeEach(() => {
2526
vi.clearAllMocks()
2627
mockPath.join.mockImplementation((...args) => args.join("/").replace(/\/+/g, "/"))
28+
mockPath.isAbsolute.mockReturnValue(true)
2729
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2830
mockCreatePolicyEngineFromFile.mockReturnValue(mockPolicyEngine as any)
2931
})
@@ -124,6 +126,11 @@ describe("loadPolicyEngine", () => {
124126
})
125127

126128
describe("error handling", () => {
129+
it("should throw when consumerDir is a relative path", () => {
130+
mockPath.isAbsolute.mockReturnValue(false)
131+
expect(() => loadPolicyEngine("compute.yaml", "./relative/path")).toThrow("policyDir must be an absolute path")
132+
})
133+
127134
it("should propagate errors from createPolicyEngineFromFile", () => {
128135
mockFs.existsSync.mockReturnValue(true)
129136
mockCreatePolicyEngineFromFile.mockImplementation(() => {

packages/aurora/src/server/policyEngineLoader.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export const loadPolicyEngine = (fileName: string, consumerDir?: string) => {
1717
const candidates: string[] = []
1818

1919
if (consumerDir) {
20+
if (!path.isAbsolute(consumerDir)) {
21+
throw new Error(`policyDir must be an absolute path, got: "${consumerDir}"`)
22+
}
2023
candidates.push(path.join(consumerDir, fileName))
2124
}
2225

0 commit comments

Comments
 (0)