Skip to content

fix(dashboard): open external links via validated host bridge in plugin views - #11613

Open
JosephTian876 wants to merge 1 commit into
AstrBotDevs:masterfrom
JosephTian876:fix/plugin-view-iframe-allow-popups
Open

JosephTian876 wants to merge 1 commit into
AstrBotDevs:masterfrom
JosephTian876:fix/plugin-view-iframe-allow-popups

Conversation

@JosephTian876

@JosephTian876 JosephTian876 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Replaces iframe allow-popups / allow-popups-to-escape-sandbox with a strictly validated, host-mediated external:open bridge capability (window.AstrBotPluginView.openExternal(url)) and trusted external anchor click delegation across both PluginViewFrame.vue and PluginViewCard.vue, addressing security review feedback while keeping plugin view iframe sandboxes completely unchanged.

Problem

Dashboard plugin views execute inside sandboxed iframes without allow-popups:

  • dashboard/src/components/plugins/PluginViewFrame.vue (plugin_page and launcher-opened chat_workbench_with_launcher): sandbox="allow-scripts allow-forms allow-downloads"
  • dashboard/src/components/chat/message_list_comps/PluginViewCard.vue (chat_message and event.view_result() workbench views): sandbox="allow-scripts"

Because popups are blocked by the iframe sandbox, user-initiated <a target="_blank"> links or programmatic requests to open documentation, help/OAuth pages, external references, or a plugin's standalone web UI fail silently. Relaxing the iframe sandbox with allow-popups-to-escape-sandbox, however, would allow an iframe to open unsandboxed same-origin tabs or bypass host URL checks.

Security Rationale & Design

