<s>
In	O
computing	O
,	O
the	O
same-origin	B-Protocol
policy	I-Protocol
(	O
SOP	O
)	O
is	O
an	O
important	O
concept	O
in	O
the	O
web	O
application	O
security	O
model	O
.	O
</s>
<s>
Under	O
the	O
policy	O
,	O
a	O
web	B-Protocol
browser	I-Protocol
permits	O
scripts	O
contained	O
in	O
a	O
first	O
web	O
page	O
to	O
access	O
data	O
in	O
a	O
second	O
web	O
page	O
,	O
but	O
only	O
if	O
both	O
web	O
pages	O
have	O
the	O
same	B-Protocol
origin	I-Protocol
.	O
</s>
<s>
An	O
origin	O
is	O
defined	O
as	O
a	O
combination	O
of	O
URI	B-Protocol
scheme	I-Protocol
,	O
host	B-Protocol
name	I-Protocol
,	O
and	O
port	B-Protocol
number	I-Protocol
.	O
</s>
<s>
This	O
policy	O
prevents	O
a	O
malicious	O
script	O
on	O
one	O
page	O
from	O
obtaining	O
access	O
to	O
sensitive	O
data	O
on	O
another	O
web	O
page	O
through	O
that	O
page	O
's	O
Document	B-General_Concept
Object	I-General_Concept
Model	I-General_Concept
.	O
</s>
<s>
This	O
mechanism	O
bears	O
a	O
particular	O
significance	O
for	O
modern	O
web	O
applications	O
that	O
extensively	O
depend	O
on	O
HTTP	B-Application
cookies	I-Application
to	O
maintain	O
authenticated	O
user	O
sessions	O
,	O
as	O
servers	O
act	O
based	O
on	O
the	O
HTTP	B-Application
cookie	I-Application
information	O
to	O
reveal	O
sensitive	O
information	O
or	O
take	O
state-changing	O
actions	O
.	O
</s>
<s>
It	O
is	O
very	O
important	O
to	O
remember	O
that	O
the	O
same-origin	B-Protocol
policy	I-Protocol
applies	O
only	O
to	O
scripts	O
.	O
</s>
<s>
Attacks	O
take	O
advantage	O
of	O
the	O
fact	O
that	O
the	O
same	B-Protocol
origin	I-Protocol
policy	I-Protocol
does	O
not	O
apply	O
to	O
HTML	O
tags	O
.	O
</s>
<s>
The	O
concept	O
of	O
same-origin	B-Protocol
policy	I-Protocol
was	O
introduced	O
by	O
Netscape	B-Application
Navigator	I-Application
2.02	I-Application
in	O
1995	O
,	O
shortly	O
after	O
the	O
introduction	O
of	O
JavaScript	B-Language
in	O
Netscape	O
2.0	O
.	O
</s>
<s>
JavaScript	B-Language
enabled	O
scripting	B-Language
on	O
web	O
pages	O
,	O
and	O
in	O
particular	O
programmatic	O
access	O
to	O
the	O
Document	B-General_Concept
Object	I-General_Concept
Model	I-General_Concept
(	O
DOM	B-General_Concept
)	O
.	O
</s>
<s>
The	O
policy	O
was	O
originally	O
designed	O
to	O
protect	O
access	O
to	O
the	B-General_Concept
DOM	I-General_Concept
,	O
but	O
has	O
since	O
been	O
broadened	O
to	O
protect	O
sensitive	O
parts	O
of	O
the	O
global	O
JavaScript	B-Language
object	O
.	O
</s>
<s>
All	O
modern	O
browsers	O
implement	O
some	O
form	O
of	O
the	O
same-origin	B-Protocol
policy	I-Protocol
as	O
it	O
is	O
an	O
important	O
security	O
cornerstone	O
.	O
</s>
<s>
The	O
policies	O
are	O
not	O
required	O
to	O
match	O
an	O
exact	O
specification	O
but	O
are	O
often	O
extended	O
to	O
define	O
roughly	O
compatible	O
security	O
boundaries	O
for	O
other	O
web	O
technologies	O
,	O
such	O
as	O
Microsoft	B-Application
Silverlight	I-Application
,	O
Adobe	B-Operating_System
Flash	I-Operating_System
,	O
or	O
Adobe	B-Application
Acrobat	I-Application
,	O
or	O
for	O
mechanisms	O
other	O
than	O
direct	O
DOM	B-General_Concept
manipulation	O
,	O
such	O
as	O
XMLHttpRequest	B-Protocol
.	O
</s>
<s>
The	O
algorithm	O
used	O
to	O
calculate	O
the	O
"	O
origin	O
"	O
of	O
a	O
URI	B-Protocol
is	O
specified	O
in	O
RFC	O
6454	O
,	O
Section	O
4	O
.	O
</s>
<s>
For	O
absolute	O
URIs	B-Protocol
,	O
the	O
origin	O
is	O
the	O
triple	O
{	O
scheme	O
,	O
host	O
,	O
port}	O
.	O
</s>
<s>
If	O
the	O
URI	B-Protocol
does	O
not	O
use	O
a	O
hierarchical	O
element	O
as	O
a	O
naming	O
authority	O
(	O
see	O
RFC	O
3986	O
,	O
Section	O
3.2	O
)	O
or	O
if	O
the	O
URI	B-Protocol
is	O
not	O
an	O
absolute	O
URI	B-Protocol
,	O
then	O
a	O
globally	O
unique	O
identifier	O
is	O
used	O
.	O
</s>
<s>
Two	O
resources	O
are	O
considered	O
to	O
be	O
of	O
the	O
same	B-Protocol
origin	I-Protocol
if	O
and	O
only	O
if	O
all	O
these	O
values	O
are	O
exactly	O
the	O
same	O
.	O
</s>
<s>
The	O
same-origin	B-Protocol
policy	I-Protocol
protects	O
against	O
reusing	O
authenticated	O
sessions	O
across	O
origins	O
.	O
</s>
<s>
The	O
following	O
example	O
illustrates	O
a	O
potential	O
security	O
risk	O
that	O
could	O
arise	O
without	O
the	O
same-origin	B-Protocol
policy	I-Protocol
.	O
</s>
<s>
Then	O
,	O
the	O
user	O
goes	O
to	O
another	O
site	O
that	O
has	O
malicious	O
JavaScript	B-Language
code	O
that	O
requests	O
data	O
from	O
the	O
banking	O
site	O
.	O
</s>
<s>
This	O
is	O
because	O
,	O
in	O
the	O
original	O
spirit	O
of	O
a	O
world	O
wide	O
web	O
,	O
browsers	O
are	O
required	O
to	O
tag	O
along	O
authentication	O
details	O
such	O
as	O
session	O
cookies	B-Application
and	O
platform-level	O
kinds	O
of	O
the	O
Authorization	O
request	O
header	O
to	O
the	O
banking	O
site	O
based	O
on	O
the	O
domain	O
of	O
the	O
banking	O
site	O
.	O
</s>
<s>
The	O
bank	O
site	O
owners	O
would	O
expect	O
that	O
regular	O
browsers	O
of	O
users	O
visiting	O
the	O
malicious	O
site	O
do	O
not	O
allow	O
the	O
code	O
loaded	O
from	O
the	O
malicious	O
site	O
access	O
the	O
banking	O
session	O
cookie	B-Application
or	O
platform-level	O
authorization	O
.	O
</s>
<s>
While	O
it	O
is	O
true	O
that	O
JavaScript	B-Language
has	O
no	O
direct	O
access	O
to	O
the	O
banking	O
session	O
cookie	B-Application
,	O
it	O
could	O
still	O
send	O
and	O
receive	O
requests	O
to	O
the	O
banking	O
site	O
with	O
the	O
banking	O
site	O
's	O
session	O
cookie	B-Application
.	O
</s>
<s>
Same	B-Protocol
Origin	I-Protocol
Policy	I-Protocol
was	O
introduced	O
as	O
a	O
requirement	O
for	O
security-minded	O
browsers	O
to	O
deny	O
read	O
access	O
to	O
responses	O
from	O
across	O
origins	O
,	O
with	O
the	O
assumption	O
that	O
the	O
majority	O
of	O
users	O
choose	O
to	O
use	O
compliant	O
browsers	O
.	O
</s>
<s>
Counteracting	O
the	O
abuse	O
of	O
the	O
write	O
permission	O
requires	O
additional	O
CSRF	B-Protocol
protections	O
by	O
the	O
target	O
sites	O
.	O
</s>
<s>
In	O
some	O
circumstances	O
,	O
the	O
same-origin	B-Protocol
policy	I-Protocol
is	O
too	O
restrictive	O
,	O
posing	O
problems	O
for	O
large	O
websites	O
that	O
use	O
multiple	O
subdomains	B-Protocol
.	O
</s>
<s>
Modern	O
browsers	O
support	O
multiple	O
techniques	O
for	O
relaxing	O
the	O
same-origin	B-Protocol
policy	I-Protocol
in	O
a	O
controlled	O
manner	O
:	O
</s>
<s>
Netscape	B-Protocol
Navigator	I-Protocol
briefly	O
contained	O
a	O
taint	O
checking	O
feature	O
.	O
</s>
<s>
The	O
feature	O
was	O
turned	O
off	O
by	O
default	O
,	O
but	O
if	O
enabled	O
by	O
a	O
user	O
it	O
would	O
allow	O
websites	O
to	O
attempt	O
to	O
read	O
JavaScript	B-Language
properties	O
of	O
windows	O
and	O
frames	B-General_Concept
belonging	O
to	O
a	O
different	O
domain	O
.	O
</s>
<s>
If	O
two	O
windows	O
(	O
or	O
frames	B-General_Concept
)	O
contain	O
scripts	O
that	O
set	O
domain	O
to	O
the	O
same	O
value	O
,	O
the	O
same-origin	B-Protocol
policy	I-Protocol
is	O
relaxed	O
for	O
these	O
two	O
windows	O
,	O
and	O
each	O
window	O
can	O
interact	O
with	O
the	O
other	O
.	O
</s>
<s>
For	O
example	O
,	O
cooperating	O
scripts	O
in	O
documents	O
loaded	O
from	O
orders.example.com	O
and	O
catalog.example.com	O
might	O
set	O
their	O
document.domain	O
properties	O
to	O
“	O
example.com”	O
,	O
thereby	O
making	O
the	O
documents	O
appear	O
to	O
have	O
the	O
same	B-Protocol
origin	I-Protocol
and	O
enabling	O
each	O
document	O
to	O
read	O
properties	O
of	O
the	O
other	O
.	O
</s>
<s>
The	O
document.domain	O
concept	O
was	O
introduced	O
as	O
part	O
of	O
Netscape	B-Protocol
Navigator	I-Protocol
3	O
,	O
released	O
in	O
1996	O
.	O
</s>
<s>
The	O
other	O
technique	O
for	O
relaxing	O
the	O
same-origin	B-Protocol
policy	I-Protocol
is	O
standardized	O
under	O
the	O
name	O
Cross-Origin	B-General_Concept
Resource	I-General_Concept
Sharing	I-General_Concept
(	O
CORS	B-General_Concept
)	O
.	O
</s>
<s>
This	O
standard	O
extends	O
HTTP	O
with	O
a	O
new	O
Origin	O
request	O
header	O
and	O
a	O
new	O
Access-Control-Allow-Origin	B-General_Concept
response	O
header	O
.	O
</s>
<s>
Browsers	O
such	O
as	O
Firefox	O
3.5	O
,	O
Safari	O
4	O
and	O
Internet	O
Explorer	O
10	O
use	O
this	O
header	O
to	O
allow	O
the	O
cross-origin	O
HTTP	O
requests	O
with	O
XMLHttpRequest	B-Protocol
that	O
would	O
otherwise	O
have	O
been	O
forbidden	O
by	O
the	O
same-origin	B-Protocol
policy	I-Protocol
.	O
</s>
<s>
Another	O
technique	O
,	O
cross-document	B-General_Concept
messaging	I-General_Concept
allows	O
a	O
script	O
from	O
one	O
page	O
to	O
pass	O
textual	O
messages	O
to	O
a	O
script	O
on	O
another	O
page	O
regardless	O
of	O
the	O
script	O
origins	O
.	O
</s>
<s>
Calling	O
the	O
postMessage( )	O
method	O
on	O
a	O
Window	O
object	O
asynchronously	O
fires	O
an	O
"	O
onmessage	O
"	O
event	O
in	O
that	O
window	O
,	O
triggering	O
any	O
user-defined	O
event	O
handlers	O
.	O
</s>
<s>
Since	O
HTML	O
<script>	O
elements	O
are	O
allowed	O
to	O
retrieve	O
and	O
execute	O
content	O
from	O
other	O
domains	O
,	O
a	O
page	O
can	O
bypass	O
the	O
same-origin	B-Protocol
policy	I-Protocol
and	O
receive	O
JSON	O
data	O
from	O
a	O
different	O
domain	O
by	O
loading	O
a	O
resource	O
that	O
returns	O
a	O
JSONP	O
payload	O
.	O
</s>
<s>
Modern	O
browsers	O
will	O
permit	O
a	O
script	O
to	O
connect	O
to	O
a	O
WebSocket	O
address	O
without	O
applying	O
the	O
same-origin	B-Protocol
policy	I-Protocol
.	O
</s>
<s>
However	O
,	O
they	O
recognize	O
when	O
a	O
WebSocket	O
URI	B-Protocol
is	O
used	O
,	O
and	O
insert	O
an	O
Origin	O
:	O
header	O
into	O
the	O
request	O
that	O
indicates	O
the	O
origin	O
of	O
the	O
script	O
requesting	O
the	O
connection	O
.	O
</s>
<s>
The	O
behavior	O
of	O
same-origin	B-Protocol
checks	O
and	O
related	O
mechanisms	O
is	O
not	O
well-defined	O
in	O
a	O
number	O
of	O
corner	O
cases	O
such	O
as	O
for	O
pseudo-protocols	O
that	O
do	O
not	O
have	O
a	O
clearly	O
defined	O
host	B-Protocol
name	I-Protocol
or	O
port	O
associated	O
with	O
their	O
URLs	O
(	O
file	O
:	O
,	O
data	O
:	O
,	O
etc	O
.	O
)	O
.	O
</s>
<s>
Lastly	O
,	O
certain	O
types	O
of	O
attacks	O
,	O
such	O
as	O
DNS	O
rebinding	O
or	O
server-side	O
proxies	O
,	O
permit	O
the	O
host	B-Protocol
name	I-Protocol
check	O
to	O
be	O
partly	O
subverted	O
,	O
and	O
make	O
it	O
possible	O
for	O
rogue	O
web	O
pages	O
to	O
directly	O
interact	O
with	O
sites	O
through	O
addresses	O
other	O
than	O
their	O
"	O
true	O
"	O
,	O
canonical	O
origin	O
.	O
</s>
<s>
The	O
impact	O
of	O
such	O
attacks	O
is	O
limited	O
to	O
very	O
specific	O
scenarios	O
,	O
since	O
the	O
browser	O
still	O
believes	O
that	O
it	O
is	O
interacting	O
with	O
the	O
attacker	O
's	O
site	O
,	O
and	O
therefore	O
does	O
not	O
disclose	O
third-party	O
cookies	B-Application
or	O
other	O
sensitive	O
information	O
to	O
the	O
attacker	O
.	O
</s>
<s>
Even	O
when	O
same-origin	B-Protocol
policy	I-Protocol
is	O
in	O
effect	O
(	O
without	O
being	O
relaxed	O
by	O
Cross-Origin	B-General_Concept
Resource	I-General_Concept
Sharing	I-General_Concept
)	O
,	O
certain	O
cross-origin	O
computer	O
attacks	O
can	O
be	O
performed	O
.	O
</s>
<s>
WebRTC	B-Protocol
can	O
be	O
used	O
to	O
find	O
out	O
the	O
internal	O
IP	O
address	O
of	O
a	O
victim	O
.	O
</s>
<s>
If	O
attempting	O
to	O
connect	O
to	O
a	O
cross-origin	O
port	O
,	O
responses	O
cannot	O
be	O
read	O
in	O
face	O
of	O
same-origin	B-Protocol
policy	I-Protocol
,	O
but	O
a	O
JavaScript	B-Language
can	O
still	O
make	O
inferences	O
on	O
whether	O
the	O
port	O
is	O
open	O
or	O
closed	O
by	O
checking	O
if	O
the	O
onload/onerror	O
event	O
fires	O
,	O
or	O
if	O
we	O
get	O
a	O
timeout	O
.	O
</s>
<s>
Further	O
,	O
a	O
JavaScript	B-Language
can	O
even	O
fingerprint	O
services	O
cross-origin	O
by	O
taking	O
advantage	O
of	O
default	O
files	O
.	O
</s>
<s>
For	O
example	O
,	O
if	O
a	O
JavaScript	B-Language
loaded	O
from	O
the	O
site	O
evil.com	O
attempts	O
to	O
open	O
the	O
file	O
,	O
and	O
the	O
onload	O
event	O
fires	O
,	O
then	O
it	O
can	O
be	O
inferred	O
that	O
the	O
victim	O
runs	O
Jenkins	O
on	O
their	O
own	O
computer	O
.	O
</s>
<s>
This	O
way	O
,	O
the	O
attacker	O
can	O
find	O
potentially	O
vulnerable	O
services	O
for	O
example	O
on	O
the	O
internal	O
network	O
,	O
even	O
in	O
face	O
of	O
same-origin	B-Protocol
policy	I-Protocol
.	O
</s>
<s>
Should	O
any	O
service	O
be	O
vulnerable	O
to	O
Cross-site	B-Protocol
Request	I-Protocol
Forgery	I-Protocol
,	O
they	O
can	O
even	O
be	O
compromised	O
.	O
</s>
