Skip to content

Conversation

opsysdebug
Copy link

Accessing files using paths constructed from user-controlled data can allow an attacker to access unexpected resources. This can result in sensitive information being revealed or deleted, or an attacker being able to influence behavior by modifying unexpected files.

Fix this issue should validate any user-provided path before passing it to filesystem APIs. The best way to do this is to ensure that the final path, after normalization (using path.resolve and, optionally, fs.realpathSync), remains within the intended safe root directory. For the _patch handler, this is __dirname; for the default handler, it's process.cwd(). You should update both handlers to resolve and check their paths, and modify handleFile to accept only validated file paths.

Concrete steps:

  • In both _patch and _default handlers, after joining the root + user path, normalize the path and check that it starts with the intended root (using path.resolve and fs.realpathSync if available).
  • If the check fails, return a 403 error (forbidden).
  • Only call handleFile if the path is safe.
  • Optionally, wrap the normalization/check in a reusable function.

No new methods or imports are needed, as both path and fs are already present.

Edits required:

  • lib/server.js, in _patch and _default handlers (lines ~524-535), update file path resolution, add containment check, error out if the check fails.

References
npm:sanitize-filename

@opsysdebug opsysdebug requested a review from a team as a code owner August 24, 2025 20:00
@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 24, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

@browserstack-support
Copy link

browserstack-support commented Aug 25, 2025 via email

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.

4 participants