R
realfun
I have been to some css/html/js discussing board which provide a text
box to enter the html and a "Run it!" button to run the html in new
pops up window.
I want to make one also, which is easy in jQuery:
function try_show_result() {
var code = $("#try-input").val();
if (code !== "") {
var newwin = window.open('','','');
newwin.opener = null;
newwin.document.write(code);
newwin.document.close();
}
}
But then I found a security problem: the pops up window has all the
abilities of running an arbitrary javascript. So that when another
authenticated user runs a given piece of code on the page, then it
could stealing cookies or access some url that is only for the
specified user only through ajax posts, or XSS/CSRF attack.
Is there an easy way to avoid this?
I added newwin.document.cookie="" before open the window, but no luck.
box to enter the html and a "Run it!" button to run the html in new
pops up window.
I want to make one also, which is easy in jQuery:
function try_show_result() {
var code = $("#try-input").val();
if (code !== "") {
var newwin = window.open('','','');
newwin.opener = null;
newwin.document.write(code);
newwin.document.close();
}
}
But then I found a security problem: the pops up window has all the
abilities of running an arbitrary javascript. So that when another
authenticated user runs a given piece of code on the page, then it
could stealing cookies or access some url that is only for the
specified user only through ajax posts, or XSS/CSRF attack.
Is there an easy way to avoid this?
I added newwin.document.cookie="" before open the window, but no luck.