Skip to content

Disallow absolute path at the raw WASI level#270

Merged
mhdawson merged 1 commit intonodejs:mainfrom
yagehu:abs-path
Jun 14, 2024
Merged

Disallow absolute path at the raw WASI level#270
mhdawson merged 1 commit intonodejs:mainfrom
yagehu:abs-path

Conversation

@yagehu
Copy link
Contributor

@yagehu yagehu commented Jun 11, 2024

This commit fixes a path_open behavior that allows opening absolute paths. Although the path normalization correctly resolves the path and enforces the sandbox, it's still a good idea to converge with other runtimes here.

fixes #269

This commit fixes a `path_open` behavior that allows opening absolute
paths. Although the path normalization correctly resolves the path and
enforces the sandbox, it's still a good idea to converge with other
runtimes here.

fixes nodejs#269

Signed-off-by: Yage Hu <me@huyage.dev>
Comment on lines +190 to +191
pass("/bar", "/baz", "bar/test_path", "/baz/bar/test_path");
pass("/bar", "/baz", "bar/../bar/test_path", "/baz/bar/test_path");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two test cases were spec'd wrong to begin with.

Copy link
Contributor

@guybedford guybedford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a quick verification against the Wasmtime test suite and can confirm that this is the correct behaviour for Wasmtime.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mhdawson mhdawson merged commit 9811374 into nodejs:main Jun 14, 2024
@yagehu yagehu deleted the abs-path branch October 19, 2024 14:57
@aduh95 aduh95 mentioned this pull request Aug 16, 2025
aduh95 added a commit that referenced this pull request Sep 2, 2025
Notable changes:

- Disallow malformed path with null byte (#266) (7aaa0b4)
- Preserve trailing slash in file path (#268) (afffaaa)
- Disallow absolute path at the raw WASI level (#270) (9811374)
- Error if creating symlink to absolute path (#272) (c8d4f01)
- Add cflite and document normalize path (#280) (6eeddba)
- Resolve old_path in uvwasi_path_symlink() (#303) (98da5ad)
- Use index rather than `telldir`/`seekdir` to represent `fd_readdir` cookie (#298) (392e1f1)
- fix: static library name (#305) (146e516)
- fix: do not put header files in a subfolders (#302) (ec28b58)
- fix: explicitly export symbols (#308) (4e9b4e0)
@fzhinkin
Copy link

Just to clarify: this change disallowed absolute paths in all functions, and that was an expected outcome (even though the summary says that the original target was path_open only)?

@yagehu
Copy link
Contributor Author

yagehu commented Nov 24, 2025

Just to clarify: this change disallowed absolute paths in all functions, and that was an expected outcome (even though the summary says that the original target was path_open only)?

Yes. The original problem was detected with path_open, but all such behaviors should be considered errors. The most current WASI filesystem spec says:

All functions in wasi-filesystem which operate on filesystem paths take a pair of values: a base directory handle, and a relative path. Absolute paths are not permitted, and there is no global namespace. All path accesses are relative to a base directory handle.

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.

Should not be able to path_open absolute path

4 participants