Skip to content

Allow dynamic changes to web worker permissions #30339

@omasakun

Description

@omasakun

Intro

Deno's permission system is a distinctive feature that is useful for secure plugin systems and sandboxing.
However, there is currently no way to change permissions during execution other than using a tty-based prompter. This limits the possible uses.

Therefore, I propose making it possible to change Web Worker permissions not only at startup but also after startup.
This will allow users to implement their own user interfaces for managing permissions for the modules they want to execute.

For example, when creating an app that allows users to add extensions, such as vscode, users could be prompted via a GUI to grant file access permissions to the extensions.

Demonstration

// start a worker with no permissions
const worker = new Worker("extension.js", { type: "module", deno: { permissions: "none" } });

worker.onmessage = ({ data }) => {
  if (data.event === "requestPermission") {
    if (confirm("allow the extension to access local files?")) {
      // allow the worker to access local files -- new api
      worker.updatePermissions({ read: true });
    }
  }
};

Related to #29280 and #29834

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