Skip to content

fix: replace target=_blank links with shell bridge open_url #203

@sanity

Description

@sanity

Problem

freenet/freenet-core is removing allow-popups-to-escape-sandbox from the gateway iframe sandbox to fix a security vulnerability where a malicious web app can open a popup that escapes the sandbox and gains full localhost:7509 origin access -- enabling it to interact with other web apps, forge delegate operations, and bypass the new permission prompt system.

Without allow-popups-to-escape-sandbox, popups opened from the iframe inherit the sandbox (opaque origin). This breaks external links in River because the target website sees Origin: null in CORS requests, causing failures.

Solution

The gateway shell page now supports an open_url message via the existing postMessage bridge. Instead of <a target="_blank">, web apps send:

parent.postMessage({
    __freenet_shell__: true,
    type: 'open_url',
    url: 'https://example.com'
}, '*');

The shell page validates the URL (must be https:, must not be localhost) and opens it with window.open(url, '_blank', 'noopener'), giving the popup proper origin without sandbox inheritance.

Changes Needed in River

In ui/src/components/conversation.rs, the add_target_blank_to_links function (around line 406) currently adds target="_blank" to all <a> tags in rendered messages. This needs to be changed so that link clicks are intercepted and routed through the shell bridge instead.

Options:

  1. Add an onclick handler that calls parent.postMessage(...) and prevents default navigation
  2. Or use the freenet-stdlib helper (if one is added) for shell bridge URL opening

Blocked By

This is blocked by the freenet-core PR that removes allow-popups-to-escape-sandbox and adds the open_url shell bridge handler. External links will break in River once that PR is released until this change is made.

Priority

High -- must be done immediately after the freenet-core release that removes allow-popups-to-escape-sandbox.

[AI-assisted - Claude]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions