mirror of
https://github.com/tauri-apps/tauri.git
synced 2025-01-03 16:42:42 +03:00
* refactor(tauri) rename `whitelist` to `allowlist`, ref #645 * chore(changes) add changefile
This commit is contained in:
parent
cbd14c3077
commit
a6bb3b5905
5
.changes/refactor-whitelist.md
Normal file
5
.changes/refactor-whitelist.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": minor
|
||||
---
|
||||
|
||||
Renaming `whitelist` to `allowlist` (see #645).
|
@ -41,7 +41,7 @@ const getTauriConfig = (cfg: Partial<TauriConfig>): TauriConfig => {
|
||||
frameworks: []
|
||||
}
|
||||
},
|
||||
whitelist: {
|
||||
allowlist: {
|
||||
all: false
|
||||
},
|
||||
window: {
|
||||
|
@ -84,7 +84,7 @@ class Runner {
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const cargoManifest = this.__getManifest() as any as CargoManifest
|
||||
this.__whitelistApi(cfg, cargoManifest)
|
||||
this.__allowlistApi(cfg, cargoManifest)
|
||||
this.__rewriteManifest(cargoManifest as unknown as toml.JsonMap)
|
||||
|
||||
const runningDevServer = devPath.startsWith('http')
|
||||
@ -248,7 +248,7 @@ class Runner {
|
||||
}
|
||||
|
||||
const cargoManifest = this.__getManifest()
|
||||
this.__whitelistApi(cfg, cargoManifest as unknown as CargoManifest)
|
||||
this.__allowlistApi(cfg, cargoManifest as unknown as CargoManifest)
|
||||
this.__rewriteManifest(cargoManifest)
|
||||
|
||||
const inlinedAssets = (await this.__parseHtml(cfg, cfg.build.distDir)).inlinedAssets
|
||||
@ -507,13 +507,13 @@ class Runner {
|
||||
}, WATCHER_INTERVAL * 2)
|
||||
}
|
||||
|
||||
__whitelistApi(
|
||||
__allowlistApi(
|
||||
cfg: TauriConfig,
|
||||
manifest: CargoManifest
|
||||
): void {
|
||||
const tomlFeatures = []
|
||||
|
||||
if (cfg.tauri.whitelist.all) {
|
||||
if (cfg.tauri.allowlist.all) {
|
||||
tomlFeatures.push('all-api')
|
||||
} else {
|
||||
const toKebabCase = (value: string): string => {
|
||||
@ -521,10 +521,10 @@ class Runner {
|
||||
.replace(/\s+/g, '-')
|
||||
.toLowerCase()
|
||||
}
|
||||
const whitelist = Object.keys(cfg.tauri.whitelist).filter(
|
||||
w => cfg.tauri.whitelist[String(w)]
|
||||
const allowlist = Object.keys(cfg.tauri.allowlist).filter(
|
||||
w => cfg.tauri.allowlist[String(w)]
|
||||
)
|
||||
tomlFeatures.push(...whitelist.map(toKebabCase))
|
||||
tomlFeatures.push(...allowlist.map(toKebabCase))
|
||||
}
|
||||
|
||||
if (cfg.tauri.cli) {
|
||||
|
@ -32,7 +32,7 @@ export default {
|
||||
},
|
||||
exceptionDomain: ''
|
||||
},
|
||||
whitelist: {
|
||||
allowlist: {
|
||||
all: true
|
||||
},
|
||||
window: {
|
||||
|
@ -277,6 +277,22 @@
|
||||
],
|
||||
"description": "tauri root configuration object",
|
||||
"properties": {
|
||||
"allowlist": {
|
||||
"additionalProperties": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"defaultProperties": [
|
||||
],
|
||||
"properties": {
|
||||
"all": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"all"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"bundle": {
|
||||
"additionalProperties": false,
|
||||
"defaultProperties": [
|
||||
@ -440,22 +456,6 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"whitelist": {
|
||||
"additionalProperties": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"defaultProperties": [
|
||||
],
|
||||
"properties": {
|
||||
"all": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"all"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"window": {
|
||||
"additionalProperties": false,
|
||||
"defaultProperties": [
|
||||
@ -484,11 +484,11 @@
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"allowlist",
|
||||
"bundle",
|
||||
"embeddedServer",
|
||||
"inliner",
|
||||
"security",
|
||||
"whitelist",
|
||||
"window"
|
||||
],
|
||||
"type": "object"
|
||||
|
@ -271,7 +271,7 @@ export interface TauriConfig {
|
||||
}
|
||||
exceptionDomain?: string
|
||||
}
|
||||
whitelist: {
|
||||
allowlist: {
|
||||
all: boolean
|
||||
[index: string]: boolean
|
||||
}
|
||||
|
@ -287,6 +287,22 @@ export const TauriConfigSchema = {
|
||||
],
|
||||
"description": "tauri root configuration object",
|
||||
"properties": {
|
||||
"allowlist": {
|
||||
"additionalProperties": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"defaultProperties": [
|
||||
],
|
||||
"properties": {
|
||||
"all": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"all"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"bundle": {
|
||||
"additionalProperties": false,
|
||||
"defaultProperties": [
|
||||
@ -450,22 +466,6 @@ export const TauriConfigSchema = {
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"whitelist": {
|
||||
"additionalProperties": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"defaultProperties": [
|
||||
],
|
||||
"properties": {
|
||||
"all": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"all"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"window": {
|
||||
"additionalProperties": false,
|
||||
"defaultProperties": [
|
||||
@ -494,11 +494,11 @@ export const TauriConfigSchema = {
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"allowlist",
|
||||
"bundle",
|
||||
"embeddedServer",
|
||||
"inliner",
|
||||
"security",
|
||||
"whitelist",
|
||||
"window"
|
||||
],
|
||||
"type": "object"
|
||||
|
@ -4,7 +4,7 @@
|
||||
"distDir": "../dist"
|
||||
},
|
||||
"tauri": {
|
||||
"whitelist": {
|
||||
"allowlist": {
|
||||
"all": true
|
||||
},
|
||||
"bundle": {
|
||||
@ -15,4 +15,4 @@
|
||||
"title": "Fixture"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@
|
||||
"icons/32x32.png", "icons/128x128.png", "icons/128x128@2x.png", "icons/icon.icns", "icons/icon.ico"
|
||||
]
|
||||
},
|
||||
"whitelist": {
|
||||
"allowlist": {
|
||||
"all": true
|
||||
},
|
||||
"window": {
|
||||
|
@ -33,7 +33,7 @@ pub(crate) fn handle(webview: &mut Webview, arg: &str) -> crate::Result<()> {
|
||||
#[cfg(read_text_file)]
|
||||
file_system::read_text_file(webview, path, options, callback, error);
|
||||
#[cfg(not(read_text_file))]
|
||||
whitelist_error(webview, error, "readTextFile");
|
||||
allowlist_error(webview, error, "readTextFile");
|
||||
}
|
||||
ReadBinaryFile {
|
||||
path,
|
||||
@ -44,7 +44,7 @@ pub(crate) fn handle(webview: &mut Webview, arg: &str) -> crate::Result<()> {
|
||||
#[cfg(read_binary_file)]
|
||||
file_system::read_binary_file(webview, path, options, callback, error);
|
||||
#[cfg(not(read_binary_file))]
|
||||
whitelist_error(webview, error, "readBinaryFile");
|
||||
allowlist_error(webview, error, "readBinaryFile");
|
||||
}
|
||||
WriteFile {
|
||||
path,
|
||||
@ -56,7 +56,7 @@ pub(crate) fn handle(webview: &mut Webview, arg: &str) -> crate::Result<()> {
|
||||
#[cfg(write_file)]
|
||||
file_system::write_file(webview, path, contents, options, callback, error);
|
||||
#[cfg(not(write_file))]
|
||||
whitelist_error(webview, error, "writeFile");
|
||||
allowlist_error(webview, error, "writeFile");
|
||||
}
|
||||
WriteBinaryFile {
|
||||
path,
|
||||
@ -68,7 +68,7 @@ pub(crate) fn handle(webview: &mut Webview, arg: &str) -> crate::Result<()> {
|
||||
#[cfg(write_binary_file)]
|
||||
file_system::write_binary_file(webview, path, contents, options, callback, error);
|
||||
#[cfg(not(write_binary_file))]
|
||||
whitelist_error(webview, error, "writeBinaryFile");
|
||||
allowlist_error(webview, error, "writeBinaryFile");
|
||||
}
|
||||
ReadDir {
|
||||
path,
|
||||
@ -79,7 +79,7 @@ pub(crate) fn handle(webview: &mut Webview, arg: &str) -> crate::Result<()> {
|
||||
#[cfg(read_dir)]
|
||||
file_system::read_dir(webview, path, options, callback, error);
|
||||
#[cfg(not(read_dir))]
|
||||
whitelist_error(webview, error, "readDir");
|
||||
allowlist_error(webview, error, "readDir");
|
||||
}
|
||||
CopyFile {
|
||||
source,
|
||||
@ -91,7 +91,7 @@ pub(crate) fn handle(webview: &mut Webview, arg: &str) -> crate::Result<()> {
|
||||
#[cfg(copy_file)]
|
||||
file_system::copy_file(webview, source, destination, options, callback, error);
|
||||
#[cfg(not(copy_file))]
|
||||
whitelist_error(webview, error, "copyFile");
|
||||
allowlist_error(webview, error, "copyFile");
|
||||
}
|
||||
CreateDir {
|
||||
path,
|
||||
@ -102,7 +102,7 @@ pub(crate) fn handle(webview: &mut Webview, arg: &str) -> crate::Result<()> {
|
||||
#[cfg(create_dir)]
|
||||
file_system::create_dir(webview, path, options, callback, error);
|
||||
#[cfg(not(create_dir))]
|
||||
whitelist_error(webview, error, "createDir");
|
||||
allowlist_error(webview, error, "createDir");
|
||||
}
|
||||
RemoveDir {
|
||||
path,
|
||||
@ -113,7 +113,7 @@ pub(crate) fn handle(webview: &mut Webview, arg: &str) -> crate::Result<()> {
|
||||
#[cfg(remove_dir)]
|
||||
file_system::remove_dir(webview, path, options, callback, error);
|
||||
#[cfg(not(remove_dir))]
|
||||
whitelist_error(webview, error, "removeDir");
|
||||
allowlist_error(webview, error, "removeDir");
|
||||
}
|
||||
RemoveFile {
|
||||
path,
|
||||
@ -124,7 +124,7 @@ pub(crate) fn handle(webview: &mut Webview, arg: &str) -> crate::Result<()> {
|
||||
#[cfg(remove_file)]
|
||||
file_system::remove_file(webview, path, options, callback, error);
|
||||
#[cfg(not(remove_file))]
|
||||
whitelist_error(webview, error, "removeFile");
|
||||
allowlist_error(webview, error, "removeFile");
|
||||
}
|
||||
RenameFile {
|
||||
old_path,
|
||||
@ -136,13 +136,13 @@ pub(crate) fn handle(webview: &mut Webview, arg: &str) -> crate::Result<()> {
|
||||
#[cfg(rename_file)]
|
||||
file_system::rename_file(webview, old_path, new_path, options, callback, error);
|
||||
#[cfg(not(rename_file))]
|
||||
whitelist_error(webview, error, "renameFile");
|
||||
allowlist_error(webview, error, "renameFile");
|
||||
}
|
||||
SetTitle { title } => {
|
||||
#[cfg(set_title)]
|
||||
webview.set_title(&title);
|
||||
#[cfg(not(set_title))]
|
||||
throw_whitelist_error(webview, "title");
|
||||
throw_allowlist_error(webview, "title");
|
||||
}
|
||||
Execute {
|
||||
command,
|
||||
@ -153,13 +153,13 @@ pub(crate) fn handle(webview: &mut Webview, arg: &str) -> crate::Result<()> {
|
||||
#[cfg(execute)]
|
||||
crate::call(webview, command, args, callback, error);
|
||||
#[cfg(not(execute))]
|
||||
throw_whitelist_error(webview, "execute");
|
||||
throw_allowlist_error(webview, "execute");
|
||||
}
|
||||
Open { uri } => {
|
||||
#[cfg(open)]
|
||||
browser::open(uri);
|
||||
#[cfg(not(open))]
|
||||
throw_whitelist_error(webview, "open");
|
||||
throw_allowlist_error(webview, "open");
|
||||
}
|
||||
ValidateSalt {
|
||||
salt,
|
||||
@ -179,13 +179,13 @@ pub(crate) fn handle(webview: &mut Webview, arg: &str) -> crate::Result<()> {
|
||||
webview.eval(&js_string);
|
||||
}
|
||||
#[cfg(not(event))]
|
||||
throw_whitelist_error(webview, "event");
|
||||
throw_allowlist_error(webview, "event");
|
||||
}
|
||||
Emit { event, payload } => {
|
||||
#[cfg(event)]
|
||||
crate::event::on_event(event, payload);
|
||||
#[cfg(not(event))]
|
||||
throw_whitelist_error(webview, "event");
|
||||
throw_allowlist_error(webview, "event");
|
||||
}
|
||||
OpenDialog {
|
||||
options,
|
||||
@ -195,7 +195,7 @@ pub(crate) fn handle(webview: &mut Webview, arg: &str) -> crate::Result<()> {
|
||||
#[cfg(open_dialog)]
|
||||
dialog::open(webview, options, callback, error)?;
|
||||
#[cfg(not(open_dialog))]
|
||||
whitelist_error(webview, error, "title");
|
||||
allowlist_error(webview, error, "title");
|
||||
}
|
||||
SaveDialog {
|
||||
options,
|
||||
@ -205,7 +205,7 @@ pub(crate) fn handle(webview: &mut Webview, arg: &str) -> crate::Result<()> {
|
||||
#[cfg(save_dialog)]
|
||||
dialog::save(webview, options, callback, error)?;
|
||||
#[cfg(not(save_dialog))]
|
||||
throw_whitelist_error(webview, "saveDialog");
|
||||
throw_allowlist_error(webview, "saveDialog");
|
||||
}
|
||||
MessageDialog { message } => {
|
||||
let exe = std::env::current_exe()?;
|
||||
@ -246,7 +246,7 @@ pub(crate) fn handle(webview: &mut Webview, arg: &str) -> crate::Result<()> {
|
||||
#[cfg(http_request)]
|
||||
http::make_request(webview, *options, callback, error);
|
||||
#[cfg(not(http_request))]
|
||||
whitelist_error(webview, error, "httpRequest");
|
||||
allowlist_error(webview, error, "httpRequest");
|
||||
}
|
||||
#[cfg(assets)]
|
||||
LoadAsset {
|
||||
@ -272,7 +272,7 @@ pub(crate) fn handle(webview: &mut Webview, arg: &str) -> crate::Result<()> {
|
||||
api_error(
|
||||
webview,
|
||||
error,
|
||||
"CLI definition not set under tauri.conf.json > tauri > cli (https://tauri.studio/docs/api/config#tauri)",
|
||||
"CLI definition not set under tauri.conf.json > tauri > cli (https://tauri.studio/docs/api/config#tauri.cli)",
|
||||
);
|
||||
}
|
||||
Notification {
|
||||
@ -283,19 +283,19 @@ pub(crate) fn handle(webview: &mut Webview, arg: &str) -> crate::Result<()> {
|
||||
#[cfg(notification)]
|
||||
notification::send(webview, options, callback, error);
|
||||
#[cfg(not(notification))]
|
||||
whitelist_error(webview, error, "notification");
|
||||
allowlist_error(webview, error, "notification");
|
||||
}
|
||||
IsNotificationPermissionGranted { callback, error } => {
|
||||
#[cfg(notification)]
|
||||
notification::is_permission_granted(webview, callback, error);
|
||||
#[cfg(not(notification))]
|
||||
whitelist_error(webview, error, "notification");
|
||||
allowlist_error(webview, error, "notification");
|
||||
}
|
||||
RequestNotificationPermission { callback, error } => {
|
||||
#[cfg(notification)]
|
||||
notification::request_permission(webview, callback, error)?;
|
||||
#[cfg(not(notification))]
|
||||
whitelist_error(webview, error, "notification");
|
||||
allowlist_error(webview, error, "notification");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@ -310,20 +310,23 @@ fn api_error(webview: &mut Webview, error_fn: String, message: &str) {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn whitelist_error(webview: &mut Webview, error_fn: String, whitelist_key: &str) {
|
||||
fn allowlist_error(webview: &mut Webview, error_fn: String, allowlist_key: &str) {
|
||||
api_error(
|
||||
webview,
|
||||
error_fn,
|
||||
&format!(
|
||||
"{}' not whitelisted (https://tauri.studio/docs/api/config#tauri)",
|
||||
whitelist_key
|
||||
"{}' not on the allowlist (https://tauri.studio/docs/api/config#tauri.allowlist)",
|
||||
allowlist_key
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn throw_whitelist_error(webview: &mut Webview, whitelist_key: &str) {
|
||||
let reject_code = format!(r#"throw new Error("'{}' not whitelisted")"#, whitelist_key);
|
||||
fn throw_allowlist_error(webview: &mut Webview, allowlist_key: &str) {
|
||||
let reject_code = format!(
|
||||
r#"throw new Error("'{}' not on the allowlist")"#,
|
||||
allowlist_key
|
||||
);
|
||||
webview.eval(&reject_code)
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
"bundle": {
|
||||
"active": true
|
||||
},
|
||||
"whitelist": {
|
||||
"allowlist": {
|
||||
"all": true
|
||||
},
|
||||
"window": {
|
||||
|
Loading…
Reference in New Issue
Block a user