mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-21 11:26:15 +02:00
9cf0390a52
* fix(shell): properly validate open scope * change empty regex to an impossible match --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app> Co-authored-by: Chip Reed <chip@chip.sh>
44 lines
1.5 KiB
Rust
44 lines
1.5 KiB
Rust
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
use serde::Deserialize;
|
|
|
|
/// Configuration for the shell plugin.
|
|
#[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize)]
|
|
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
|
pub struct Config {
|
|
/// Open URL with the user's default application.
|
|
#[serde(default)]
|
|
pub open: ShellAllowlistOpen,
|
|
}
|
|
|
|
/// Defines the `shell > open` api scope.
|
|
#[derive(Debug, PartialEq, Eq, Clone, Deserialize)]
|
|
#[serde(untagged, deny_unknown_fields)]
|
|
#[non_exhaustive]
|
|
pub enum ShellAllowlistOpen {
|
|
/// Shell open API allowlist is not defined by the user.
|
|
/// In this case we add the default validation regex (same as [`Self::Flag(true)`]).
|
|
Unset,
|
|
/// If the shell open API should be enabled.
|
|
///
|
|
/// If enabled, the default validation regex (`^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+`) is used.
|
|
Flag(bool),
|
|
|
|
/// Enable the shell open API, with a custom regex that the opened path must match against.
|
|
///
|
|
/// The regex string is automatically surrounded by `^...$` to match the full string.
|
|
/// For example the `https?://\w+` regex would be registered as `^https?://\w+$`.
|
|
///
|
|
/// If using a custom regex to support a non-http(s) schema, care should be used to prevent values
|
|
/// that allow flag-like strings to pass validation. e.g. `--enable-debugging`, `-i`, `/R`.
|
|
Validate(String),
|
|
}
|
|
|
|
impl Default for ShellAllowlistOpen {
|
|
fn default() -> Self {
|
|
Self::Unset
|
|
}
|
|
}
|