Skip to content
Closed
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
2 changes: 2 additions & 0 deletions src/lab/events/limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ 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 FILE_POSIX_URI_RE = /\bfile:\/\/\//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.

P2 Badge Recognize localhost authorities in file URIs

When an event contains a URI such as file://localhost/home/alice/secret.txt, this expression does not match because it requires the path's third slash immediately after file://, while RAW_POSIX_PATH_RE also skips the slashes following an authority. The URL API normalizes this standard local-file form to file:///home/alice/secret.txt, but enforceEventStructureLimits accepts it, so an unsanitized event can still persist the same sensitive local path through the ledger backstop. Match local file URIs with either an empty or localhost authority and add the authority form to the focused regression cases.

Useful? React with 👍 / 👎.


function fieldPath(base: string, key: string | number): string {
return base ? `${base}.${String(key)}` : String(key);
Expand Down Expand Up @@ -80,6 +81,7 @@ export function enforceEventStructureLimits(
}
if (
/^[A-Za-z]:\\/.test(value) ||
FILE_POSIX_URI_RE.test(value) ||
RAW_POSIX_PATH_RE.test(value) ||
value.includes("\\Users\\")
) {
Expand Down
2 changes: 2 additions & 0 deletions tests/lab-post-merge-hardening.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ test("event privacy admission rejects raw POSIX path bypass forms", () => {
"cwd=/home/@alice",
"cwd=/home/josé/work",
"x-/home/alice",
"detail=file:///etc/passwd",
"detail=file:///home/alice/secret.txt",
]) {
try {
enforceEventStructureLimits({ detail });
Expand Down
Loading