From 2c982e4226477a2201daea52e4992e8479ac04d8 Mon Sep 17 00:00:00 2001 From: "smart-ssh-coder[bot]" <338317697+smart-ssh-coder[bot]@users.noreply.github.com> Date: Fri, 27 Nov 2026 12:09:43 +0000 Subject: [PATCH] fix(app): open dotfile edit copies locally on macOS and Linux (#1608) * fix(app): allow opening dotfile edit copies locally (#1607) Co-Authored-By: Claude Sonnet 5.5 * test(app): allow unwrap in opener scope test (#1607) Co-Authored-By: Claude Sonnet 5.5 * test(app): run the opener scope test on Unix only (#1607) The Windows test binary linked tauri's webview and aborted at load. Co-Authored-By: Claude Sonnet 5.5 --------- Co-authored-by: smart-ssh-coder[bot] <338317697+smart-ssh-coder[bot]@users.noreply.github.com> Co-authored-by: Claude Sonnet 5.5 --- apps/smart-ssh-community/Cargo.toml | 9 ++ apps/smart-ssh-community/tauri.conf.json | 5 + .../tests/opener_dotfile_scope.rs | 112 ++++++++++++++++++ .../issue-1607-open-locally-dotfiles.md | 2 + docs/specs/0054-sftp-browser-actions.md | 8 ++ 5 files changed, 136 insertions(+) create mode 100644 apps/smart-ssh-community/tests/opener_dotfile_scope.rs create mode 100644 changelog.d/issue-1607-open-locally-dotfiles.md diff --git a/apps/smart-ssh-community/Cargo.toml b/apps/smart-ssh-community/Cargo.toml index 5932b1d8f..edb36bd0e 100644 --- a/apps/smart-ssh-community/Cargo.toml +++ b/apps/smart-ssh-community/Cargo.toml @@ -26,6 +26,9 @@ tauri-build = { version = "2", features = [] } [dependencies] app-shell = { workspace = true } tauri = { workspace = true } +# Issue #1607: `generate_context!` expands to `serde_json::json!` once +# `tauri.conf.json` has a `plugins` section. +serde_json = { workspace = true } # `tauri-build`'s ACL-/Capability-Auflösung (in `build.rs`, läuft für dieses # Binary-Crate) scannt nur die eigenen, direkten Abhängigkeiten dieser # Crate nach Plugin-Berechtigungen — eine rein transitive Abhängigkeit über @@ -59,6 +62,12 @@ tauri-plugin-android-host = { workspace = true } # Dieselbe Fassung, die `app-shell` ohnehin nutzt, keine neue Crate im Baum. serde_json = { workspace = true } toml = { workspace = true } +# Issue #1607: `tests/opener_dotfile_scope.rs` builds a `tauri::fs::Scope` +# against the mock runtime. Unix only: the literal-leading-dot rule exists only +# there, and a Windows test binary linking tauri's webview needs an app +# manifest and aborts at load (0xc0000139). +[target.'cfg(unix)'.dev-dependencies] +tauri = { workspace = true, features = ["test"] } [lints] workspace = true diff --git a/apps/smart-ssh-community/tauri.conf.json b/apps/smart-ssh-community/tauri.conf.json index 8909f0486..d8f173cb9 100644 --- a/apps/smart-ssh-community/tauri.conf.json +++ b/apps/smart-ssh-community/tauri.conf.json @@ -34,6 +34,11 @@ "csp": "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline' tauri-plugin-decoration: http://tauri-plugin-decoration.localhost https://tauri-plugin-decoration.localhost; img-src 'self' data:; connect-src 'self' ipc:;" } }, + "plugins": { + "opener": { + "requireLiteralLeadingDot": false + } + }, "bundle": { "license": "GPL-3.0-only", "android": { diff --git a/apps/smart-ssh-community/tests/opener_dotfile_scope.rs b/apps/smart-ssh-community/tests/opener_dotfile_scope.rs new file mode 100644 index 000000000..ad7fcfced --- /dev/null +++ b/apps/smart-ssh-community/tests/opener_dotfile_scope.rs @@ -0,0 +1,112 @@ +//! Issue #1607: "Open locally" must work for dotfile edit copies +//! (`.env.local`). The opener plugin builds a `tauri::fs::Scope` whose +//! `require_literal_leading_dot` defaults to `true` on Unix, so `**` never +//! matches a component starting with `.`. `tauri.conf.json` switches that off +//! for the opener plugin; the scope itself stays the edit-session folder. + +#![allow(clippy::unwrap_used)] + +fn conf() -> serde_json::Value { + let raw = include_str!("../tauri.conf.json"); + serde_json::from_str(raw).expect("tauri.conf.json is valid JSON") +} + +fn capability() -> serde_json::Value { + let raw = include_str!("../capabilities/default.json"); + serde_json::from_str(raw).expect("default.json is valid JSON") +} + +#[test] +fn config_disables_literal_leading_dot_for_opener() { + assert_eq!( + conf()["plugins"]["opener"]["requireLiteralLeadingDot"], + serde_json::Value::Bool(false), + "plugins.opener.requireLiteralLeadingDot must be false (issue #1607)" + ); +} + +#[test] +fn capability_scope_stays_the_edit_session_folder() { + let cap = capability(); + let entry = cap["permissions"] + .as_array() + .unwrap() + .iter() + .find(|p| p["identifier"] == "opener:allow-open-path") + .expect("opener:allow-open-path entry"); + let allow = entry["allow"].as_array().unwrap(); + assert_eq!(allow.len(), 1); + assert_eq!(allow[0]["path"], "$CACHE/smart-ssh/edit-sessions/**"); + assert_eq!(allow[0]["app"], true); +} + +#[cfg(unix)] +mod scope { + use std::fs; + use std::path::{Path, PathBuf}; + use tauri::test::{mock_builder, mock_context, noop_assets}; + use tauri::utils::config::FsScope; + + fn touch(path: &Path) { + fs::create_dir_all(path.parent().unwrap()).unwrap(); + fs::write(path, b"x").unwrap(); + } + + /// Builds a scope with the same pattern shape as the capability, rooted in a + /// fresh temp dir, and checks `paths` against it. + fn check(require_dot: Option, check: impl FnOnce(&dyn Fn(&Path) -> bool, &Path)) { + let root: PathBuf = std::env::temp_dir().join(format!( + "smart-ssh-1607-{}-{:?}", + std::process::id(), + require_dot + )); + let _ = fs::remove_dir_all(&root); + fs::create_dir_all(&root).unwrap(); + let root = root.canonicalize().unwrap(); + let app = mock_builder() + .build(mock_context(noop_assets())) + .expect("mock app"); + let pattern = root.join("smart-ssh/edit-sessions/**"); + let scope = tauri::fs::Scope::new( + &app, + &FsScope::Scope { + allow: vec![pattern], + deny: vec![], + require_literal_leading_dot: require_dot, + }, + ) + .unwrap(); + check(&|p| scope.is_allowed(p), &root); + let _ = fs::remove_dir_all(&root); + } + + #[test] + fn dotfile_edit_copy_allowed_and_everything_else_rejected() { + check(Some(false), |allowed, root| { + let ok = root.join("smart-ssh/edit-sessions/data-1/abc/.env.local"); + touch(&ok); + assert!(allowed(&ok), "dotfile edit copy must be allowed"); + let plain = root.join("smart-ssh/edit-sessions/data-1/abc/readme.txt"); + touch(&plain); + assert!(allowed(&plain)); + + let ssh = root.join(".ssh/id_ed25519"); + touch(&ssh); + assert!(!allowed(&ssh), "dotfile outside edit-sessions"); + let other = root.join("smart-ssh/other/.env"); + touch(&other); + assert!(!allowed(&other)); + let traversal = root.join("smart-ssh/edit-sessions/../../.ssh/id_ed25519"); + assert!(!allowed(&traversal), "traversal"); + }); + } + + #[test] + fn counter_proof_literal_leading_dot_rejects_dotfile() { + check(Some(true), |allowed, root| { + let ok = root.join("smart-ssh/edit-sessions/data-1/abc/.env.local"); + touch(&ok); + assert!(!allowed(&ok)); + }); + } +} diff --git a/changelog.d/issue-1607-open-locally-dotfiles.md b/changelog.d/issue-1607-open-locally-dotfiles.md new file mode 100644 index 000000000..f7caec336 --- /dev/null +++ b/changelog.d/issue-1607-open-locally-dotfiles.md @@ -0,0 +1,2 @@ +### Fixed +- "Open locally" now works for remote files whose name starts with a dot, such as `.env.local`, on macOS and Linux. diff --git a/docs/specs/0054-sftp-browser-actions.md b/docs/specs/0054-sftp-browser-actions.md index 33a2a4822..4c4a84fa1 100644 --- a/docs/specs/0054-sftp-browser-actions.md +++ b/docs/specs/0054-sftp-browser-actions.md @@ -301,6 +301,14 @@ Zeile in der Übertragungsliste. Ein erneuter Versuch ersetzt die Meldung, statt eine weitere hinzuzufügen. Ein erfolgreicher Upload meldet sich wie bisher. +**Dateien mit führendem Punkt** (`.env.local`, `.bashrc`, `.gitignore`) lassen +sich auf macOS, Linux und Windows gleich lokal öffnen. Die Freigabe zum Öffnen +gilt weiter nur für den Ordner der Bearbeitungskopien; die Einstellung +`requireLiteralLeadingDot: false` des Opener-Plugins sorgt nur dafür, dass +Punkt-Dateien *innerhalb* dieses Ordners passen. Pfade außerhalb (auch +Punkt-Dateien wie `~/.ssh/id_ed25519`) und Pfade mit `..` bleiben abgelehnt. +Die Bearbeitungskopie behält den Originalnamen. + ## Teil 5: Standardprogramme je Dateityp - In den Einstellungen legt der Nutzer je Dateiendung ein Programm fest