input-output-hk / input-output-hk/fs-sim
Semantics of `mkFsPath` inconsistent between instances and vulnerable in IO
- Dominant language
- Haskell
- Stars
- 2
- Forks
- 6
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 1
Description
The semantics of `mkFsPath` are inconsistent between the real and simulated filesystem instances, as is documented in the description of `FsPath`.
This inconsistency makes it easy to write code that behaves differently depending on whether or not it runs on a real or simulated filesystem.
This makes it nigh-impossible to write code that is truly known to be invariant over what kind of filesystem it will be evaluated on, since the segments of the `FsPath` will be interpreted differently by the different instances.
Notably, the code `mkFsPath ["/", "etc", "passwd"]` will yield an `FsPath` that is well-behaved in the simulation, but yields a path to `/etc/passwd` when evaluated with the actual filesystem, _regardless of the mount point_.
```hs
tmpDir <- Dir.getTemporaryDirectory
let mountPoint = tmpDir "fs-sim"
let hasFS = ioHasFS (MountPoint mountPoint)
let passwd = mkFsPath ["/", "etc", "passwd"]
putStrLn (unsafeToFilePath passwd)
-- "/etc/passwd"
-- NOT: "/tmp/fs-sim/etc/passwd"
```
This breaks the encapsulation that the mount point is intended to introduce and introduces an attack vector that can be exploited by any `FsPath` created from user input or by an unreviewed version of a dependency.
Furthermore, `fs-api` significantly obfuscates the dangers here.
In my opinion, the `fsPathToFilePath` function that is used to interpreted `FsPath` on the real filesystem should escape all characters that have special meaning on the current platform in order to yield consistent behaviour across the API instances and better encapsulation.
Contributor guide
Research direction
Start by reading the FsPath description and the mkFsPath and fsPathToFilePath entry points, comparing real and simulated filesystem behavior. Define and verify platform-specific escaping so paths remain mount-point-contained and consistent across instances, including the ["/", "etc", "passwd"] example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- operating-systems, security
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100