Need ability to allow users to securely embed javascript in their profile

145 Views Asked by At

I am building a web app & I want to allow users the ability to embed javascript on their personal profile page. Now, I know this opens huge security issues (xss & man in the middle attacks). I want to allow this functionality, but I want to do it securely. Can anyone point me to some condensed information on how to accomplish this? I've done some Google searches but its all over the board.

1

There are 1 best solutions below

4
On

First and foremost you must embed everything inside a iframe. Best would be on a sub-domain (or even better a different domain) so it can't get access to the same origin (where you store users cookies and other client side storage)
however you can get await with using the same origin (domain) if you ensure you use sandboxed attributes correctly and if you know if it's supported

Set your cookies to http-only so javascript can't get access to them...

Second i suggest you read more about the sandboxed attribute to limit what the script can and can't do

To top it all of also take a look at content security policy to limit what can and can't be done (it's more like black/whitelisting things)