Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/lab/events/limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const FORBIDDEN_EXACT_KEYS = new Set([

const RAW_POSIX_PATH_RE =
/(?:^|[^A-Za-z0-9._~/])\/(?:(?=$|[^A-Za-z0-9._~/])|(?!\/)(?![ \t\r\n])(?:\/|[^/\0\r\n]+)+\/?(?=$|[^A-Za-z0-9._~/]))/u;
const ASCII_URL_WHITESPACE_RE = /[\t\r\n]/g;
const FILE_URI_RE = /(?:^|[^A-Za-z0-9+.-])file:/i;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Normalize URL whitespace before matching file schemes

When an event string contains embedded ASCII URL whitespace, such as fi\nle:///etc/passwd, fil\te:///etc/passwd, or file\n:///etc/passwd, this regex does not match and the existing POSIX-path check also misses the repeated slash form. Bun's WHATWG URL parser normalizes each of these to file:///etc/passwd, so the follow-up slash and separator-less fixes still allow a file-URL-encoded local path into retained Lab evidence. Strip tabs, CR, and LF according to URL preprocessing before applying FILE_URI_RE, and add focused regression cases for these forms.

Useful? React with 👍 / 👎.


function fieldPath(base: string, key: string | number): string {
return base ? `${base}.${String(key)}` : String(key);
Expand Down Expand Up @@ -80,6 +82,8 @@ export function enforceEventStructureLimits(
}
if (
/^[A-Za-z]:\\/.test(value) ||
FILE_URI_RE.test(value) ||
FILE_URI_RE.test(value.replace(ASCII_URL_WHITESPACE_RE, "")) ||
RAW_POSIX_PATH_RE.test(value) ||
value.includes("\\Users\\")
) {
Expand Down
22 changes: 21 additions & 1 deletion tests/lab-post-merge-hardening.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ test("replay discards an oversized unterminated line after reporting it once", (
expect(replay.corruptions[0]?.kind).toBe("malformed_line");
});

test("event privacy admission rejects raw POSIX path bypass forms", () => {
test("event privacy admission rejects raw filesystem path bypass forms", () => {
for (const detail of [
"config=/home/alice/work/repo",
"cwd=/usr/local/bin",
Expand All @@ -192,6 +192,22 @@ test("event privacy admission rejects raw POSIX path bypass forms", () => {
"cwd=/home/@alice",
"cwd=/home/josé/work",
"x-/home/alice",
"file:///etc/passwd",
"FiLe:///home/alice/secret.txt",
"file://localhost/home/alice/secret.txt",
"detail_file:///etc/passwd",
"file://server/share/secret",
String.raw`file:\\server\share\secret`,
String.raw`file:\C:\secret\data`,
String.raw`file:C:\private\secret`,
"file:etc/passwd",
"fi\nle:///etc/passwd",
"fil\te:///etc/passwd",
"file\r:///etc/passwd",
"file\n:///etc/passwd",
"detail\nfile:///etc/passwd",
"detail\rfile:etc/passwd",
"detail\tfile:C:\\private\\secret",
]) {
try {
enforceEventStructureLimits({ detail });
Expand All @@ -200,6 +216,10 @@ test("event privacy admission rejects raw POSIX path bypass forms", () => {
expect((err as { code?: string }).code).toBe("raw_path");
}
}

for (const detail of ["https://example.com/path", "profile:///etc/passwd"]) {
expect(() => enforceEventStructureLimits({ detail })).not.toThrow();
}
});

test("invalid JSON contract artifacts classify as artifact_mismatch", () => {
Expand Down
Loading