Skip to content

Should WebAssembly be at the same "privilege level" as JS? #41

Closed

Description

@littledan

This proposal lets WebAssembly import JS modules just as much as it lets JS import WebAssembly modules. The idea is that they're all part of the same big module graph. Logically, they can be thought of at the same "privilege level"--in HTML, this level would be based on the origin of the document that the module graph was loaded from.

Having WebAssembly and JS modules at the same privilege level contradicts the idea, which the Wasm/JS API supports, of WebAssembly only having access to what's passed into it explicitly. Instead, Wasm modules within ESM can make a request for any JS module--even on a different origin--and that JS module could package up any Web API in a form that can be accessed by Wasm. So, the thinking is a bit different.

Should we add Wasm/JS integration in a way which equalizes their privilege levels like this? Or should we consider certain restrictions, such as allowing JS to import Wasm, but not the reverse?

(Note, if we did have a "lower privilege" way of running code, there would be a massive demand to have this for JS modules as well. But it's unclear to me how this design should look. We're not talking about hard security boundaries here, since it's all within the same process, but more like softer isolation, what is given direct access to what, as with the Realm API.)

Activity

  1. guybedford commented on Nov 11, 2020

    @guybedford
    Collaborator

    Interesting questions. When you mention JS modules as well in terms of privilege management, this may also relate to the isolated scopes proposal for restricting import capabilities.

  2. devsnek commented on Nov 11, 2020

    @devsnek
    Member

    this sounds like something that would be represented in an esm resolver implementation, not this proposal.

  3. littledan commented on Nov 11, 2020

    @littledan
    CollaboratorAuthor

    Yeah, I agree that I'd like to separate these more complex questions from this proposal (so I do somewhat agree with @devsnek 's 😕 reaction), but I find that many, many people have the intuition that Wasm runs at a lower privilege level, so I'm not sure what order we should do these things in.

  4. lukewagner commented on Nov 11, 2020

    @lukewagner
    Member

    I agree that JS and wasm should run at the same privilege level. To isolate wasm, I think there should be two options:

    • some solution orthogonal to wasm that works just as well for JS
    • use instantiate (either via the JS API or via Module Linking)
  5. annevk commented on Nov 30, 2020

    @annevk
    Member

    I don't think it's about JS vs Wasm and "privilige" might be the wrong word to use here; it's about Wasm having much better encapsulation than JS and letting Wasm import JS destroying that.

    (And yes, I think there should be some kind of top-level Wasm that has access to the global.)

  6. Pyrolistical commented on Jun 6, 2021

    @Pyrolistical

    We must retain backwards compatibility for security of all existing wasm by ensuring WebAssembly.instantiate(bufferSource, importObject); fails given (import "./counter.js" "count" ... as there is no key of ./counter.js in importObject.

    What we should do is introduce a new WebAssembly.instantiateWithEsm(bufferSource) API for this proposal if we really want to have API parity in JS land.

  7. fgmccabe commented on Dec 6, 2021

    @fgmccabe

    Jumping in with both feet ... :)

    It seems to me that regardless of usage, importing a module (whether it is JS or Wasm) should simply be subject to the same requirements and access that the top-level module (i.e., the one mentioned in the script element) has.

    Put another way, there are two orthogonal aspects: whether a given collection of modules may be imported or not and the wiring up of those modules into a coherent executable program.

    Please forgive me if this is old news...

  8. guybedford commented on Jul 11, 2025

    @guybedford
    Collaborator

    This was effectively resolved to be true in the HTML PR based on the argument that any cyclic module record can import any other cyclic module record and therefore exists at a similar privilege level transitively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions