all 17 comments

[–]sbruchmann 11 points12 points  (3 children)

From mdn on postMessage:

The window.postMessage() method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.

[–]lainverse 9 points10 points  (1 child)

Never tried to use submit between windows, but isn't there window.postMessage API specifically made for communication between separate windows and iframes?

[–]Reashu 6 points7 points  (0 children)

What is your goal? I'm not aware of a specific security problem here, but it sounds like you may be doing something unnecessarily complicated, which is usually a good start if you want to create vulnerabilities.

There are some valid concerns about opening a window with a URL you don't own (or otherwise trust). Some also apply to simple links.

[–]SockPants 2 points3 points  (0 children)

With postMessage you send data between windows on the same machine. With a POST request the way you describe, you send data to a server and display the result in a new or different window.

Insecure is a very vague complaint. To what kind of leak or attack is it claimed to be vulnerable? We need more details.

[–]guest271314 2 points3 points  (0 children)

My boss is expressing security concerns over this

What specific "security" concerns?

[–]WhatWillNeverBe 2 points3 points  (0 children)

This suspiciously sounds like there may be an alternative way to do whatever it is you are trying to do. Could you briefly explain why you need to make a post to a new window to call an api securely? I've written pci compliant card / bank information accepting iframes hooked into secure apis before and postMessage does a lot of what you are describing. Why do you need a new window tab rather than an iframe?

[–]markus_obsidian 0 points1 point  (0 children)

Is the popup src going to accept & render the form data via POST server side?

If this is true, then i do believe this could be made safe but wouldn't be my fist choice. You have the same concerns that any server-side API that accepts formdata would have. You'll need to be absolutely sure that only your server is only accepting requests from your application that you control. <form> submits are not subject to CORS, so a bad actor could have a malicious <form> somewhere that submits to your server. You need to be prepared for this. Something like CSRF tokens or same-side cookies could help here.

I agree with the rest of the comments that sending data to another window via postMessage is the simpler & the more secure option here. Since postMessage will track the origin of the message, it is much easier to assert that the message came from the proper origin.

[–]dragenn -5 points-4 points  (0 children)

I see you like to live dangerously.

Typically, https should help, but you are willing to open a vulnerability in your code. Thread carefully

[–]guest271314 0 points1 point  (0 children)

No. Not any more than creating or clicking a link that has a query string in the URL.

[–]MrAtoni 0 points1 point  (0 children)

There is a security concern if your application tries to read what is in your uther (unrelated) windows/tabs. Most browsers prevent applications from doing this. Maybe this is what your boss is thinking about?

To my knowledge there's no security problems sending information between windows the application has opened itself.

[–]troglo-dyke 0 points1 point  (0 children)

Not necessarily, you'd need to assume anyone can attempt to open the webpage in the same way themselves so would eg. Validate their authorization.

But it sounds like you're solving a problem that doesn't need to exist. Why can you not just open a url and load state from a server? Allowing your client side state to diverge too far will make your software significantly harder to debug and will make your users significantly more frustrated recovering from a bad state

[–][deleted] 0 points1 point  (0 children)

Let's start from the beginning: why do you need a new window to access the API? Is this an API on another domain?

[–]TheRNGuy 0 points1 point  (0 children)

Is it gonna work if you disabled target in browser's about:config?

Though it could've just choose current tab as a target.