Skip to content

Commit ccc9c49

Browse files
committed
fix: keep GitLab upload secrets out of logs and detect fences in CRLF bodies
1 parent e60ee43 commit ccc9c49

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎apps/server/src/http.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,11 @@ export const layerAssetRoute = HttpRouter.add(
447447
}
448448
if (asset.kind === "gitlab-media") {
449449
return yield* gitlabMediaResponse(asset, request.headers).pipe(
450-
// Request errors can carry the token, so only the URL is logged.
450+
// Errors can carry the token, and the URL the upload secret, so only the host is logged.
451451
Effect.tapError(() =>
452-
Effect.logWarning("Failed to fetch GitLab media.", { url: asset.url }),
452+
Effect.logWarning("Failed to fetch GitLab media.", {
453+
host: URL.canParse(asset.url) ? new URL(asset.url).host : "invalid",
454+
}),
453455
),
454456
Effect.orElseSucceed(() =>
455457
HttpServerResponse.empty({

‎packages/shared/src/gitlabMedia.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,9 @@ describe("gitlabMedia", () => {
8888
].join("\n"),
8989
);
9090
});
91+
92+
it("keeps fenced code as written in a body with CRLF line endings", () => {
93+
const body = ["```md", `![in a fence](/uploads/${SECRET}/fenced.png)`, "```", ""].join("\r\n");
94+
expect(resolveGitLabUploadLinks(body, "https://gitlab.com/team/app")).toBe(body);
95+
});
9196
});

‎packages/shared/src/gitlabMedia.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function resolveGitLabUploadLinks(markdown: string, projectUrl: string):
8282
.map((line) => {
8383
const continuesLabel = afterBareLabel;
8484
afterBareLabel = false;
85-
const fence = FENCE_PATTERN.exec(line);
85+
const fence = FENCE_PATTERN.exec(line.replace(/\r$/u, ""));
8686
if (fence !== null) {
8787
const marker = fence[1]!;
8888
if (openFence === null) openFence = marker;

0 commit comments

Comments
 (0)