Skip to content
Open
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
5 changes: 5 additions & 0 deletions sdk/typescript/src/findings-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ export async function parseImportedFindings(
);
}
occurrenceIds.add(finding.occurrenceId);
if (finding.locations.some((location) => !safeFindingPath(location.path))) {
throw new CodexSecurityError(
`Findings JSON finding ${index + 1} has an invalid path.`,
);
}
}
return document.findings;
}
Expand Down
15 changes: 15 additions & 0 deletions sdk/typescript/tests-ts/findings-import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,19 @@ describe("findings import formats", () => {
),
).rejects.toThrow("duplicate occurrenceId");
});

test("rejects an unsafe finding location path in either import format", async () => {
const document = await sourceDocument();
document.findings[0]!.locations[0]!.path = "../../../outside/secrets.env";
await expect(
parseImportedFindings(JSON.stringify(document), "json", PLUGIN_ROOT),
).rejects.toThrow("has an invalid path");
await expect(
parseImportedFindings(
CSV_SOURCE.replace("src/extract.ts", "../../../outside/secrets.env"),
"csv",
PLUGIN_ROOT,
),
).rejects.toThrow("has an invalid path");
});
});