Live data from Hacker News

Recommendations when publishing a WASM library

nickb.dev

1–10 of 22 posts

Re: Recommendations when publishing a WASM library

#2
Security wise, it is not a good idea to consume WASM libraries "as is", ask for the source, read it, and compile it yourself

You don't want to be in a position to ship code to production with binary code that could potentially be harmful

Off topic: Please don't mess up the way my browser scroll pages, it is infuriating

Re: Recommendations when publishing a WASM library

#3

Security wise, it is not a good idea to consume WASM libraries "as is", ask for the source, read it, and compile it yourself You don't want to be in a position to ship code to production with binary code that could potentially be harmful Off topic: Please don't mess up the way my browser scroll pages, it is infuriating

Can you elaborate on that? From what I know, WASM is a safe, rather abstract bytecode format and has far less API capabilites as JS has (which is why you need to call it from JS to affect the browser).

Re: Recommendations when publishing a WASM library

#4

Security wise, it is not a good idea to consume WASM libraries "as is", ask for the source, read it, and compile it yourself You don't want to be in a position to ship code to production with binary code that could potentially be harmful Off topic: Please don't mess up the way my browser scroll pages, it is infuriating

[deleted]

Re: Recommendations when publishing a WASM library

#5
post #3

Security wise, it is not a good idea to consume WASM libraries "as is", ask for the source, read it, and compile it yourself You don't want to be in a position to ship code to production with binary code that could potentially be harmful Off topic: Please don't mess up the way my browser scroll pages, it is infuriating

Can you elaborate on that? From what I know, WASM is a safe, rather abstract bytecode format and has far less API capabilites as JS has (which is why you need to call it from JS to affect the browser).

The concern is the same as with any dependency: The dependency runs under your privileges with access to your data. A malice vendor could do "anything" at least within the scope of your application.

For instance if you create a web mail application the code probably has access to all mails, can delete them, can send mail under the user's identity, ...

How relevant those scenarios are you have to evaluate.

If you compile yourself, you can verify the source to increase trust. If you just get the binary, you have to trust the vendor more.

Re: Recommendations when publishing a WASM library

#6
post #3

Earlier quoted context omitted.

Can you elaborate on that? From what I know, WASM is a safe, rather abstract bytecode format and has far less API capabilites as JS has (which is why you need to call it from JS to affect the browser).

The concern is the same as with any dependency: The dependency runs under your privileges with access to your data. A malice vendor could do "anything" at least within the scope of your application. For instance if you create a web mail application the code probably has access to all mails, can delete them, can send mail under the user's identity, ... How relevant those scenarios are you have to evaluate. If you comp…

But again, it's not "just" a binary. You provide the interfaces to it that actually affect the world. I agree with the general implications of using a dependency though.

Re: Recommendations when publishing a WASM library

#7

Security wise, it is not a good idea to consume WASM libraries "as is", ask for the source, read it, and compile it yourself You don't want to be in a position to ship code to production with binary code that could potentially be harmful Off topic: Please don't mess up the way my browser scroll pages, it is infuriating

In the case of NPM consumers of wasm libraries, it often isn't realistic option "as-is", since they won't have the toolchain needed to build the code. Rust is a lot more well oiled than C/C++ in this regard but it's a bit of a hassle to line things up and keep things reliable and reproducible. (Good luck if the blob is not only C/C++ but uses 3rd party dependencies on top of that, which often require even more hurdles). If you don't use the pre-built blob you'll often have to 'insert' it otherwise into the library, somehow, which is its own chore. So it's all a bit chicken and egg at some level. Now, it's not like a lot of these packages ever followed best practices in this regard (I'm reminded of many Ruby, Python, JS packages that love to ship random .so files, and often do it incorrectly) but it is what it is.

That said I generally agree with the premise, and even with sandboxing you should vet dependencies like these where appropriate if you can. A good example of this is something like an image decoder versus a database library (both of these being real scenarios; e.g. using a pure-Rust implementation of some SQL protocol.) The first one I probably wouldn't worry too about much, you're just giving it pixels in and getting pixels out. But the second one is likely worth a bit of scrutiny since it interfaces directly with a sensitive component.

Re: Recommendations when publishing a WASM library

#8
Wow, this is a great resource! I’ve been dealing with a lot of these issues with a JS sandbox library I’m building quickjs-emecripten. I want to offer a ton of different build variants of my core WASM file. Here’s what I tried: https://github.com/justjake/quickjs-emscripten/blob/master/t...

This approach works great for NodeJS, but once I ran a test bundle I found that Webpack (and bundlephobia) included all the base64 “release” variants instead of lazy-loading the import statements. Bummer. I assumed this because Typescript on its own compiled import to Promise.resolve(require(…)), so it’s good to know that most bundlers will STILL get this wrong even if I’m emitting ES6 module import syntax. Yikes! I need to bite the bullet and start using Rollup to emit a slew of separate entry points. Oy veh.

Anyways A+++ would read again. This will save me 4-5 days of work stubbing my toe on bundlers and build system which is the Least Fun part of JS work.

Re: Recommendations when publishing a WASM library

#9

Security wise, it is not a good idea to consume WASM libraries "as is", ask for the source, read it, and compile it yourself You don't want to be in a position to ship code to production with binary code that could potentially be harmful Off topic: Please don't mess up the way my browser scroll pages, it is infuriating

No post body was provided.

Re: Recommendations when publishing a WASM library

#10
post #6

Earlier quoted context omitted.

The concern is the same as with any dependency: The dependency runs under your privileges with access to your data. A malice vendor could do "anything" at least within the scope of your application. For instance if you create a web mail application the code probably has access to all mails, can delete them, can send mail under the user's identity, ... How relevant those scenarios are you have to evaluate. If you comp…

But again, it's not "just" a binary. You provide the interfaces to it that actually affect the world. I agree with the general implications of using a dependency though.

At least in in-browser Blazor (C# compiled to WASM) I have full access to the page's Javascript environment: I can call most Javascript methods available, and I can even call eval.

I'm still new to WASM, but I assume this functionality is part of the WASM runtime? (As opposed to a hook that's part of the Javascript part of Blazor?)

Post reply on HN