Skip to content

feat: support Cloud plugin installation deep links - #201

Merged
Soulter merged 2 commits into
mainfrom
codex/plugin-install-deep-links
Nov 26, 2026
Merged

Soulter merged 2 commits into
mainfrom
codex/plugin-install-deep-links

Conversation

@Soulter

@Soulter Soulter commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary / 改动概述

Allow Cloud to open a plugin installation in the AstrBot desktop application using astrbot://extension/plugins?market_plugin_id=author%2Fname and optional registry_url.

  • Register the astrbot scheme with Tauri Deep Link and forward activations through the existing single-instance application.
  • Validate the action, metadata ID, and optional HTTPS registry. Keep a pending target during startup or backend restart, then forward it after the trusted WebUI is ready.
  • Treat deep-link registration/current-URL errors as nonfatal and log them so normal startup still works.
  • Probe backend state on a blocking worker, resume pending links after a successful backend restart, and allow another link activation to retry a failed startup.
  • Open the existing core installation confirmation flow. The desktop shell does not install packages directly.

Companion Cloud PR: https://github.com/AstrBotDevs/astrbot-cloud/pull/20

Verification / 验证方式

  • cargo check --manifest-path src-tauri/Cargo.toml
  • cargo test --manifest-path src-tauri/Cargo.toml --locked: 287 passed, including valid/default/custom-source links, invalid action/identity/credential/duplicate-parameter cases, restart recovery, and startup-failure retry decisions.
  • cargo clippy --manifest-path src-tauri/Cargo.toml --locked --all-targets -- -D warnings
  • cargo fmt --manifest-path src-tauri/Cargo.toml --all -- --check

The target core/WebUI needs marketplace installation-link support (AstrBot v4.30.0+). OS-level activation still needs verification with installed application bundles on Windows, macOS, and Linux. Desktop registers astrbot; Launcher registers astrbot-launcher, allowing both applications to coexist.

Checklist / 检查清单

  • Additive protocol support; existing launch behavior is preserved.
  • Local Rust checks and tests passed.
  • Dependency lockfile updated.
  • No workflow changes.

Launcher companion: AstrBotDevs/astrbot-launcher#115

Summary by Sourcery

Enable the desktop application to receive Cloud plugin installation deep links and forward validated requests to the existing core installation confirmation flow.

New Features:

  • Support opening plugin installation confirmation flows from validated astrbot:// deep links, including optional HTTPS registries.

Enhancements:

  • Preserve and resume installation-link requests across application startup, backend restarts, and WebUI readiness while routing them through the existing trusted installation flow.
  • Integrate deep-link handling with single-instance activation and focus the existing desktop window.

Build:

  • Add Tauri deep-link support and update the dependency lockfile.

Deployment:

  • Register the desktop application's astrbot URL scheme.

Tests:

  • Add coverage for valid installation links, custom registries, malformed links, duplicate parameters, credentials, and backend readiness states.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 6 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src-tauri/src/install_link.rs" line_range="37-45" />
<code_context>
+            "market_plugin_id" if plugin_id.is_none() => plugin_id = Some(value.into_owned()),
+            "registry_url" if registry_url.is_none() => {
+                let registry = Url::parse(&value).ok()?;
+                if registry.scheme() != "https"
+                    || registry.host_str().is_none()
+                    || !registry.username().is_empty()
+                    || registry.password().is_some()
+                    || registry.fragment().is_some()
+                {
+                    return None;
+                }
+                registry_url = Some(registry.to_string());
+            }
+            _ => return None,
</code_context>
<issue_to_address>
**Deep links probe private HTTPS services**

When an untrusted page or local process opens an `astrbot://` link whose `registry_url` resolves to a private or loopback HTTPS service, `parse_target` accepts any HTTPS host and `InstallTarget::fragment` forwards it into the WebUI marketplace flow, so a link sender can make the core’s registry lookup contact private or loopback services. HTTPS does not prevent access to those hosts, exposing internal services to requests triggered by the desktop app.