Rather than relaxing the iframe sandbox, external navigation is mediated exclusively by the Dashboard host:

  1. Iframe sandbox remains completely unchanged: Neither allow-popups, allow-popups-to-escape-sandbox, allow-same-origin, nor allow-top-navigation is added to PluginViewFrame.vue or PluginViewCard.vue (and HtmlGenUiNode.vue remains untouched).
  2. Strict host-side URL validation (dashboard/src/utils/pluginExternalUrl.ts):
    • Allows only absolute cross-origin http: / https: URLs.
    • Rejects relative URLs, same-origin Dashboard URLs, embedded credentials (user:pass@), control characters, and dangerous schemes (javascript:, data:, blob:, file:, etc.) with INVALID_EXTERNAL_URL.
  3. User activation enforcement: Checks navigator.userActivation.isActive (rejecting non-gesture calls with USER_ACTIVATION_REQUIRED).
  4. Tab isolation: Opens validated targets via window.open(safeUrl, "_blank", "noopener,noreferrer") and defensively nulls opened.opener.
  5. Seamless DX & automatic anchor delegation (astrbot/dashboard/plugin_page_bridge.js):
    • Exposes window.AstrBotPluginView.openExternal(url) across all plugin view targets (plugin_page, chat_message, chat_workbench, chat_workbench_with_launcher).
    • Automatically intercepts trusted left-click / modifier-click events on <a href="https://..." target="_blank"> links to cross-origin http(s) URLs (skipping download, #hash, same-origin, or non-trusted events) and forwards them through external:open.

Changes

  • dashboard/src/utils/pluginExternalUrl.ts: New host-side validation and safe window opener (validateExternalPluginUrl, openExternalPluginUrl, typed INVALID_EXTERNAL_URL / USER_ACTIVATION_REQUIRED errors).
  • astrbot/dashboard/plugin_page_bridge.js: Permit external:open across all view targets, expose openExternal(url), and delegate trusted external <a target="_blank"> clicks.
  • dashboard/src/components/plugins/PluginViewFrame.vue & dashboard/src/components/chat/message_list_comps/PluginViewCard.vue: Handle external:open bridge requests via openExternalPluginUrl without changing iframe sandbox attributes.
  • docs/public/types/astrbot-plugin-view.d.ts, docs/en/dev/star/guides/plugin-views/bridge.md, docs/zh/dev/star/guides/plugin-views/bridge.md: Document openExternal(url), OpenExternalResult, and anchor delegation in English and Chinese.
  • dashboard/tests/pluginViewBridge.test.mjs & dashboard/tests/pluginViewCard.test.mjs: Extended existing test suites to cover host validation, error codes, anchor delegation, and strict sandbox preservation (0 new standalone test files per #11511).

Files Changed (9 files, +828 / -4)

  • astrbot/dashboard/plugin_page_bridge.js
  • dashboard/src/components/chat/message_list_comps/PluginViewCard.vue
  • dashboard/src/components/plugins/PluginViewFrame.vue
  • dashboard/src/utils/pluginExternalUrl.ts
  • dashboard/tests/pluginViewBridge.test.mjs
  • dashboard/tests/pluginViewCard.test.mjs
  • docs/en/dev/star/guides/plugin-views/bridge.md
  • docs/public/types/astrbot-plugin-view.d.ts
  • docs/zh/dev/star/guides/plugin-views/bridge.md

Verification

  • node --test tests/*.test.mjs (in dashboard/): 138 passed, 0 failed (including expanded pluginViewBridge.test.mjs and pluginViewCard.test.mjs).
  • git diff --check 44447db3e..HEAD: PASS (0 whitespace/EOF warnings).
  • Zero new standalone test files added (#11511 compliant); zero file overlap with all 9 sibling AstrBot PR branches.

建议合并顺序 (Recommended Merge Order)

  • Independent, zero-file-overlap security fix updating existing OPEN PR #11613 — can be merged in any order alongside the sibling AstrBot PRs:
    1. #11609 fix/plugin-service-closed-connector (31cd10cfe)
    2. #11610 fix/t2i-local-skip-external-probe (fa03d8382)
    3. #11611 fix/aiocqhttp-at-member-fallback (695686d2e)
    4. #11612 fix/system-one-decision-float32-softmax-tol (ca095e44f)
    5. #11613 fix/plugin-view-iframe-allow-popups (a24df86ec — this PR update)
    6. #11614 fix/gemini-thinking-camelcase-and-safety (397ee6bc1)
    7. #11615 fix/gemini-openai-extra-body-guard (b6c2b1554)
    8. #11616 feat/provider-text-chat-structured-output (7a2f9fe93)
    9. #11617 feat/gemini-decision-1-provider-adapter (0736069ad)
    10. perf/fail-fast-credential-500-and-fallback-cooldown (e3ba1699b — new standalone PR)

Summary by Sourcery

Enable plugin views to open validated external links through the Dashboard host without loosening iframe sandbox restrictions.

New Features:

  • Add an openExternal(url) capability for plugin views and automatically route eligible external-link clicks through the Dashboard host.

Enhancements:

  • Keep plugin-view iframe sandbox permissions unchanged while limiting external navigation to validated cross-origin HTTP(S) URLs opened in isolated tabs with user activation.

Documentation:

  • Document the external-link bridge API and automatic anchor handling in English and Chinese, and add its result type to the public plugin-view declarations.

Tests:

  • Extend existing plugin-view bridge and card tests to cover URL validation, user activation, link delegation, and sandbox preservation.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

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

## Individual Comments

### Comment 1
<location path="dashboard/src/components/plugins/PluginViewFrame.vue" line_range="695" />
<code_context>
       :style="{ colorScheme: themeParam }"
       referrerpolicy="no-referrer"
-      sandbox="allow-scripts allow-forms allow-downloads"
+      sandbox="allow-scripts allow-forms allow-downloads allow-popups allow-popups-to-escape-sandbox"
       @load="handleIframeLoad"
     ></iframe>
</code_context>
<issue_to_address>
**Plugin popups escape dashboard isolation**

When a plugin view opens a popup from a user gesture, `allow-popups-to-escape-sandbox` lets the popup run without the iframe’s sandbox restrictions while retaining its opener. Same-origin plugin content can read Dashboard localStorage credentials, and hostile popup code can navigate the Dashboard tab, exposing credentials or redirecting users.

Remove `allow-popups-to-escape-sandbox` so opened windows remain sandboxed.

Also at `dashboard/src/components/chat/message_list_comps/PluginViewCard.vue:8`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and a plugin view can now open a popup that escapes the iframe sandbox, so plugin content can present an unrestricted window to users and potentially exploit the trust that the sandbox was meant to limit. Reverting prevents future popups from getting that permission, but cannot undo a user interaction or data exposure that already occurred.

Blocking findings: dashboard/src/components/plugins/PluginViewFrame.vue:695


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

…in views

Replace iframe allow-popups/allow-popups-to-escape-sandbox with a host-mediated external:open bridge capability (window.AstrBotPluginView.openExternal) and trusted external anchor click delegation, keeping plugin view iframe sandboxes strictly isolated while validating cross-origin http(s) URLs, user activation, and noopener/noreferrer.
@JosephTian876
JosephTian876 force-pushed the fix/plugin-view-iframe-allow-popups branch from a6877cf to a24df86 Compare December 4, 2026 03:41
@JosephTian876 JosephTian876 changed the title fix(dashboard): allow popups to escape sandbox in plugin view iframes fix(dashboard): open external links via validated host bridge in plugin views Dec 4, 2026

This branch has not been deployed

No deployments
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