Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 128 additions & 3 deletions desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9232,10 +9232,23 @@ const APP_PAGE_NOTIFICATIONS: [&str; 3] = [
"notification:allow-notify",
];

/**
A link the page opens outside the window: a `mailto:` or `tel:` link, a link meant for a new tab
that the outside-links shim leaves alone (another address on this computer), and a link pressed
with Control or Shift. The opener plugin's own script, which Tauri puts in every page, takes those
clicks and asks `plugin:opener|open_url`; without this grant the page was refused ("Command
plugin:opener|open_url not allowed by ACL") and the link did nothing.

URLs only, and only `http:`, `https:`, `mailto:` and `tel:` (the plugin's `allow-default-urls`
scope): never a path, a file, or another app's scheme.
*/
const APP_PAGE_LINKS: [&str; 2] = ["opener:allow-open-url", "opener:allow-default-urls"];

/**
Lets OpenBot's own page move and zoom the window from its drag handle, set the window's appearance
to its own theme, use Settings → This computer (`desktop_page`), and show a Bot's notifications
(`APP_PAGE_NOTIFICATIONS`), and nothing more.
to its own theme, use Settings → This computer (`desktop_page`), show a Bot's notifications
(`APP_PAGE_NOTIFICATIONS`), and open a link in the person's browser or mail app
(`APP_PAGE_LINKS`), and nothing more.

Only the origin this shell verified as its own OpenBot (`trust_owned_app`). A page on any other
loopback port, which a link in a reply can open in this window, gets none of it: Settings → This
Expand All @@ -9261,6 +9274,7 @@ fn allow_app_page<R: tauri::Runtime>(app: &tauri::AppHandle<R>, url: &tauri::Url
for permission in desktop_page::PERMISSIONS
.iter()
.chain(&APP_PAGE_NOTIFICATIONS)
.chain(&APP_PAGE_LINKS)
{
capability = capability.permission(*permission);
}
Expand Down Expand Up @@ -9373,7 +9387,8 @@ mod app_page_tests {
/**
A downloaded file's Show in Finder is the one thing the page needs to reveal a file, and Tauri's
ACL lets OpenBot's own page ask it and nothing else. No shell or opener permission is granted for
it: the page can only name a number the window gave it (`downloads`).
it: the page can only name a number the window gave it (`downloads`). The page's one opener grant
opens a URL (`APP_PAGE_LINKS`), never a path.
*/
#[test]
fn only_openbots_own_page_can_show_a_file_it_downloaded() {
Expand All @@ -9393,6 +9408,116 @@ mod app_page_tests {
.chain(&APP_PAGE_NOTIFICATIONS)
.all(|permission| !permission.starts_with("opener:")
&& !permission.starts_with("shell:")));
assert_eq!(
APP_PAGE_LINKS,
["opener:allow-open-url", "opener:allow-default-urls"]
);
}

/// The opener plugin's `open_url`, as a stand-in under the plugin's own name, so Tauri's real
/// ACL and the real `opener:` permissions guard it. It answers with the URLs the page may open,
/// read from the command's and the plugin's scopes as the real command reads them
/// (tauri-plugin-opener, `commands.rs`), instead of opening a browser.
fn opener_stand_in() -> tauri::plugin::TauriPlugin<tauri::test::MockRuntime> {
use tauri::ipc::{CommandArg, CommandItem, CommandScope, GlobalScope};
type Entry = serde_json::Value;
tauri::plugin::Builder::<tauri::test::MockRuntime>::new("opener")
.invoke_handler(|invoke| {
let item = |key| CommandItem {
plugin: Some("opener"),
name: "open_url",
key,
message: &invoke.message,
acl: &invoke.acl,
};
let command = CommandScope::<Entry>::from_command(item("commandScope")).unwrap();
let global = GlobalScope::<Entry>::from_command(item("globalScope")).unwrap();
let urls = |a: &Vec<std::sync::Arc<Entry>>, b: &Vec<std::sync::Arc<Entry>>| {
let mut urls: Vec<String> = a
.iter()
.chain(b)
.filter_map(|entry| entry.get("url")?.as_str().map(String::from))
.collect();
urls.sort();
urls.dedup();
urls
};
let answer = serde_json::json!({
"allowed": urls(command.allows(), global.allows()),
"denied": urls(command.denies(), global.denies()),
});
invoke.resolver.resolve(answer);
true
})
.build()
}

/**
PostHog, Dec 3 2026: OpenBot's page in the Desktop window threw "Command plugin:opener|open_url
not allowed by ACL", and before that, from Desktop releases that still carried the shell plugin,
"Command plugin:shell|open not allowed by ACL". Tauri puts the opener plugin's link script in
every page; it takes a click on a `mailto:` link, a new-tab link the outside-links shim leaves
alone, or a link pressed with Control or Shift, and asks `plugin:opener|open_url`. OpenBot's own
page (on this computer, or the relay's for OpenBot Cloud) was granted no opener permission, so the
click was swallowed and the link opened nothing.

OpenBot's own page may now open `http:`, `https:`, `mailto:` and `tel:` links; a page on another
loopback port still may not.
*/
#[test]
fn openbots_own_page_can_open_a_link_and_another_page_cannot() {
const OPEN_URL: &str = "plugin:opener|open_url";
let app = tauri::test::mock_builder()
.plugin(opener_stand_in())
.manage(Shell::default())
.build(side_by_side(tauri::generate_context!(test = true)))
.unwrap();
know_app_page_grants(app.handle());
let window = app.get_webview_window("main").unwrap_or_else(|| {
tauri::WebviewWindowBuilder::new(&app, "main", Default::default())
.build()
.unwrap()
});
let open = |from: &str| {
tauri::test::get_ipc_response(
&window,
tauri::webview::InvokeRequest {
cmd: OPEN_URL.into(),
callback: tauri::ipc::CallbackFn(0),
error: tauri::ipc::CallbackFn(1),
url: from.parse().unwrap(),
body: tauri::ipc::InvokeBody::Json(
serde_json::json!({ "url": "mailto:support@open.bot" }),
),
headers: Default::default(),
invoke_key: tauri::test::INVOKE_KEY.into(),
},
)
.map(|body| body.deserialize::<serde_json::Value>().unwrap())
};

// A page on another loopback port, which a link in a reply can open in this window.
let foreign = "http://127.0.0.1:3011/";
allow_app_page(app.handle(), &foreign.parse().unwrap());
let refused = open(foreign).unwrap_err();
assert!(refused.to_string().contains("not allowed"), "{refused}");

// OpenBot on this computer, and OpenBot Cloud through the relay.
for (address, page) in [
("http://127.0.0.1:3010", "http://127.0.0.1:3010/channel/c1"),
("http://127.0.0.1:4410", "http://127.0.0.1:4410/settings"),
] {
trust_owned_app(app.handle(), address);
allow_app_page(app.handle(), &page.parse().unwrap());
assert_eq!(
open(page),
Ok(serde_json::json!({
"allowed":["http://*", "https://*", "mailto:*", "tel:*"],
"denied": [],
})),
"{page}"
);
}
}

/// On Windows the tray said "Quit Ctrl+Q" and Ctrl+Q in the window did nothing: a tray menu's
Expand Down
Loading