<s>
In	O
computer	O
network	O
security	O
,	O
session	B-Protocol
fixation	I-Protocol
attacks	O
attempt	O
to	O
exploit	O
the	O
vulnerability	O
of	O
a	O
system	O
that	O
allows	O
one	O
person	O
to	O
fixate	O
(	O
find	O
or	O
set	O
)	O
another	O
person	O
's	O
session	B-Protocol
identifier	I-Protocol
.	O
</s>
<s>
Most	O
session	B-Protocol
fixation	I-Protocol
attacks	O
are	O
web	O
based	O
,	O
and	O
most	O
rely	O
on	O
session	B-Protocol
identifiers	I-Protocol
being	O
accepted	O
from	O
URLs	O
(	O
query	B-Protocol
string	I-Protocol
)	O
or	O
POST	O
data	O
.	O
</s>
<s>
Mallory	O
has	O
determined	O
that	O
http://unsafe.example.com/	O
accepts	O
any	O
session	B-Protocol
identifier	I-Protocol
,	O
accepts	O
session	B-Protocol
identifiers	I-Protocol
from	O
query	B-Protocol
strings	I-Protocol
and	O
has	O
no	O
security	O
validation	O
.	O
</s>
<s>
A	O
misconception	O
is	O
that	O
if	O
a	O
server	O
only	O
accepts	O
server-generated	O
session	B-Protocol
identifiers	I-Protocol
,	O
it	O
is	O
safe	O
from	O
fixation	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
server	O
may	O
respond	O
:	O
Set-Cookie	O
:	O
SID	O
=	O
0D6441FEA4496C2	O
.	O
</s>
<s>
Alice	O
logs	O
on	O
,	O
with	O
fixated	O
session	B-Protocol
identifier	I-Protocol
SID	O
=	O
0D6441FEA4496C2	O
.	O
</s>
<s>
This	O
type	O
of	O
attack	O
is	O
similar	O
to	O
a	O
cross-site	O
cookie	B-Application
attack	O
except	O
that	O
,	O
it	O
does	O
not	O
rely	O
on	O
the	O
vulnerability	O
of	O
the	O
user	O
's	O
browser	O
.	O
</s>
<s>
Rather	O
,	O
it	O
relies	O
on	O
the	O
fact	O
that	O
wildcard	O
cookies	B-Application
can	O
be	O
set	O
by	O
a	O
subdomain	O
and	O
,	O
that	O
those	O
cookies	B-Application
may	O
affect	O
other	O
subdomains	O
.	O
</s>
<s>
When	O
Alice	O
visits	O
www.example.com	O
this	O
cookie	B-Application
will	O
be	O
sent	O
with	O
the	O
request	O
and	O
Alice	O
will	O
have	O
the	O
session	O
specified	O
by	O
Mallory	O
's	O
cookie	B-Application
.	O
</s>
<s>
It	O
is	O
not	O
essential	O
that	O
a	O
user	O
login	O
to	O
exploit	O
session	B-Protocol
fixation	I-Protocol
attacks	O
and	O
,	O
although	O
these	O
unauthenticated	O
attacks	O
are	O
not	O
constrained	O
to	O
cross-sub-domain	O
cookie	B-Application
attacks	O
,	O
the	O
implications	O
of	O
sub-domain	O
attacks	O
are	O
relevant	O
to	O
these	O
unauthenticated	O
scenarios	O
.	O
</s>
<s>
Consider	O
,	O
for	O
example	O
,	O
that	O
Mallory	O
may	O
create	O
a	O
user	O
A1ice	O
on	O
www.example.com	O
and	O
login	O
that	O
user	O
to	O
capture	O
a	O
current	O
,	O
valid	O
session	B-Protocol
identifier	I-Protocol
.	O
</s>
<s>
Mallory	O
then	O
entraps	O
Alice	O
with	O
a	O
URL	O
from	O
evil.example.com	O
which	O
fixates	O
that	O
session	O
cookie	B-Application
in	O
Alice	O
's	O
browser	O
(	O
as	O
described	O
above	O
)	O
and	O
redirects	O
to	O
www.example.com	O
for	O
finalizing	O
a	O
particular	O
transaction	O
(	O
or	O
,	O
in	O
fact	O
,	O
broader	O
use	O
)	O
.	O
</s>
<s>
Session	B-Protocol
identifiers	I-Protocol
in	O
URL	O
(	O
query	B-Protocol
string	I-Protocol
,	O
GET	O
variables	O
)	O
or	O
POST	O
variables	O
are	O
not	O
recommended	O
as	O
they	O
simplify	O
this	O
attack	O
it	O
is	O
easy	O
to	O
make	O
links	O
or	O
forms	O
that	O
set	O
GET	O
/	O
POST	O
variables	O
.	O
</s>
<s>
Note	O
:	O
Cookies	B-Application
are	O
shared	O
between	O
tabs	O
and	O
popped	O
up	O
browser	O
windows	O
.	O
</s>
<s>
If	O
your	O
system	O
requires	O
to	O
be	O
hit	O
with	O
the	O
same	O
domain	O
(	O
www.example.com/?code=site1	O
and	O
www.example.com/?code=site2	O
)	O
,	O
cookies	B-Application
may	O
conflict	O
with	O
one	O
another	O
between	O
tabs	O
.	O
</s>
<s>
It	O
may	O
be	O
required	O
to	O
send	O
the	O
session	B-Protocol
identifier	I-Protocol
on	O
the	O
URL	O
in	O
order	O
to	O
overcome	O
this	O
limitation	O
.	O
</s>
<s>
If	O
possible	O
use	O
site1.example.com	O
or	O
site2.example.com	O
so	O
there	O
is	O
no	O
domain	O
conflicts	O
in	O
the	O
cookies	B-Application
.	O
</s>
<s>
This	O
attack	O
can	O
be	O
largely	O
avoided	O
by	O
changing	O
the	O
session	B-Protocol
ID	I-Protocol
when	O
users	O
log	O
in	O
.	O
</s>
<s>
When	O
the	O
victim	O
visits	O
the	O
link	O
with	O
the	O
fixed	O
session	B-Protocol
id	I-Protocol
,	O
however	O
,	O
they	O
will	O
need	O
to	O
log	O
into	O
their	O
account	O
in	O
order	O
to	O
do	O
anything	O
"	O
important	O
"	O
as	O
themselves	O
.	O
</s>
<s>
At	O
this	O
point	O
,	O
their	O
session	B-Protocol
id	I-Protocol
will	O
change	O
,	O
and	O
the	O
attacker	O
will	O
not	O
be	O
able	O
to	O
do	O
anything	O
"	O
important	O
"	O
with	O
the	O
anonymous	O
session	B-Protocol
ID	I-Protocol
.	O
</s>
<s>
This	O
technique	O
is	O
also	O
useful	O
against	O
cross-site	B-Protocol
request	I-Protocol
forgery	I-Protocol
attacks	O
.	O
</s>
<s>
The	O
session	B-Protocol
identifier	I-Protocol
on	O
most	O
modern	O
systems	O
is	O
stored	O
by	O
default	O
in	O
an	O
HTTP	B-Application
cookie	I-Application
,	O
which	O
has	O
a	O
moderate	O
level	O
of	O
security	O
as	O
long	O
as	O
the	O
session	O
system	O
disregards	O
GET/POST	O
values	O
.	O
</s>
<s>
However	O
,	O
this	O
solution	O
is	O
vulnerable	O
to	O
cross-site	B-Protocol
request	I-Protocol
forgery	I-Protocol
,	O
and	O
it	O
does	O
not	O
meet	O
the	O
statelessness	O
requirement	O
of	O
REST	O
.	O
</s>
<s>
When	O
enabling	O
HTTPS	B-Protocol
security	O
,	O
some	O
systems	O
allow	O
applications	O
to	O
obtain	O
the	O
SSL	B-Protocol
/	I-Protocol
TLS	I-Protocol
session	B-Protocol
identifier	I-Protocol
.	O
</s>
<s>
Use	O
of	O
the	O
SSL/TLS	B-Protocol
session	B-Protocol
identifier	I-Protocol
is	O
very	O
secure	O
,	O
but	O
many	O
web	O
development	O
languages	O
do	O
not	O
provide	O
robust	O
built-in	O
functionality	O
for	O
this	O
.	O
</s>
<s>
A	O
countermeasure	O
against	O
session	B-Protocol
fixation	I-Protocol
is	O
to	O
generate	O
a	O
new	O
session	B-Protocol
identifier	I-Protocol
(	O
SID	O
)	O
on	O
each	O
request	O
.	O
</s>
<s>
Get	O
previous	O
Session	B-Protocol
Identifier	I-Protocol
OLD_SID	O
from	O
HTTP	B-Protocol
request	O
.	O
</s>
<s>
Generate	O
new	O
session	B-Protocol
identifier	I-Protocol
NEW_SID	O
with	O
a	O
secure	O
random	O
number	O
generator	O
.	O
</s>
<s>
If	O
Mallory	O
successfully	O
tricks	O
Alice	O
into	O
visiting	O
http://victim.example.com/?SID=I_KNOW_THE_SID	O
,	O
this	O
HTTP	B-Protocol
request	O
is	O
sent	O
to	O
victim.example.com	O
:	O
</s>
<s>
Mallory	O
is	O
thus	O
unsuccessful	O
in	O
the	O
session	B-Protocol
fixation	I-Protocol
attempt	O
.	O
</s>
<s>
If	O
the	O
implementation	O
of	O
sessions	O
includes	O
transmitting	O
the	O
SID	O
through	O
GET	O
or	O
POST	O
variables	O
,	O
then	O
this	O
might	O
also	O
render	O
the	O
"	O
back	O
"	O
button	O
in	O
most	O
browsers	O
unusable	O
,	O
as	O
the	O
user	O
would	O
then	O
be	O
using	O
an	O
older	O
,	O
invalid	O
,	O
session	B-Protocol
identifier	I-Protocol
from	O
a	O
previous	O
request	O
.	O
</s>
<s>
One	O
way	O
to	O
improve	O
security	O
is	O
not	O
to	O
accept	O
session	B-Protocol
identifiers	I-Protocol
that	O
were	O
not	O
generated	O
by	O
the	O
server	O
.	O
</s>
<s>
However	O
,	O
as	O
noted	O
above	O
,	O
this	O
does	O
not	O
prevent	O
all	O
session	B-Protocol
fixation	I-Protocol
attacks	O
.	O
</s>
<s>
Note	O
that	O
the	O
following	O
code	O
performs	O
no	O
Cross-site	B-Protocol
request	I-Protocol
forgery	I-Protocol
checks	O
,	O
potentially	O
allowing	O
an	O
attacker	O
to	O
force	O
users	O
to	O
log	O
out	O
of	O
the	O
web	O
application	O
.	O
</s>
<s>
When	O
visiting	O
a	O
page	O
,	O
most	O
web	O
browsers	O
will	O
set	O
the	O
Referrer	B-Protocol
header	I-Protocol
the	O
page	O
that	O
contained	O
the	O
link	O
that	O
you	O
followed	O
to	O
get	O
to	O
this	O
page	O
.	O
</s>
<s>
When	O
the	O
user	O
is	O
logged	O
into	O
a	O
site	O
that	O
is	O
not	O
likely	O
to	O
be	O
linked	O
to	O
from	O
outside	O
that	O
site	O
(	O
e.g.	O
,	O
banking	O
websites	O
,	O
or	O
webmail	B-Protocol
)	O
,	O
and	O
the	O
site	O
is	O
not	O
the	O
kind	O
of	O
site	O
where	O
users	O
would	O
remain	O
logged	O
in	O
for	O
any	O
great	O
length	O
of	O
time	O
,	O
the	O
Referrer	B-Protocol
should	O
be	O
from	O
that	O
site	O
.	O
</s>
<s>
Any	O
other	O
Referrer	B-Protocol
should	O
be	O
considered	O
suspicious	O
.	O
</s>
<s>
However	O
,	O
if	O
the	O
originating	O
request	O
is	O
from	O
a	O
HTTPS	B-Protocol
page	O
,	O
then	O
the	O
referrer	B-Protocol
will	O
be	O
stripped	O
,	O
so	O
you	O
cannot	O
depend	O
on	O
this	O
security	O
system	O
.	O
</s>
<s>
This	O
makes	O
it	O
a	O
bit	O
harder	O
to	O
perform	O
session	B-Protocol
fixation	I-Protocol
and	O
other	O
attacks	O
.	O
</s>
<s>
As	O
more	O
and	O
more	O
networks	O
begin	O
to	O
conform	O
to	O
RFC	O
3704	O
and	O
other	O
anti-spoofing	O
practices	O
,	O
the	O
IP	B-Protocol
address	I-Protocol
becomes	O
more	O
reliable	O
as	O
a	O
"	O
same	O
source	O
"	O
identifier	O
.	O
</s>
<s>
Therefore	O
,	O
the	O
security	O
of	O
a	O
web	O
site	O
can	O
be	O
improved	O
by	O
verifying	O
that	O
the	O
source	O
IP	B-Protocol
address	I-Protocol
is	O
consistent	O
throughout	O
a	O
session	O
.	O
</s>
<s>
Several	O
users	O
may	O
share	O
one	O
IP	B-Protocol
address	I-Protocol
.	O
</s>
<s>
It	O
is	O
not	O
uncommon	O
for	O
an	O
entire	O
building	O
to	O
share	O
one	O
IP	B-Protocol
address	I-Protocol
using	O
NAT	B-Protocol
.	O
</s>
<s>
One	O
user	O
may	O
have	O
an	O
inconsistent	O
IP	B-Protocol
address	I-Protocol
.	O
</s>
<s>
Browsers	O
identify	O
themselves	O
by	O
"	O
User-Agent	O
"	O
HTTP	B-Protocol
headers	O
.	O
</s>
<s>
HTTP	B-Protocol
referrers	I-Protocol
are	O
not	O
passed	O
with	O
SSL/TLS	B-Protocol
(	O
HTTPS	B-Protocol
)	O
.	O
</s>
<s>
Note	O
that	O
this	O
code	O
checks	O
the	O
current	O
REMOTE_ADDR	O
(	O
the	O
user	O
's	O
IP	B-Protocol
address	I-Protocol
)	O
and	O
User-agent	O
against	O
the	O
REMOTE_ADDR	O
and	O
User-agent	O
of	O
the	O
previous	O
request	O
.	O
</s>
