Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions .changes/register-plugin-listener-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:bug
---

Fix `core > addPluginListener` failing on command permission check.
34 changes: 27 additions & 7 deletions crates/tauri/src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1715,14 +1715,34 @@ tauri::Builder::default()
url: request.url.clone(),
}
};
let window_label = message.webview.window_label();
let (resolved_acl, has_app_acl_manifest) = {
let runtime_authority = manager.runtime_authority.lock().unwrap();
let acl = runtime_authority.resolve_access(
&request.cmd,
message.webview.window_ref().label(),
message.webview.label(),
&acl_origin,
);
let acl = runtime_authority
.resolve_access(
&request.cmd,
&window_label,
message.webview.label(),
&acl_origin,
)
.or_else(|| {
if request.cmd.chars().any(|c| c.is_uppercase()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly don't like this, it means we now match the commands in different casing without formal documentation, and that's confusing, I'd rather use a try catch call in the addPluginListener function

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we just have a particular case for registerListener then? i don't really want to make two calls for a single command :/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well i'll just go with your idea.. better than bloating the rust side with a lot of temp logic :(

// fallback to the snake case of the command
// we do not do this by default for backwards compatibility
runtime_authority.resolve_access(
&if let Some((prefix, cmd_name)) = request.cmd.split_once('|') {
format!("{prefix}|{}", heck::AsSnakeCase(cmd_name))
} else {
request.cmd.clone()
},
&window_label,
message.webview.label(),
&acl_origin,
)
} else {
None
}
});
(acl, runtime_authority.has_app_manifest())
};

Expand Down Expand Up @@ -1759,7 +1779,7 @@ tauri::Builder::default()
.resolve_access_message(
key,
&command_name,
invoke.message.webview.window().label(),
&window_label,
invoke.message.webview.label(),
&acl_origin,
),
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ async function addPluginListener<T>(
cb: (payload: T) => void
): Promise<PluginListener> {
const handler = new Channel<T>(cb)
// note: we must stick with camelCase here for backwards compatibility
return invoke(`plugin:${plugin}|registerListener`, { event, handler }).then(
() => new PluginListener(plugin, event, handler.id)
)
Expand Down
Loading