summaryrefslogtreecommitdiff
path: root/cli/state.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-05-11 13:13:27 +0200
committerGitHub <noreply@github.com>2020-05-11 13:13:27 +0200
commit32aeec9630dc91162f0408b95dd86e1c26e4c1d3 (patch)
treef93d8e6b665df0c3054dba56973712412916493e /cli/state.rs
parent0d148c6e80583dfe029d5362f61b92334a22341a (diff)
refactor: check permissions in SourceFileFetcher (#5011)
This PR hot-fixes permission escapes in dynamic imports, workers and runtime compiler APIs. "permissions" parameter was added to public APIs of SourceFileFetcher and appropriate permission checks are performed during loading of local and remote files.
Diffstat (limited to 'cli/state.rs')
-rw-r--r--cli/state.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/cli/state.rs b/cli/state.rs
index 8c425d700..9501ed286 100644
--- a/cli/state.rs
+++ b/cli/state.rs
@@ -67,6 +67,7 @@ pub struct StateInner {
pub seeded_rng: Option<StdRng>,
pub target_lib: TargetLib,
pub debug_type: DebugType,
+ pub is_main: bool,
}
impl State {
@@ -314,9 +315,20 @@ impl ModuleLoader for State {
let module_url_specified = module_specifier.to_string();
let global_state = state.global_state.clone();
let target_lib = state.target_lib.clone();
+ let permissions = if state.is_main {
+ Permissions::allow_all()
+ } else {
+ state.permissions.clone()
+ };
+
let fut = async move {
let compiled_module = global_state
- .fetch_compiled_module(module_specifier, maybe_referrer, target_lib)
+ .fetch_compiled_module(
+ module_specifier,
+ maybe_referrer,
+ target_lib,
+ permissions,
+ )
.await?;
Ok(deno_core::ModuleSource {
// Real module name, might be different from initial specifier
@@ -395,6 +407,7 @@ impl State {
seeded_rng,
target_lib: TargetLib::Main,
debug_type,
+ is_main: true,
}));
Ok(Self(state))
@@ -430,6 +443,7 @@ impl State {
seeded_rng,
target_lib: TargetLib::Worker,
debug_type: DebugType::Dependent,
+ is_main: false,
}));
Ok(Self(state))