Reject private, loopback, and link-local destinations after DNS resolution (including redirects), or restrict registry URLs to explicitly trusted hosts.
</issue_to_address>

### Comment 2
<location path="src-tauri/src/install_link.rs" line_range="87" />
<code_context>
+
+pub(crate) fn setup(app: &tauri::App) -> Result<(), Box<dyn std::error::Error>> {
+    #[cfg(target_os = "linux")]
+    app.deep_link().register_all()?;
+    let handle = app.handle().clone();
+    app.deep_link().on_open_url(move |event| {
</code_context>
<issue_to_address>
**Deep-link errors prevent launch**

When linux scheme registration or current-link lookup returns an error, `install_link::setup` propagates the error through Tauri setup, and application construction panics at `expect`, so AstrBot fails to launch instead of running without deep-link support.

Handle errors from `register_all()` and `get_current()` without failing application setup.

Also at `src-tauri/src/install_link.rs:94`.
</issue_to_address>

### Comment 3
<location path="src-tauri/src/install_link.rs" line_range="113" />
<code_context>
+        "open plugin installation link",
+        move |app| {
+            let state = app.state::<InstallLinkState>();
+            *state.pending.lock().unwrap() = Some(fragment);
+            crate::window::actions::show_main_window(app, DEFAULT_SHELL_LOCALE, append_desktop_log);
+            if state.ready.load(Ordering::SeqCst) {
</code_context>
<issue_to_address>
**Earlier installation links are lost**

When multiple valid installation links arrive before the dashboard is ready, `receive` overwrites the single `pending` value for each link, so `open_pending` forwards only the last target to the WebUI and earlier installation requests are lost.

Store pending targets in a queue and forward each one when the dashboard is ready.

Also at `src-tauri/src/install_link.rs:90-91`.
</issue_to_address>

### Comment 4
<location path="src-tauri/src/install_link.rs" line_range="118-119" />
<code_context>
+            if state.ready.load(Ordering::SeqCst) {
+                let backend = app.state::<BackendState>().bridge_state(app);
+                if backend.spawning || backend.restarting {
+                    state.ready.store(false, Ordering::SeqCst);
+                    return;
+                }
+                if !backend.running && !backend.spawning && !backend.restarting {
</code_context>
<issue_to_address>
**Restart leaves links unopened**

When a valid link arrives during a backend restart that completes without reloading the WebUI document, `receive` clears `ready` and returns without scheduling a retry; `run_restart_backend_task` only reports the result, and the loaded document does not call `dashboard_ready` again, so the pending link stays unopened.

Retry forwarding the pending link when the backend restart completes, even if the WebUI document does not reload.
</issue_to_address>

### Comment 5
<location path="src-tauri/src/install_link.rs" line_range="123" />
<code_context>
+                }
+                if !backend.running && !backend.spawning && !backend.restarting {
+                    state.ready.store(false, Ordering::SeqCst);
+                    crate::startup_task::spawn_startup_task(app.clone(), crate::append_startup_log);
+                } else {
+                    open_pending(app);
</code_context>
<issue_to_address>
**Retries stop after startup failure**

When a previously loaded backend becomes unavailable and the link-triggered startup attempt fails, `spawn_startup_task` reports a failed backend startup without restoring `ready`; subsequent links only replace `pending` and never start another attempt, so the installation flow remains stuck until the app is restarted or the dashboard is loaded another way.

Restore a retryable state after startup failure, or allow a later link activation to start another backend attempt when the app is showing the startup error.
</issue_to_address>

### Comment 6
<location path="src-tauri/src/install_link.rs" line_range="116" />
<code_context>
+            *state.pending.lock().unwrap() = Some(fragment);
+            crate::window::actions::show_main_window(app, DEFAULT_SHELL_LOCALE, append_desktop_log);
+            if state.ready.load(Ordering::SeqCst) {
+                let backend = app.state::<BackendState>().bridge_state(app);
+                if backend.spawning || backend.restarting {
+                    state.ready.store(false, Ordering::SeqCst);
</code_context>
<issue_to_address>
**Deep link freezes desktop UI**

When the backend probe or DNS resolution is slow while a link arrives, `receive` calls `bridge_state` inside its main-thread dispatch; that call performs synchronous DNS resolution and TCP probes, so a slow resolver or backend probe stalls the UI while the link is handled.

Perform the backend-state probe off the main thread and dispatch only its result back to the UI thread.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 6 findings to address first, and an external astrbot: link can send the app to the plugin installation flow with a caller-supplied HTTPS registry URL; if a user installs a plugin from that source, its code may remain installed and run after this change is reverted. This code does not itself install a plugin, but it does introduce an untrusted link path into that security-sensitive flow.

Blocking findings: src-tauri/src/install_link.rs:45, src-tauri/src/install_link.rs:87, src-tauri/src/install_link.rs:113, src-tauri/src/install_link.rs:119, src-tauri/src/install_link.rs:123, and 1 more


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment on lines +37 to +45
if registry.scheme() != "https"
|| registry.host_str().is_none()
|| !registry.username().is_empty()
|| registry.password().is_some()
|| registry.fragment().is_some()
{
return None;
}
registry_url = Some(registry.to_string());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Deep links probe private HTTPS services

When an untrusted page or local process opens an astrbot:// link whose registry_url resolves to a private or loopback HTTPS service, parse_target accepts any HTTPS host and InstallTarget::fragment forwards it into the WebUI marketplace flow, so a link sender can make the core’s registry lookup contact private or loopback services. HTTPS does not prevent access to those hosts, exposing internal services to requests triggered by the desktop app.

Reject private, loopback, and link-local destinations after DNS resolution (including redirects), or restrict registry URLs to explicitly trusted hosts.

Prompt for AI agents
In `src-tauri/src/install_link.rs` at lines 37-45:

**Deep links probe private HTTPS services**

When an untrusted page or local process opens an `astrbot://` link whose `registry_url` resolves to a private or loopback HTTPS service, `parse_target` accepts any HTTPS host and `InstallTarget::fragment` forwards it into the WebUI marketplace flow, so a link sender can make the core’s registry lookup contact private or loopback services. HTTPS does not prevent access to those hosts, exposing internal services to requests triggered by the desktop app.

Reject private, loopback, and link-local destinations after DNS resolution (including redirects), or restrict registry URLs to explicitly trusted hosts.

Comment thread src-tauri/src/install_link.rs Resolved
"open plugin installation link",
move |app| {
let state = app.state::<InstallLinkState>();
*state.pending.lock().unwrap() = Some(fragment);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Earlier installation links are lost

When multiple valid installation links arrive before the dashboard is ready, receive overwrites the single pending value for each link, so open_pending forwards only the last target to the WebUI and earlier installation requests are lost.

Store pending targets in a queue and forward each one when the dashboard is ready.

Also at src-tauri/src/install_link.rs:90-91.

Prompt for AI agents
In `src-tauri/src/install_link.rs` at line 113:

**Earlier installation links are lost**

When multiple valid installation links arrive before the dashboard is ready, `receive` overwrites the single `pending` value for each link, so `open_pending` forwards only the last target to the WebUI and earlier installation requests are lost.

Store pending targets in a queue and forward each one when the dashboard is ready.

Also at `src-tauri/src/install_link.rs:90-91`.

Comment thread src-tauri/src/install_link.rs Resolved
Comment thread src-tauri/src/install_link.rs Resolved
Comment thread src-tauri/src/install_link.rs Resolved
@Soulter
Soulter merged commit 32b0e69 into main Nov 26, 2026
4 checks passed
@Soulter
Soulter deleted the codex/plugin-install-deep-links branch November 26, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant