Repository: denoland/deno
File: runtime/permissions/lib.rs (Rust)

Code before:
  pub ffi: UnaryPermission<FfiQueryDescriptor>,
  pub import: UnaryPermission<ImportDescriptor>,
  pub all: UnitPermission,
  pub unstable_subdomain_wildcards: bool,
}

#[derive(Clone, Debug, Eq, PartialEq, Default, Serialize, Deserialize)]
pub struct PermissionsOptions {
  pub allow_all: bool,
  pub allow_env: Option<Vec<String>>,
  pub deny_env: Option<Vec<String>>,
  pub allow_net: Option<Vec<String>>,
  pub deny_net: Option<Vec<String>>,
  pub allow_ffi: Option<Vec<String>>,
  pub deny_ffi: Option<Vec<String>>,
  pub allow_read: Option<Vec<String>>,
  pub deny_read: Option<Vec<String>>,
  pub allow_run: Option<Vec<String>>,
  pub deny_run: Option<Vec<String>>,
  pub allow_sys: Option<Vec<String>>,
  pub deny_sys: Option<Vec<String>>,
  pub allow_write: Option<Vec<String>>,
  pub deny_write: Option<Vec<String>>,
  pub allow_import: Option<Vec<String>>,
  pub prompt: bool,
  pub unstable_subdomain_wildcards: bool,
}

#[derive(Debug, thiserror::Error)]
pub enum PermissionsFromOptionsError {
  #[error("{0}")]
  PathResolve(#[from] PathResolveError),
  #[error("{0}")]
  SysDescriptorParse(#[from] SysDescriptorParseError),
  #[error("{0}")]
  NetDescriptorParse(#[from] NetDescriptorParseError),
  #[error("{0}")]
  EnvDescriptorParse(#[from] EnvDescriptorParseError),
  #[error("{0}")]
  RunDescriptorParse(#[from] RunDescriptorParseError),
  #[error("Empty command name not allowed in --allow-run=...")]
  RunEmptyCommandName,
}

impl Permissions {
  pub fn new_unary<TQuery>(
    allow_list: Option<HashSet<TQuery::AllowDesc>>,
    deny_list: Option<HashSet<TQuery::DenyDesc>>,
    prompt: bool,
  ) -> UnaryPermission<TQuery>
  where

Review comment (security):
Instead of this being here and on `Permissions`. I think it should be a constructor parameter to `RuntimePermissionDescriptorParser`? That way the value isn't being passed around horizontally through the code.

Code after:
}

#[derive(Clone, Debug, Eq, PartialEq, Default, Serialize, Deserialize)]
pub struct PermissionsOptions {
  pub allow_all: bool,
  pub allow_env: Option<Vec<String>>,
  pub deny_env: Option<Vec<String>>,
  pub allow_net: Option<Vec<String>>,
  pub deny_net: Option<Vec<String>>,
  pub allow_ffi: Option<Vec<String>>,
  pub deny_ffi: Option<Vec<String>>,
  pub allow_read: Option<Vec<String>>,
  pub deny_read: Option<Vec<String>>,
  pub allow_run: Option<Vec<String>>,
  pub deny_run: Option<Vec<String>>,
  pub allow_sys: Option<Vec<String>>,
  pub deny_sys: Option<Vec<String>>,
  pub allow_write: Option<Vec<String>>,
  pub deny_write: Option<Vec<String>>,
  pub allow_import: Option<Vec<String>>,
  pub prompt: bool,
}

#[derive(Debug, thiserror::Error)]
pub enum PermissionsFromOptionsError {
  #[error("{0}")]
  PathResolve(#[from] PathResolveError),
  #[error("{0}")]
  SysDescriptorParse(#[from] SysDescriptorParseError),
  #[error("{0}")]
  NetDescriptorParse(#[from] NetDescriptorParseError),
  #[error("{0}")]
  EnvDescriptorParse(#[from] EnvDescriptorParseError),
  #[error("{0}")]
  RunDescriptorParse(#[from] RunDescriptorParseError),
  #[error("Empty command name not allowed in --allow-run=...")]
  RunEmptyCommandName,
}

impl Permissions {
  pub fn new_unary<TQuery>(
    allow_list: Option<HashSet<TQuery::AllowDesc>>,
    deny_list: Option<HashSet<TQuery::DenyDesc>>,
    prompt: bool,
  ) -> UnaryPermission<TQuery>
  where
    TQuery: QueryDescriptor,
  {
    UnaryPermission::<TQuery> {
      granted_global: global_from_option(allow_list.as_ref()),
      granted_list: allow_list.unwrap_or_default(),