Skip to content

security: prevent arbitrary file read via path traversal in file share #498

Open

Description

@Abfa41

Summary

The /api/files/browse and /api/files/download endpoints in src/server/signalling/handlers/fileShare.ts resolve user-provided path parameters without verifying if the resolved path remains within an allowed boundary. This allows a client to read arbitrary files from the host system (e.g., /etc/passwd or C:\Windows\win.ini).

Scope

Security fix. Restrict filesystem access to the user's Home directory (os.homedir()) and the designated Upload directory (getUploadDir()).

  • Add an isPathSafe(targetPath) helper in fileShare.ts.
  • Apply the guard in handleFileBrowse: fallback to the default upload directory if the path is unsafe.
  • Apply the guard in handleFileDownload: return a 403 Forbidden if the path is unsafe.
  • Implement Windows-specific case normalization (toLowerCase()) inside the helper to prevent bypasses like C:\Users vs c:\users.

Not in scope

  • handleFileUpload (uploads are already strictly sanitized via path.basename()).
  • Completely disabling filesystem browsing (the feature is meant to allow host browsing, but it must be sandboxed to the user's home/upload directories).

Verification

  • npm run test passes locally (7 test files, 43 tests passed).
  • Manually tested attempting to browse/download paths outside the home directory; correctly falls back or returns 403.

Activity

  1. github-actions commented on Nov 17, 2026

    @github-actions

    Discussions are carried on Discord.

    Instead of commenting here, go to the Discord channel.

    macOS and macOS-related issues are not supported at the moment. We are looking for funding to support macOS and would appreciate sponsorships.

    If you find this project useful, a GitHub star would be appreciated.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions