Preferences: Revoke removes a script grant outside the automation read roots

With automation read roots in force, script.grants names a script or a
path outside them by its file name alone, and script.grants.revoke
matches that name against the stored full path, so Revoke on such a row
removed nothing and said the access was already revoked.

Script File Access now reads the grants file, which is the app's own,
with no roots in force. Each row keeps its script and path whole for
script.grants.revoke and shows them as script.grants names them to the
request that opened Preferences. ui.inspect, the reply of ui.dialog.set
and the Reset Preferences question over the dialog name them the same
way and leave out the whole values; ui.dialog.set's reply also leaves
out the folder preferences outside the read roots, as ui.inspect does.
This commit is contained in:
dotCooCoo committed 2026-11-21 21:25:20 -08:00
1 parent 6445fd1700
commit b9070d0013
5 files changed
+123 -16

No files matched your search

+24 -7
View File
@@ -1152,7 +1152,8 @@ fn leave_out_unreadable_values(v: &mut Value, place: ParamsPlace) {
/// Takes out of `ui.inspect`'s copy of the UI state the paths the request may not read: recent files,
/// a library panel's file, folder preferences (saved, and in an open Preferences dialog) and the paths
/// in recorded actions' steps and in the item an open Insert Menu Item dialog picked, outside the
/// read root. The file selected in an open JavaScript Files dialog is named as `svgInteractivity.info`
/// read root. An open Preferences dialog's kept script file access names its scripts and paths as
/// `script.grants` does. The file selected in an open JavaScript Files dialog is named as `svgInteractivity.info`
/// names the active document's linked files. The UI state itself is not changed.
fn leave_out_unreadable_paths(app: &VectorcraftApp, ui: &mut serde_json::Map<String, Value>) {
if let Some(Value::Array(files)) = ui.get_mut("recent_files") {
@@ -1171,11 +1172,8 @@ fn leave_out_unreadable_paths(app: &VectorcraftApp, ui: &mut serde_json::Map<Str
if let Some(Value::Object(prefs)) = ui.get_mut("engine_prefs") {
leave_out_unreadable_folders(prefs);
}
if let Some(Value::Object(dialog)) = ui.get_mut("dialog")
&& dialog.get("kind").and_then(Value::as_str) == Some("preferences")
&& let Some(Value::Object(fields)) = dialog.get_mut("fields")
{
leave_out_unreadable_folders(fields);
if let Some(Value::Object(dialog)) = ui.get_mut("dialog") {
leave_out_unreadable_preferences(dialog);
}
// The menu item picked in an open Insert Menu Item dialog, such as a saved proof setup's file.
if let Some(Value::Object(dialog)) = ui.get_mut("dialog")
@@ -1197,6 +1195,22 @@ fn leave_out_unreadable_paths(app: &VectorcraftApp, ui: &mut serde_json::Map<Str
}
}
/// Takes out of a copy of an open Preferences dialog `dialog` the folder preferences the request may
/// not read, and names its kept script file access as `script.grants` does (`ui.inspect` and
/// `ui.dialog.set`'s reply), also where a dialog over it (Reset Preferences) holds it to show again.
/// Another dialog is left as it is.
fn leave_out_unreadable_preferences(dialog: &mut serde_json::Map<String, Value>) {
let preferences = dialog.get("kind").and_then(Value::as_str) == Some("preferences");
let Some(Value::Object(fields)) = dialog.get_mut("fields") else { return };
if preferences {
leave_out_unreadable_folders(fields);
crate::prefs_dialog::script_access::list_as_listed(fields);
}
if let Some(Value::Object(parent)) = fields.get_mut(crate::dialogs::PARENT) {
leave_out_unreadable_preferences(parent);
}
}
/// Takes out of `prefs` the folder preferences
/// ([`vectorcraft_engine::cmd::prefscmds::FOLDER_PREFS`]) the request may not read ([`shows_folder`]).
fn leave_out_unreadable_folders(prefs: &mut serde_json::Map<String, Value>) {
@@ -1639,7 +1653,10 @@ fn dispatch(app: &mut VectorcraftApp, ctx: &egui::Context, req: &ControlRequest)
return err(e);
}
}
let dialog = app.ui.dialog.as_ref().and_then(|d| serde_json::to_value(d).ok()).unwrap_or_default();
let mut dialog = app.ui.dialog.as_ref().and_then(|d| serde_json::to_value(d).ok()).unwrap_or_default();
if let Value::Object(shown) = &mut dialog {
leave_out_unreadable_preferences(shown);
}
// `action` answers the dialog the fields were just set in, within this request.
match action {
None => ok(dialog),
+1 -1
View File
@@ -13,7 +13,7 @@ use crate::theme::{self, Accent, Brightness, Scheme, Tokens};
use crate::{VectorcraftApp, widgets};
mod descriptions;
mod script_access;
pub(crate) mod script_access;
/// UI-only fields shown in the dialog (backed by `UiState`, not engine prefs).
pub const UI_FIELDS: &[(&str, &str, &str)] = &[
@@ -27,12 +27,27 @@ const ROW_HEIGHT: f32 = 30.0;
/// The list's height before it scrolls.
const LIST_HEIGHT: f32 = 180.0;
/// The keys of a row that hold its script and path as it shows them, each with the key that holds
/// it whole.
const WHOLE: [(&str, &str); 2] = [("script", "wholeScript"), ("path", "wholePath")];
/// The kept grants (`script.grants`) as the rows of the field [`ROWS`] in the Preferences dialog's
/// `fields`. Where the session keeps no grants, the field is removed.
/// `fields`. Where the session keeps no grants, the field is removed. The grants file is the app's
/// own, so it is read with no automation roots in force: each row keeps its script and path whole
/// (`wholeScript` and `wholePath`) for `script.grants.revoke`, and shows them (`script` and `path`)
/// as `script.grants` names them to the request that opened the dialog ([`as_listed`]).
pub(super) fn load(app: &mut VectorcraftApp, fields: &mut Map<String, Value>) {
match app.session.execute("script.grants", &json!({})) {
match vectorcraft_engine::file_access::unconfined(|| app.session.execute("script.grants", &json!({}))) {
Ok(v) if !v["file"].is_null() => {
fields.insert(ROWS.into(), Value::Array(rows(&v["grants"])));
let mut rows = rows(&v["grants"]);
for row in rows.iter_mut().filter_map(Value::as_object_mut) {
for (shown, whole) in WHOLE {
let Some(path) = row.get(shown).and_then(Value::as_str).map(str::to_string) else { continue };
row.insert(shown.into(), json!(as_listed(&path)));
row.insert(whole.into(), json!(path));
}
}
fields.insert(ROWS.into(), Value::Array(rows));
}
_ => {
fields.remove(ROWS);
@@ -77,6 +92,29 @@ pub(super) fn shown(path: &str) -> String {
permissions::display_text(path, MAX_SHOWN_PATH)
}
/// A kept script or path as `script.grants` names it to the request being served: whole where that
/// request may read it, else its file name alone (empty for a path that ends in no name).
pub(crate) fn as_listed(path: &str) -> &str {
if vectorcraft_engine::file_access::check_read(path).is_ok() {
return path;
}
let name = path.rsplit(vectorcraft_doc::links::path_separators(path)).next().unwrap_or_default();
if matches!(name, "." | "..") { "" } else { name }
}
/// The rows of `ROWS` in a copy of the Preferences dialog's `fields` (`ui.inspect` and
/// `ui.dialog.set`'s reply) with each script and path as [`as_listed`] gives it to the request being
/// served, and without the whole ones.
pub(crate) fn list_as_listed(fields: &mut Map<String, Value>) {
for row in fields.get_mut(ROWS).and_then(Value::as_array_mut).into_iter().flatten().filter_map(Value::as_object_mut) {
for (shown, whole) in WHOLE {
if let Some(path) = row.remove(whole).as_ref().and_then(Value::as_str) {
row.insert(shown.into(), json!(as_listed(path)));
}
}
}
}
/// The label of a row's access.
fn access_label(access: &str) -> &'static str {
match access {
@@ -106,7 +144,7 @@ pub(super) fn show(ui: &mut egui::Ui, app: &mut VectorcraftApp, d: &mut Dialog)
}
let mut lines = Vec::with_capacity(rows.len() * 2);
for (i, row) in rows.iter().enumerate() {
if i == 0 || rows[i - 1]["script"] != row["script"] {
if i == 0 || rows[i - 1]["wholeScript"] != row["wholeScript"] {
lines.push(Line::Script(i));
}
lines.push(Line::Row(i));
@@ -178,13 +216,13 @@ pub(super) fn show(ui: &mut egui::Ui, app: &mut VectorcraftApp, d: &mut Dialog)
}
}
/// Revoke on the row `i` of the Preferences dialog `d`: every kept grant of its script and path is
/// removed (`script.grants.revoke`), the rows are read again and the row now at `i`, or the last
/// Revoke on the row `i` of the Preferences dialog `d`: every kept grant of its script and path,
/// whole, is removed (`script.grants.revoke`), the rows are read again and the row now at `i`, or the last
/// row, takes the keyboard focus. The status bar says what happened; on an error the rows stay as
/// they were.
pub(super) fn revoke(app: &mut VectorcraftApp, d: &mut Dialog, i: usize) {
let Some(row) = d.fields.get(ROWS).and_then(|rows| rows.get(i)).cloned() else { return };
match app.run("script.grants.revoke", json!({"script": row["script"], "path": row["path"]})) {
match app.run("script.grants.revoke", json!({"script": row["wholeScript"], "path": row["wholePath"]})) {
Ok(v) => {
load(app, &mut d.fields);
let left = d.fields.get(ROWS).and_then(Value::as_array).map_or(0, Vec::len);
+52
View File
@@ -3129,6 +3129,58 @@ fn script_file_access_shows_none_and_a_revoke_of_a_removed_row() {
assert!(!text.contains("No script has kept file access."), "{text}");
}
/// Preferences opened with a read root in force shows a script and a path outside it by their file
/// names alone, as `script.grants` lists them, and `ui.inspect`, `ui.dialog.set`'s reply and the
/// Reset Preferences question over the dialog name them the same way; Revoke still removes that
/// pair's kept grants, both with the root in force and without it.
#[test]
fn script_file_access_revokes_a_pair_outside_the_read_roots() {
let dir = std::env::temp_dir().join("vc-ui-prefs-grants-nowhere");
let (script, path) = (dir.join("a.jsx"), dir.join("out.txt"));
let root = temp_folder("grants-root-in");
let roots = vectorcraft_engine::file_access::AutomationRoots::new(&[root.as_path()], &[]).unwrap();
for confined in [true, false] {
let (mut a, store) = app_with_grants("grants-outside-roots", json!([grant(&script, &path, "1", false, false)]));
let (shown, inspected, set, under) = vectorcraft_engine::file_access::confine(roots.as_ref(), || {
open(&mut a, Some("General"));
let shown = access_rows(&a);
let ctx = egui::Context::default();
let inspected = crate::control::inspect(&a, &ctx);
let (req, _) = crate::control::ControlRequest::new("ui.dialog.set", json!({"field": "unitsGeneral", "value": "points"}));
let crate::control::Outcome::Done(set) = crate::control::handle(&mut a, &ctx, &req) else { panic!("expected an immediate reply") };
let kept = a.ui.dialog.clone();
crate::dialogs::confirm::ask_reset_prefs(&mut a);
let under = crate::control::inspect(&a, &ctx);
a.ui.dialog = kept;
(shown, inspected, set, under)
});
assert_eq!(shown, [("a.jsx".to_string(), "out.txt".to_string(), "read".to_string(), 1)]);
// The person's frame draws the rows as the request that opened the dialog was shown them.
let texts = script_access_in_view(&mut a, &fonts_context(), "out.txt");
let whole = dir.to_string_lossy();
assert!(texts.iter().any(|(t, _)| t == "a.jsx") && !texts.iter().any(|(t, _)| t.contains(&*whole)), "{texts:?}");
let listed = json!({"script": "a.jsx", "path": "out.txt"});
for (reply, row) in [
(&inspected, &inspected["ui"]["dialog"]["fields"][script_access::ROWS][0]),
(&set, &set["result"]["fields"][script_access::ROWS][0]),
(&under, &under["ui"]["dialog"]["fields"][crate::dialogs::PARENT]["fields"][script_access::ROWS][0]),
] {
assert_eq!(json!({"script": row["script"], "path": row["path"]}), listed, "{reply}");
assert!(row["wholeScript"].is_null() && row["wholePath"].is_null(), "{reply}");
}
let mut d = a.ui.dialog.clone().unwrap();
let roots_now = if confined { roots.as_ref() } else { None };
vectorcraft_engine::file_access::confine(roots_now, || script_access::revoke(&mut a, &mut d, 0));
a.ui.dialog = Some(d);
assert_eq!(a.ui.status, "Script file access revoked", "confined: {confined}");
assert!(access_rows(&a).is_empty(), "confined: {confined}");
let stored: Value = serde_json::from_slice(&std::fs::read(&store).unwrap()).unwrap();
assert!(stored["grants"].as_array().is_some_and(Vec::is_empty), "confined: {confined}: {stored}");
let _ = std::fs::remove_dir_all(store.parent().unwrap());
}
let _ = std::fs::remove_dir_all(&root);
}
/// A grants file that is not well formed or is larger than may be read is refused: Revoke shows
/// the error, grants nothing and leaves the file and the rows as they were.
#[test]
+1 -1
View File
@@ -1041,7 +1041,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- Scripts: `$.line` is the line of the running script, counting from 1, and `$.stack` is the current stack trace ([the help page](https://extendscript.docsforadobe.dev/extendscript-tools-features/dollar-object/)). VectorCraft's own rules: both count lines in the file the code is in (the script, a file it included, a file `$.evalFile` ran, or the file of an earlier run of the named engine), and `$.stack` writes each frame as `name@file:line`, outermost first; code that `eval` or `Function` compiled keeps its own line in `[eval]`, and code whose place the engine no longer keeps is at line 0 of `[unknown]`. `crates/engine/src/tests/script_include.rs`, `crates/engine/src/tests/script_engines.rs`, `crates/js/src/extension_tests.rs`.
- Scripts: `File` and `Folder` ([File object](https://extendscript.docsforadobe.dev/file-system-access/file-object/), [Folder object](https://extendscript.docsforadobe.dev/file-system-access/folder-object/)) name files and folders by platform or URI path, with `name`, `fsName`, `absoluteURI`, `relativeURI`, `parent`, `Folder.current` and `encode`/`decode`, and read them: `exists`, `length`, the dates, `getFiles` with a mask or a function, and `open('r')` with `read`, `readln`, `readch`, `seek`, `tell` and `close`, decoding by byte order mark, `encoding`, UTF-8 or CP1252. VectorCraft's own rules: a script reads only in its own folder and below (and inside the automation read roots when they are set); any other path and a network or device path are refused before anything is looked up, and a link that leads out is refused as well (`false` or `null`, with `error` set); a file is read whole up to 8 MiB and a run reads up to 32 MiB; `execute` is not available. `crates/engine/src/tests/script_io.rs`.
- Scripts: `File` and `Folder` write ([File object](https://extendscript.docsforadobe.dev/file-system-access/file-object/), [Folder object](https://extendscript.docsforadobe.dev/file-system-access/folder-object/)): `open('w')`, `open('e')` and `open('a')` with `write` and `writeln` by `lineFeed`, `copy`, `remove` (a folder only when empty), `rename`, `folder.create()`, the `length` and `readonly` setters, and `File.openDialog`, `File.saveDialog`, `Folder.selectDialog`, `openDlg`, `saveDlg` and `selectDlg`, with a `filter` of file types or a filter function and `multiSelect`. VectorCraft's own rules: a script writes only in `Folder.temp` (one for the run, deleted when it ends), its own `Folder.userData` next to the settings, and what a person allowed it in a file dialog, once or always; Always keeps the grant for that script file with that text by its SHA-256 and for the sources the run evaluated (`$.evalFile`, `eval`, `Function`), so a run that evaluates other code, or whose named engine holds other code, loses it first; `script.grants` lists the grants and `script.grants.revoke` removes them; the settings folder is kept out of every grant; the commands a script runs with `vc.run` read and write only in the same places and the open documents' own files; a run with nobody to ask gets `null` from the dialogs; a file is written at close or when the run ends, 8 MiB a file and 32 MiB a run, and named in `written`, also after a run that failed. `crates/engine/src/tests/script_io.rs`.
- Scripts: Preferences › General › Script File Access lists the file access kept with Always Allow This Script (`script.grants`), one row for each script and path with its widest access (read file, read and write file, or read and write folder), and its Revoke button removes every kept version of that script and path (`script.grants.revoke`), so the next run asks again. Paths show control and bidirectional characters as escapes; a grants file that is not well formed or is over 4 MiB makes Revoke show its error and leaves the file as it was. VectorCraft's own addition. `crates/ui-egui/src/prefs_dialog/tests.rs` (`script_file_access_*`).
- Scripts: Preferences › General › Script File Access lists the file access kept with Always Allow This Script (`script.grants`), one row for each script and path with its widest access (read file, read and write file, or read and write folder), and its Revoke button removes every kept version of that script and path (`script.grants.revoke`), so the next run asks again. Paths show control and bidirectional characters as escapes, and a script or path outside the automation read roots in force when Preferences opens shows by its file name, as `script.grants` lists it, and Revoke still removes it; a grants file that is not well formed or is over 4 MiB makes Revoke show its error and leaves the file as it was. VectorCraft's own addition. `crates/ui-egui/src/prefs_dialog/tests.rs` (`script_file_access_*`).
- Scripts: the `hidden` setter and `createAlias(target)` ([File object](https://extendscript.docsforadobe.dev/file-system-access/file-object/)), with setting `hidden`, `rename` and `remove` acting on an alias itself ([Using File and Folder objects](https://extendscript.docsforadobe.dev/file-system-access/using-file-and-folder-objects/)). VectorCraft's own rules: on Unix a name that starts with a dot is hidden, so setting `hidden` renames the file with one dot added or its leading dots taken off, and both names must be places the script may write; `createAlias` makes a symbolic link to the real path of a file the script may read, in a place it may write where nothing is, a link that leads nowhere included; a link is checked again each time it is used; on Windows both set `error` and change nothing. `crates/engine/src/tests/script_io.rs`.
- Scripts: `#strict on` (and `//@strict on`) runs the script with the checks the [`$` object](https://extendscript.docsforadobe.dev/extendscript-tools-features/dollar-object/) help page gives for `$.strict`: an assignment to a read-only property throws a `TypeError`, and so does a new property on an object that takes none. VectorCraft's own rules: a getter-only property counts as read-only, the objects that take no new properties are the non-extensible ones (`Object.preventExtensions`, `seal`, `freeze`, and the frozen `vc` and `$` objects), the last `#strict` line of the script and its includes sets the whole run, a file `$.evalFile` runs keeps its own line's checks for its code, and the rest of ES5 strict mode stays with `'use strict'`. Without the line, runs are unchanged. `crates/engine/src/tests/script_include.rs` (`strict_on_*`, `strict_mode_in_eval_file_is_scoped`), `crates/js/src/interp_tests.rs` (`strict_writes_are_separate_from_es5_strict`).
- Scripts folder: File › Scripts lists the `.js` and `.jsx` files of the `Scripts` folder next to the preferences, each named after its file without the extension, with each subfolder as a submenu, above Check Script… and Other Script… (https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/automate-actions/install-and-run-scripts.html). VectorCraft's own rules: the folder is read again when the window becomes active and when the File menu opens (in the macOS menu bar, when any of its menus opens, and the new listing shows the next time the menu opens), links are not followed, and one read stops at 2,048 entries, 512 scripts, 128 subfolders, 4 levels or 250 ms. `script.listInstalled` returns the listing. `crates/engine/src/tests/script_folder.rs`, `crates/ui-egui/src/tests/scripts_menu.rs`.