WebAssembly with Rust problem compiling wasm

Hi,

I am a new user just trying out WebAssembly with Rust. I coded up some rust code that reads from Postgres and returns vector of structs. Hoping to expose this to javascript via WebAssembly. Is this something that is not doable in terms of security? Like not allowing WebAssembly to read a local file.

By including Postgres crate in my library I hit this problem.

error[E0583]: file not found for module `sys`
  --> /Users/laiboonhui/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.3.9/src/lib.rs:72:5
   |
72 | mod sys;
   |     ^^^
   |
   = help: name the file either sys.rs or sys/mod.rs inside the directory "/Users/laiboonhui/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.3.9/src"

error: aborting due to previous error

WebAssembly can't read/write to files on disk, at least not without a JS shim (or more likely, web-sys's File) which goes through the regular web File API and is limited by those constraints like explicitly asking the user for permission.

Thinking about it from a security perspective - this makes total sense, otherwise any ol' site could read any visitor's local harddrive and all the goodies therein.

Yes, I agree it makes sense for reading local file. But how about querying information from Postgres? I think it should be doable no?

Unfortunately the web also doesn't allow direct remote/tcp connections - rather you have to go through one of the web's network api's (similar to the File api restriction - but in this case it's the limitations of XHR/WebSockets/etc.)

I think the best chance of success is to put a layer in front of the database that speaks one of the web API's, for example GitHub - PostgREST/postgrest: REST API for any Postgres database .. then you could use native wasm-bindgen calls for talking to it.

WASM in the browser has no access to anything outside of its sandbox, except talking to JavaScript. So if plain JS can't do it, WASM can't do it either.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.