Skip to content

Harden cross-platform path boundary resolution against CWE-22 escapes - #34

Open
sknr wants to merge 1 commit into
developfrom
fix-cwe22-cross-platform-path-escape-15706751150931214226
Open

sknr wants to merge 1 commit into
developfrom
fix-cwe22-cross-platform-path-escape-15706751150931214226

Conversation

@sknr

@sknr sknr commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Defensive Category: Safe Path Resolution (CWE-22 / CWE-59)

Defensive Rationale & Root Cause Analysis

The path boundary containment logic in ensureWithinRoot and resolveBundleDir previously relied solely on the native filepath.IsAbs() function. Because this function is platform-dependent, it fails to correctly identify a Windows absolute path (e.g., C:\Windows\System32 or \etc\passwd) when the Go binary is executing on a POSIX operating system. Consequently, the logic would treat the malicious absolute path as a relative path, joining it directly to the bundle root, and potentially enabling an attacker to escape the designated boundary after subsequent normalization.

Implemented Hardening & Tests Added

  1. Strict Cross-Platform Absolute Path Checking: Updated the containment functions in pkg/okf/bundle.go and cmd/okf/mcp.go to explicitly test for drive letters and root slashes on the normalized path structure instead of relying solely on filepath.IsAbs().
  2. Negative Unit Tests Added:
    • TestEnsureWithinRootCrossPlatformAbsolute in pkg/okf/mutate_security_test.go to verify deterministic rejection of payload vectors on the bundle API level.
    • TestMCPBundle_CrossPlatformAbsoluteEscape in cmd/okf/mcp_test.go to verify the same defensive invariants on the MCP interface level.

PR created automatically by Jules for task 15706751150931214226 started by @sknr

This commit hardens `ensureWithinRoot` in `pkg/okf/bundle.go` and
`resolveBundleDir` in `cmd/okf/mcp.go` to explicitly identify cross-platform
absolute paths (such as Windows drive letters or leading slashes) which would
otherwise be incorrectly identified as relative paths on POSIX systems,
bypassing path containment checks. Negative tests have been added to verify
these invariants.

Co-authored-by: sknr <11868275+sknr@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant