Skip to content

🔒 Fix Path Traversal in serve.js File Serving#3

Open
megawron wants to merge 4 commits into
mainfrom
fix/path-traversal-serve-js-7956458420731863915
Open

🔒 Fix Path Traversal in serve.js File Serving#3
megawron wants to merge 4 commits into
mainfrom
fix/path-traversal-serve-js-7956458420731863915

Conversation

@megawron

Copy link
Copy Markdown
Contributor

🎯 What: Fixed a path traversal vulnerability in serve.js where requests were improperly sanitized.
⚠️ Risk: Attackers could append ../ segments to URL requests and read arbitrary sensitive files on the server hosting the app, such as environment files, source code, and credentials.
🛡️ Solution: Used path.join to cleanly resolve path traversals against process.cwd() and applied strict validation logic to ensure that resulting file paths correctly started with the intended base directory (plus the appropriate path separator to prevent sibling directory attacks). Added URL decoding with decodeURIComponent to catch encoded traversal injections (e.g. %2e%2e).


PR created automatically by Jules for task 7956458420731863915 started by @megawron

- Add decodeURIComponent to safely parse incoming paths
- Use path.join to resolve relative requests against process.cwd()
- Verify the normalized path strictly begins with the expected base directory
- Issue a 403 Forbidden for malformed or out-of-bound traversal attempts
- Address minor issue with query strings breaking static `/lib/` files
- Fix prevents reading sensitive local files such as /etc/passwd or .env

Co-authored-by: megawron <52606827+megawron@users.noreply.github.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 23, 2026

Copy link
Copy Markdown

Deploying 0cms with  Cloudflare Pages  Cloudflare Pages

Latest commit: cb501fd
Status:🚫  Build failed.

View logs

@google-labs-jules

Copy link
Copy Markdown

👋 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.

google-labs-jules Bot and others added 3 commits April 23, 2026 14:19
- Add decodeURIComponent to safely parse incoming paths in serve.js
- Use path.join to resolve relative requests against process.cwd()
- Verify the normalized path strictly begins with the expected base directory
- Issue a 403 Forbidden for malformed or out-of-bound traversal attempts
- Address minor issue with query strings breaking static `/lib/` files
- Fix CI build script `build.mjs` failing when trying to write directories using Bun.write. Added fs/promises stat and cp to handle directories properly when copying the `lib` directory contents.

Co-authored-by: megawron <52606827+megawron@users.noreply.github.com>
- Add decodeURIComponent to safely parse incoming paths in serve.js
- Use path.join to resolve relative requests against process.cwd()
- Verify the normalized path strictly begins with the expected base directory
- Issue a 403 Forbidden for malformed or out-of-bound traversal attempts
- Address minor issue with query strings breaking static `/lib/` files
- Fix CI build script `build.mjs` failing when trying to write directories using Bun.write. Added fs/promises stat and cp to handle directories properly when copying the `lib` directory contents.
- Compile WASM Rust module automatically as part of `build.mjs` to fix CI missing dependency error.

Co-authored-by: megawron <52606827+megawron@users.noreply.github.com>
- Add decodeURIComponent to safely parse incoming paths in serve.js
- Use path.join to resolve relative requests against process.cwd()
- Verify the normalized path strictly begins with the expected base directory
- Issue a 403 Forbidden for malformed or out-of-bound traversal attempts
- Address minor issue with query strings breaking static `/lib/` files
- Fix CI build script `build.mjs` failing when trying to write directories using Bun.write. Added fs/promises stat and cp to handle directories properly when copying the `lib` directory contents.
- Compile WASM Rust module automatically as part of `build.mjs` to fix CI missing dependency error.

Co-authored-by: megawron <52606827+megawron@users.noreply.github.com>
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