🔒 Fix Path Traversal in serve.js File Serving#3
Conversation
- 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>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
- 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>
🎯 What: Fixed a path traversal vulnerability in
⚠️ Risk: Attackers could append
serve.jswhere requests were improperly sanitized.../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.jointo cleanly resolve path traversals againstprocess.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 withdecodeURIComponentto catch encoded traversal injections (e.g.%2e%2e).PR created automatically by Jules for task 7956458420731863915 started by @megawron