Skip to content
Draft
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",
Comment on lines +194 to +195

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Add a mixed-case file:/// regression case.

The current values are lowercase, so they verify rejection but not case-insensitive matching. If the i flag is removed from FILE_POSIX_URI_RE, these tests still pass. Add a mixed-case value and retain the existing raw_path assertion.

As per path instructions, the focused regression test should cover the behavior changed in src/lab/events/limits.ts.

Proposed test addition
     "detail=file:///etc/passwd",
     "detail=file:///home/alice/secret.txt",
+    "detail=FiLe:///etc/passwd",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"detail=file:///etc/passwd",
"detail=file:///home/alice/secret.txt",
"detail=file:///etc/passwd",
"detail=file:///home/alice/secret.txt",
"detail=FiLe:///etc/passwd",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/lab-post-merge-hardening.test.ts` around lines 194 - 195, Update the
file-URI test cases in the focused regression test to include a mixed-case
`file:///` detail value, while retaining the existing `raw_path` assertion and
lowercase cases. Ensure the test exercises the case-insensitive matching
behavior implemented by `FILE_POSIX_URI_RE` in the limits logic.

Source: Path instructions

]) {
try {
enforceEventStructureLimits({ detail });
Expand Down
Loading