Is a javascript bookmarklet that can set domain cookies breaking cross-domain security?

≯℡__Kan透↙ 提交于 2019-12-06 10:11:32

Bookmarklets are running in the context of the current page so that is the security context they run in and thus this doesn't break cross domain policy. You can only set cookies on the current page's domain. Because of this your bookmarklet can't have it's own cookies.

This is the same as scripts that are loaded into a given page from a variety of domains. The origin of the page is what matters, not the origin of the script.

The only way I know of for you to save settings once for your script across all domains would be to use cross domain JSONP and store the settings on your server, but you still may have difficulty identifying a unique user.

It sounds like what you're trying to do would be much more suited to a browser plug-in which has local storage for the plug-in.

It does not break cross domain policy, since it is in fact run on a separate domain (that's the point behind a bookmarklet).

If you want to store cookie information, either make use of a 3rd party service (as in, have your own server with code that accepts cookie changes). Note that this can be a security issue since every domain would be able to get cookies for your user, unless you make your service write-only (which I doubt).

Then there's another alternative - don't save settings in a cookie. Use a different storage medium instead.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!