Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic import should respect permissions #2761

Closed
teleclimber opened this issue Aug 11, 2019 · 3 comments · Fixed by #2764
Closed

Dynamic import should respect permissions #2761

teleclimber opened this issue Aug 11, 2019 · 3 comments · Fixed by #2764

Comments

@teleclimber
Copy link

(async () => {
	const filename = "../../../../some/sensitive/dir/data.json";

	let secrets = await import(filename);   // no prompts from Deno cli
	console.log(JSON.stringify(secrets));

	let file = await Deno.open(filename);    // prompts: "Deno requests read access...."
        await Deno.copy(Deno.stdout, file);
        file.close();
})();

Now that Deno has dynamic imports, file paths no longer need to be hard-coded into the script, making it trivial for a malicious script to probe possible directories in a loop hoping to find a juicy JSON.

According to this comment import might one day be able to read more than just JSON files, making this even more problematic and basically defeating the purpose of --allow-read.

I suggest that any import that resolves to a file outside the "main" script's directory should have an explicit "read" permission, such as --allow-read or `--allow-read=/path/to/import/".

@kevinkassimo
Copy link
Contributor

I agree this is indeed a problem comparing to static imports. However currently our dynamic import callback is implemented in core/ which has no idea about the whitelists or permission flags, which resides in cli/. Maybe we could add a policy check callback to core/ that takes a string, default to predicate that always return true, and allows cli/ (worker) to overwrite it?

@kitsonk
Copy link
Contributor

kitsonk commented Aug 11, 2019

Or we disallow dynamic import of JSON, or we disallow root breaking for dynamic imports, or we put dynamic imports behind a flag.

@ry
Copy link
Member

ry commented Aug 12, 2019

Yes this is a problem. And —allow-net is needed to load remote URLs.

@kevinkassimo It’s not so bad - there is a hook in CLI for dynamic import. Security checks can be put there.

i.set_dyn_import(move |id, specifier, referrer| {

@ry ry changed the title Deno script can read any JSON file anywhere on computer without prompt Dynamic import should respect permissions Aug 12, 2019
@ry ry closed this as completed in #2764 Aug 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants