Semantics of `mkFsPath` inconsistent between instances and vulnerable in IO

オープン
#100 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
haskell

調査の方向性

まず FsPath の説明と mkFsPath および fsPathToFilePath のエントリーポイントを読み、実際のファイルシステムとシミュレートされたファイルシステムの動作を比較します。パスがマウントポイント内に留まり、インスタンス間で一貫するように、プラットフォーム固有のエスケープを定義して検証します。これには ["/", "etc", "passwd"] の例も含まれます。

索引モデルが issue の本文から書いたものです。

説明

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.

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.

主要言語
Haskell
スター
2
フォーク
6
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

IntersectMBO/fs-sim のほかの issue

IntersectMBO/fs-sim の issue をすべて見る

似ている issue

Haskell の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。