Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

fix(publication): link Markdown evidence to plain source lines (#2032)

wjb9556f28d465
diff --git a/sdk/typescript/src/publication.ts b/sdk/typescript/src/publication.ts
index 2e4e6ba91..e62814c8d 100644
--- a/sdk/typescript/src/publication.ts
+++ b/sdk/typescript/src/publication.ts
@@ -501,8 +501,15 @@ function immutableSourceUrl(
const repository = remote.pathname
.replace(/\.git\/?$/, "")
.replace(/\/$/, "");
- const path = location.path.split("/").map(encodeURIComponent).join("/");
+ const segments = location.path.split("/");
+ const path = segments.map(encodeURIComponent).join("/");
remote.pathname = `${repository}/blob/${target.revision}/${path}`;
+ // GitHub renders Markdown previews without source line anchors.
+ const markdownPath =
+ /\.(?:md|markdown|mdown|mdwn|mkd|mkdn|mkdown|mdx|litcoffee|livemd|ronn|scd|workbook)$/i;
+ if (markdownPath.test(location.path) || segments.at(-1) === "contents.lr") {
+ remote.search = "plain=1";
+ }
remote.hash = `L${location.startLine}${
location.endLine === undefined || location.endLine === location.startLine
? ""
diff --git a/sdk/typescript/tests-ts/publication.test.ts b/sdk/typescript/tests-ts/publication.test.ts
index 2e88bdf42..e897c56fc 100644
--- a/sdk/typescript/tests-ts/publication.test.ts
+++ b/sdk/typescript/tests-ts/publication.test.ts
@@ -599,7 +599,7 @@ describe("scan publication preparation", () => {
expect(await readFile(findingsPath, "utf8")).toBe(saved);
});
- test("preserves nested historical evidence coordinates and source-link rules", async () => {
+ test("links code and Markdown source lines at nested historical evidence coordinates", async () => {
const scanDirectory = await copyExample();
const findingsPath = join(scanDirectory, "findings.json");
const findings = await readJson<FindingsDocument>(findingsPath);
@@ -613,7 +613,7 @@ describe("scan publication preparation", () => {
code: "canonical_nested_location()",
explanation: "Canonical explanation.",
location: {
- path: "src/canonical-nested.py",
+ path: "docs/canonical-nested.md",
startLine: 20,
endLine: 24,
},
@@ -634,12 +634,12 @@ describe("scan publication preparation", () => {
path: "src/shadow.py",
startLine: 1,
endLine: 2,
- location: { path: "src/nested.py", startLine: 12, endLine: 15 },
+ location: { path: "content/contents.lr", startLine: 12, endLine: 15 },
},
{
id: "reversed-range",
code: "reversed_range()",
- location: { path: "src/reversed.py", startLine: 48, endLine: 47 },
+ location: { path: "docs/reversed.MDX", startLine: 48, endLine: 47 },
},
{
id: "path-only",
@@ -664,15 +664,15 @@ describe("scan publication preparation", () => {
const description = await issueDescription(scanDirectory);
- expect(description).toContain("src/canonical-nested.py#L20-L24)");
+ expect(description).toContain("docs/canonical-nested.md?plain=1#L20-L24)");
expect(description).toContain("[``app/api/`id`/route.ts:7``]");
expect(description).toContain("app/api/%60id%60/route.ts#L7)");
expect(description).toContain("`` `route`.ts ``");
expect(description).not.toContain("src/shadow-canonical.py");
- expect(description).toContain("src/nested.py:12-15");
- expect(description).toContain("src/nested.py#L12-L15)");
+ expect(description).toContain("content/contents.lr:12-15");
+ expect(description).toContain("content/contents.lr?plain=1#L12-L15)");
expect(description).not.toContain("src/shadow.py");
- expect(description).toContain("src/reversed.py#L48)");
+ expect(description).toContain("docs/reversed.MDX?plain=1#L48)");
expect(description).not.toContain("#L48-L47");
expect(description).toContain("`src/path-only.py`");
expect(description).not.toContain("[`src/path-only.py");