mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
* fix(media-use): never write recipe files through links A project folder can carry symbolic links inside .media/recipes/<name>/. When recipe.json there did not parse, freezing a recipe under that name reused the folder and wrote each recipe file through the link, which could create or overwrite files outside the project. The user-tier copy then carried those links into ~/.media/recipes, and using the recipe copied them into other projects. Freezing and using a recipe now refuse a link at .media, .media/recipes or the recipe folder before anything moves or is written. Each recipe file is written as a new file and renamed into place, so a link at its name is replaced, never followed. Only the files a freeze just wrote reach the user tier, and using a recipe imports only its regular recipe files. Using a recipe also refuses a recipe whose frame.md is a link, and replaces a frame.md link in the project instead of writing through it. * fix(media-use): read user-tier recipe files through one no-follow handle Checking a file with lstat and then reading it by path leaves a gap in which the file can be swapped for a link. Importing a recipe from the user tier and copying its frame.md now open each file once with O_NOFOLLOW, and check that the open handle is a regular file before reading it. * fix(media-use): refuse recipe file links where Node has no O_NOFOLLOW Node has no O_NOFOLLOW on Windows, so opening a recipe file there followed a link and read its target. readRegularFile now checks the path with lstat first and refuses anything but a regular file. After the open, the handle must be a regular file with the same device and inode that lstat saw, so a link swapped in between is refused on every platform. O_NOFOLLOW stays as an extra guard where it exists, and O_NONBLOCK keeps a FIFO from blocking the open. A test passes 0 as the no-follow flag to check the Windows path on any platform, and another checks that a FIFO is refused without blocking. * refactor(media-use): compare the path with the handle after opening readRegularFile now opens first, then requires that lstat of the path shows a regular file with the same device and inode as the handle. A link has its own inode, so it never matches the file an open reached through it, with or without O_NOFOLLOW. O_NONBLOCK keeps a FIFO from blocking the open. Checking after the open, instead of before it, leaves no check-then-open gap on the path.