DEV Community

Cover image for Day-2: Understanding the SOP! πŸ”ͺ

Posted on

Day-2: Understanding the SOP! πŸ”ͺ

Day-2: I started My day with Netflix (Peaky Blinders) and ended it with watching OWASP Stockholm - Mathias Karlsson's Talk on YouTube (How to Differentiate Yourself as a Bug Bounty Hunter) and In between I read and researched about Same-Origin Policy!

So, What the heck is SOP?

  • As you can see the cover page of this blog, you can cleary understand what actually Same-Origin Policy means! In simple words, A script from page A can only access data from page B if they are of the same origin.

Who has the Same Origin?

  • If Two urls share the same protocol, hostname and port number are said to have Same Origin.

Example 1 is given in the starting of the blog!

Example 2: [Port 443 by default] (same origin because same protocol(https), hostname(fenilshah) and port number(443) ) (different origin, because protocol differs (http insted of https) ) (different origin, because hostname differs (fenil instead of fenilshah) ) (different origin, because port number differs (8080 instead of 443) )
Enter fullscreen mode Exit fullscreen mode

What actually the Same-Origin Policy does?

  • Modern web applications often base their authentication on HTTP cookies, and servers take action based on the cookies included automatically by the browser. This makes SOP especially important.

Okay, so imagine you are logged in and at the same time you are visiting If SOP doesn’t exist, a script hosted on is free to access your information on, since your browser would automatically include your cookies in every request you send to (Even if the request is a malicious one generated from a script hosted on

This way attacker can steal the csrf tokens, private email addresses, addresses and other information parsed from the page. And this is why Same-Origin Policy is Important, as SOP will prevent the malicious script hosted on to read the HTML data returned from

Relaxing the SOP!

  • Large websites would not be able to share information with each other because of the restrictive Same-Origin Policy so for such Issues new ways were Invented such as:

Setting document.domain!
Cross-origin resource sharing (CORS)!
Cross-domain messaging (postMessage)!
JSON with Padding (JSONP)!

Resources: (You need premium subs to read this blog).
Mozilla web docs: Same-Origin Policy
Tool to Remove SOP issues: Proxrox (This tool removes same-origin policy issues that typically occur during development.)
Mathias Karlsson's Talk: YouTube

Got doubts? Contact me on Twitter.
Feedbacks are welcomed, do comment it down below! :)

Top comments (0)