<h2 dir="auto">Why</h2>
<p dir="auto">Recent controversy about <code class="notranslate">node-ipc</code> showcased node's security weakness. People would think that deno is bulletproof for this kind of issues, but it isn't.</p>
<h2 dir="auto">Let me elaborate:</h2>
<p dir="auto">Even if you'd import non-malicious module with semver – you're fine until its time to update. You're mostly probably just updating those numbers in imports and maybe refactoring code, you don't check whether module has became dangerous.</p>
<h2 dir="auto">Idea</h2>
<p dir="auto">Here comes my idea – import permissions.<br>
By default you could take two directions:</p>
<ul dir="auto">
<li>Inherit permissions from the entry module, fully backwards compatible</li>
<li>Allow none of the permissions by default, breaking change<br>
That way, we would be 100% safe that modules imported by us wouldn't do what we need them to do.</li>
</ul>
<h2 dir="auto">Syntax</h2>
<p dir="auto">Syntax is debatable, however I see this coming closely to import assertions, e.g.:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// static imports
import * as malicious from &quot;https://deno.land/x/some-random-module/mod.ts&quot; allow { read: true } // when allowing none by default
import * as malicious from &quot;https://deno.land/x/some-random-module/mod.ts&quot; allow { read: true, write: false, run: false } // when inheriting permissions
import * as malicious &quot;https://deno.land/x/some-random-module/mod.ts&quot; allow { read: &quot;/tmp&quot; } // allow reading only specific directory

// dynamic imports
const malicious = await import(&quot;https://deno.land/x/some-random-module/mod.ts&quot;, {
  allow: {
    read: true,
  },
})"><pre class="notranslate"><span class="pl-c">// static imports</span>
<span class="pl-k">import</span> <span class="pl-c1">*</span> <span class="pl-k">as</span> <span class="pl-s1">malicious</span> <span class="pl-k">from</span> <span class="pl-s">"https://deno.land/x/some-random-module/mod.ts"</span> <span class="pl-s1">allow</span> <span class="pl-kos">{</span> <span class="pl-s1">read</span>: <span class="pl-c1">true</span> <span class="pl-kos">}</span> <span class="pl-c">// when allowing none by default</span>
<span class="pl-k">import</span> <span class="pl-c1">*</span> <span class="pl-k">as</span> <span class="pl-s1">malicious</span> <span class="pl-k">from</span> <span class="pl-s">"https://deno.land/x/some-random-module/mod.ts"</span> <span class="pl-s1">allow</span> <span class="pl-kos">{</span> <span class="pl-s1">read</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span> <span class="pl-s1">write</span>: <span class="pl-c1">false</span><span class="pl-kos">,</span> <span class="pl-s1">run</span>: <span class="pl-c1">false</span> <span class="pl-kos">}</span> <span class="pl-c">// when inheriting permissions</span>
<span class="pl-k">import</span> <span class="pl-c1">*</span> <span class="pl-k">as</span> <span class="pl-s1">malicious</span> <span class="pl-s">"https://deno.land/x/some-random-module/mod.ts"</span> <span class="pl-s1">allow</span> <span class="pl-kos">{</span> <span class="pl-s1">read</span>: <span class="pl-s">"/tmp"</span> <span class="pl-kos">}</span> <span class="pl-c">// allow reading only specific directory</span>

<span class="pl-c">// dynamic imports</span>
<span class="pl-k">const</span> <span class="pl-s1">malicious</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-k">import</span><span class="pl-kos">(</span><span class="pl-s">"https://deno.land/x/some-random-module/mod.ts"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
  <span class="pl-c1">allow</span>: <span class="pl-kos">{</span>
    <span class="pl-c1">read</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
  <span class="pl-kos">}</span><span class="pl-kos">,</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<p dir="auto">Sorry if this has been asked or discussed before. Can't seem to find it.</p>
<p dir="auto">Can I make sure imported scripts are in Sandbox mode even if my own script isn't.</p>
<p dir="auto"><code class="notranslate">// I'd like to make sure this imported script doesn't have access to disk or network even though my code is networking</code><br>
<code class="notranslate">import { SomeFeature} from "https://url.com/some-small-library.ts";</code></p>