Skip to content

Updates trypurescript to work with Halogen Affjax example #203

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

Merged
merged 1 commit into from
Dec 11, 2020

Conversation

mikesol
Copy link

@mikesol mikesol commented Sep 25, 2020

Currently, the affjax example in Halogen does not work and returns the following response:

Blocked form submission to '' because the form's frame is sandboxed and the 'allow-forms' permission is not set.

I believe this fixes the issue, although I haven't tested it yet. Thanks!

Currently, the affjax example in Halogen does not work and returns the following response:

```
Blocked form submission to '' because the form's frame is sandboxed and the 'allow-forms' permission is not set.
```

I believe this fixes the issue, although I haven't tested it yet. Thanks!
@milesfrain
Copy link
Contributor

@hdgarrood
Copy link
Collaborator

Thanks for the PR. I’d like to do a bit of research about the security implications of allowing forms here before accepting. (I assume that allow-forms is disabled by default for a reason).

@thomashoneyman
Copy link
Member

@hdgarrood as far as I understand it, the risk of allowing forms via an iframe is that the form submission can POST some data off to a server when you may not have wanted that. Yet due to allow-scripts we already let you communicate with external servers.

For example, in the linked Halogen example if you use the click event instead of the submission event then the request goes through perfectly fine. So I'm not sure what we gain by blocking form submission within this iframe.

@natefaubion
Copy link
Contributor

natefaubion commented Sep 29, 2020

Does the form submission let you navigate away from the host page within the frame?

@thomashoneyman
Copy link
Member

I believe that to do that you would have the form trigger a JS handler which changes the iframe location. But I also think that's already possible to do via allow-scripts. For example, within the console for the iframe I can do this:

2020-09-29 12 30 13

Resources are blocked by the same-origin policy, but navigation seems possible.

@natefaubion
Copy link
Contributor

natefaubion commented Sep 29, 2020

It's not clear to me your dev console is executing within the context (security policy) of the inner iframe. I don't think testing it in the dev console is a robust way of verifying the security of it.

@thomashoneyman
Copy link
Member

thomashoneyman commented Sep 29, 2020

I agree that the dev console isn't the proper way to check this. That said, the console is executing within the JS context of the iframe:

Screen Shot 2020-09-29 at 12 46 07 PM

Though perhaps that doesn't necessarily mean it's subject to the iframe's security policy. It seems that it is, but I'm open to suggestions for better ways to check this.

@natefaubion
Copy link
Contributor

I would verify it with DOM APIs in PureScript code if available. If the APIs are unavailable, you can hack around it with unsafeCoerce.

@thomashoneyman
Copy link
Member

thomashoneyman commented Sep 29, 2020

The APIs are unavailable (from a quick glance through Pursuit), so I can hack around it later today.

@natefaubion
Copy link
Contributor

I was able to use

module Main where

import Prelude

import Effect (Effect)
import Web.HTML (window)
import Web.HTML.Location (setHref)
import TryPureScript 
import Debug.Trace
import Unsafe.Coerce (unsafeCoerce)

main :: Effect Unit
main = do
  win <- window
  let loc = (unsafeCoerce win).frames.location
  setHref "https://google.com" loc
  pure unit

and it was blocked

Screen Shot 2020-09-29 at 12 57 18 PM

@natefaubion
Copy link
Contributor

So as long as a form submission does the same thing I'm ok with allowing it.

@natefaubion
Copy link
Contributor

natefaubion commented Sep 29, 2020

Oh whoops! that's due to a header on google.com specifically. You are correct, unfortunately allow-scripts does let you change the location within the iframe. I'm inclined to agree with you then.

@thomashoneyman
Copy link
Member

Fortunately it doesn't navigate the top-level window and the iframe is still sandboxed.

Copy link
Member

@thomashoneyman thomashoneyman left a comment

Choose a reason for hiding this comment

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

Given the discussion we've had so far, I think that adding this functionality doesn't increase our security risk and unblocks a nice use case for Try PureScript.

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.

5 participants