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

Added sandbox attribute to Safe App iframe #1252

Merged
merged 2 commits into from
Nov 29, 2022

Conversation

DaniSomoza
Copy link
Contributor

@DaniSomoza DaniSomoza commented Nov 25, 2022

What it solves

Resolves #1246

How this PR fixes it

Added a sandbox attribute to the Safe Apps iframe in the past

We discussed in this Problem Statement the possibility of adding the sandbox attribute in the iframe.

const IFRAME_SANDBOX_ALLOWED_FEATURES = 'allow-scripts allow-same-origin allow-popups allow-forms allow-downloads allow-orientation-lock'

Allowed features

  • allow-scripts : Lets the resource run scripts (needed for all the Safe Apps)
  • allow-same-origin : Needed to the same-origin policy (Most of Safe App access to data storage/cookies and some JavaScript APIs).
  • allow-forms : Allows Safe Apps to submit forms. Example: Transaction Builder Safe App
  • allow-orientation-lock : Lets the resource lock the screen orientation.
  • allow-popups : Most of Safe Apps, to allow new tab redirections (Etherscan links, docs links...)
  • allow-popups-to-escape-sandbox: Allows a sandboxed document to open new windows without forcing the sandboxing flags upon them (needed for some redirections like twitter see:)

Captura de pantalla 2022-11-28 a las 16 49 16

Restrictions

You can not access to the parent Safe localStorage directly from a Safe App:

  console.log('main Safe frame localstorage: ', window.parent.localStorage)

Captura de pantalla 2022-11-28 a las 13 22 19

Preventing top-level navigation:

Captura de pantalla 2022-11-25 a las 13 20 24

How to test it

  1. Go to this preview branch.
  2. Add this URL as a Custom Safe App:
     https%3A%2F%2Ffcbii9.csb.app
    
  3. Click on Scam link.
  4. Expected Result: No top navigation is performed

Screenshots

Captura de pantalla 2022-11-25 a las 13 20 24

@github-actions
Copy link

github-actions bot commented Nov 25, 2022

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@github-actions
Copy link

Copy link
Member

@katspaugh katspaugh left a comment

Choose a reason for hiding this comment

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

👍

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 28, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: ce9e8c9
Status: ✅  Deploy successful!
Preview URL: https://ef9a017b.web-core.pages.dev
Branch Preview URL: https://feature-safe-app-sandboxed-i.web-core.pages.dev

View logs

@DaniSomoza
Copy link
Contributor Author

DaniSomoza commented Nov 28, 2022

@JagoFigueroa found that some links are not working (like twitter links)

Captura de pantalla 2022-11-28 a las 16 59 53

Captura de pantalla 2022-11-28 a las 16 49 16

see this issue

To address this issue I added this allow-popups-to-escape-sandbox that allows to a sandboxed document to open new windows without forcing the sandboxing flags upon them.

see allow-popups-to-escape-sandbox MDN docs

@JagoFigueroa
Copy link

Espectacular trabajo compañero, todo bueno 😉

@DaniSomoza DaniSomoza merged commit d982bf6 into dev Nov 29, 2022
@DaniSomoza DaniSomoza deleted the feature/safe-app-sandboxed-iframe branch November 29, 2022 09:19
@gitpoap-bot
Copy link

gitpoap-bot bot commented Nov 29, 2022

Congrats, your important contribution to this open-source project has earned you a GitPOAP!

GitPOAP: 2022 Safe Web Core Contributor:

GitPOAP: 2022 Safe Web Core Contributor GitPOAP Badge

Head to gitpoap.io & connect your GitHub account to mint!

Learn more about GitPOAPs here.

@katspaugh katspaugh mentioned this pull request Dec 9, 2022
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.

[Safe Apps] It's possible to hi-jack the top-level URL
4 participants