Skip to content

loader: do not prepend cwd to path as it is a security issue - #221

Merged
alexcrichton merged 1 commit into
bytecodealliance:mainfrom
whitequark:loader-security-fix
Apr 4, 2024
Merged

alexcrichton merged 1 commit into
bytecodealliance:mainfrom
whitequark:loader-security-fix

Conversation

@whitequark

@whitequark whitequark commented Apr 3, 2024 •

Copy link
Copy Markdown
Contributor

Python does have cwd on sys.path by default:

>>> import sys; sys.path[0]
''

However, having cwd on sys.path is potentially a security issue (see safepath) and the custom loader should absolutely not add it itself since this circumvents PYTHONSAFEPATH=1, -P and other knobs that Python provides to fixes the default-unsafe behavior.

Before this commit, any application using wasmtime.loader can be subverted if it is ran in a cwd controlled by an attacker so that it runs a completely different Wasm module. Since WASI is enabled by default this means arbitrary code execution, even with PYTHONSAFEPATH set.

Python does have cwd on `sys.path` by default:

    >>> import sys; sys.path[0]
    ''

However, having cwd on `sys.path` is potentially a security issue (see
[safepath]) and the custom loader should absolutely not add it itself
since this circumvents `PYTHONSAFEPATH=1`, `-P` and other knobs that
Python provides to fixes the default-unsafe behavior.

Before this commit, any application using `wasmtime.loader` can be
subverted if it is ran in a cwd controlled by an attacker so that it
runs a completely different application. Since WASI is enabled by
default this means arbitrary code execution, even with `PYTHONSAFEPATH`
set.

[safepath]: https://docs.python.org/3/using/cmdline.html#cmdoption-P
@alexcrichton

Copy link
Copy Markdown
Member

Thanks!

@alexcrichton
alexcrichton merged commit 5456c9a into bytecodealliance:main Apr 4, 2024
@whitequark
whitequark deleted the loader-security-fix branch April 4, 2024 19:47
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.

2 participants