Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Securely create temporary directories and files using fsPromises.mkdtemp() #191

Merged
merged 7 commits into from
Oct 16, 2023

Conversation

BrianJDrake
Copy link
Contributor

@BrianJDrake BrianJDrake commented Oct 14, 2023

This change causes temporary directories and files to be created securely. Specifically, they will always be new (and therefore will not contain any untrusted data) and accessible only to the current user.

This pull request changes the four files I found by searching for tmpdir.

Since mkstemp isn't supported by Node.js yet (nodejs/node#33549), temporary files are created within temporary directories using mkdtemp; this affects the cleanup code. While working on this, I got confused about the Transcoding and Componentize tests in https://github.com/bytecodealliance/jco/blob/463589973dcf5f9fec27425e083db03ca6b4e8d3/test/cli.js, which set their own output directories and don't clean them up. I took the liberty of fixing that inconsistency by making all tests use the same temporary directory and using Mocha's teardown hook.

Closes #181.

@BrianJDrake BrianJDrake marked this pull request as draft October 14, 2023 12:40
@BrianJDrake BrianJDrake marked this pull request as ready for review October 14, 2023 14:11
@guybedford
Copy link
Collaborator

Thanks for the PR! I'll review this soon.

CLI tests: Symlink `preview2-shim` into temporary directory so that scripts
output by `jco transpile` can import `preview2-shim`.
--------------------------------------------------------------------------------
Copy link
Collaborator

@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.

This is a really great refactoring, thank you!

@guybedford guybedford merged commit 4c6b129 into bytecodealliance:main Oct 16, 2023
6 checks passed
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.

Create temporary directories using fsPromises.mkdtemp()
2 participants