-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Problem
We currently use FFI for loading sqlite3 (via jsr:@db/sqlite3), which is problematic because it'll add code from jsr:@denosaurs/plug. That code has a few issues (for example, it'll require read and write access to $DENO_DIR, network access and it'll download a dynamic library without integrity checks from the Internet).
We've already thought of some mitigations (see #73), but downloading a dynamic library from the Internet can already be problematic, since it could contain any arbitrary code, and it'll run outside of Deno's permission sandbox.
As for why this happens, there are a few reasons I can think of:
- The library is loaded using Deno's FFI interface, which uses
dlopen. I'm not entirely sure yet, but this might require a separate file for it to work. - Downloading a file from the Internet is flexible because the correct file can be downloaded. The library needs to be for the correct operating system and architecture.
Solution
Ideally, we'd want chel to be a standalone binary without having to download (potentially)) arbitrary binaries from the Internet. Solving this issue might also de-prioritise #73, since perhaps then we won't need --allow-read=/ in the binary.
There are a few ways to go about it:
- We could ship
chelandlibsqlite3.so(and its variants for different platforms) as separate files and instruct users to useDENO_SQLITE_PATH. However, this isn't very user-friendly. - We could see if there's a way to bundle
libsqlite3.so(and its variants for different platforms) in thechelbinary. Doing this requires:
a. Being able to usedlopenunder these circumstances
b. Using the correct library for the platform and architecture the binary targets
c. Modifying the bundle (or the way it works) to load the library this way - We could switch to a different library that doesn't rely on FFI, such as a WASM version (note that this might result in a performance penalty).