Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] How to prohibit <iframe> use @tauri-apps/api? #8316

Closed
ruoxiaomo opened this issue Nov 29, 2023 · 8 comments
Closed

[bug] How to prohibit <iframe> use @tauri-apps/api? #8316

ruoxiaomo opened this issue Nov 29, 2023 · 8 comments
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@ruoxiaomo
Copy link

Describe the bug

I am currently using Tauri to build a plugin platform. These plugins, developed using Vue, React, etc.,
plugin's run within <iframe> elements in the main window. loaded through HTTP or custom protocol, for example, http://localhost:5174/index.html or custom_protocol://localhost/index.html
Currently, there are significant security concerns because when these plugins install @tauri-apps/api, they can freely invoke Tauri's API functions, for example, appWindow.hide() And they can even use window.__TAURI_POST_MESSAGE__ to call my Rust API.

Is there a way to prevent <iframe> from accessing Tauri's API and window.__TAURI_POST_MESSAGE__?
or can we intercept the request?

I understand that this may not be considered a bug, but addressing this security concern is crucial for my project.

If providing code snippets would be helpful, please let me know🙏.

Reproduction

No response

Expected behavior

No response

Platform and versions

* macOS, Windows

[✔] Environment
    - OS: Mac OS 12.3.1 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.68.2 (9eb3afe9e 2023-03-27)
    ✔ cargo: 1.68.2 (6feb7c9cf 2023-03-26)
    ✔ rustup: 1.25.2 (fae52a197 2023-02-01)
    ✔ Rust toolchain: stable-x86_64-apple-darwin (default)
    - node: 14.18.0
    - yarn: 1.22.19
    - npm: 6.14.15

[-] Packages
    - tauri [RUST]: 1.5.2
    - tauri-build [RUST]: 1.5.0
    - wry [RUST]: 0.24.6
    - tao [RUST]: 0.16.2
    - cargo-tauri [RUST]: 1.0.0
    - @tauri-apps/api [NPM]: 1.5.1
    - @tauri-apps/cli [NPM]: 1.5.6

[-] App
    - build-type: bundle
    - CSP: default-src 'self'; connect-src *; frame-src *; img-src 'self' asset: *; script-src 'self' asset: https://asset.localhost; style-src 'unsafe-inline'  asset: *; media-src *;
    - distDir: ../dist
    - devPath: http://localhost:5173/
    - framework: Vue.js
    - bundler: Vite

Stack trace

No response

Additional context

No response

@ruoxiaomo ruoxiaomo added status: needs triage This issue needs to triage, applied to new issues type: bug labels Nov 29, 2023
@ruoxiaomo ruoxiaomo changed the title [bug] How to restrict <iframe> from using @tauri-apps/api? [bug] How to prohibit <iframe> use @tauri-apps/api? Nov 29, 2023
@cijiugechu
Copy link
Contributor

Will Web Workers meet your needs?

@ruoxiaomo
Copy link
Author

Will Web Workers meet your needs?

No, web worker can't solve my problem.
What I want is that iframe js code cannot use Tauri API.

@ruoxiaomo
Copy link
Author

I also used dangerousRemoteDomainIpcAccess, but it didn't work. 😢

"dangerousRemoteDomainIpcAccess": [
    {
        "scheme": "tauri",
        "domain": "localhost",
        "windows": [
            "main"
        ],
        "plugins": [],
        "enableTauriAPI": false
    }
]

@amrbashir
Copy link
Member

amrbashir commented Dec 11, 2023

I think what you're looking for is the isolation pattern https://tauri.app/v1/references/architecture/inter-process-communication/isolation

@rgbkrk
Copy link

rgbkrk commented Jan 14, 2024

I've got a similar request for the ability to load an iframe which will use HTML in the same style as the isolation pattern. I'm not sure how to load this without opening a window though. Can I refer to the bundled html with a particular scheme?

@amrbashir
Copy link
Member

Closing this since the isolation pattern should be used to prevent this.

@amrbashir amrbashir closed this as not planned Won't fix, can't repro, duplicate, stale Apr 15, 2024
@FabianLars
Copy link
Member

afaik the security team is still looking into this so i'm reopening it for now

@FabianLars FabianLars reopened this Apr 16, 2024
@FabianLars
Copy link
Member

fixed in v2 (no iframe access by default)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

5 participants