Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
BARDOT Jérôme
fusiondirectory
Commits
6e31f486
Commit
6e31f486
authored
6 years ago
by
Côme Chilliet
Browse files
Options
Download
Patches
Plain Diff
feat(core) Reject CSRF based on HEADER values
issue #5840
parent
d8dbd130
1.4-fixes
1.3.1-fixes
master
fusiondirectory-1.4
fusiondirectory-1.3.1
fusiondirectory-1.3
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/class_CSRFProtection.inc
+27
-0
include/class_CSRFProtection.inc
with
27 additions
and
0 deletions
+27
-0
include/class_CSRFProtection.inc
+
27
−
0
View file @
6e31f486
...
...
@@ -29,6 +29,8 @@ class CSRFProtection
throw
new
Exception
(
'CSRF protection token missing'
);
}
static
::
checkHeaders
();
$validToken
=
static
::
getToken
();
if
(
$_POST
[
'CSRFtoken'
]
!==
static
::
getToken
())
{
throw
new
Exception
(
'CSRF protection token invalid'
);
...
...
@@ -42,4 +44,29 @@ class CSRFProtection
}
return
session
::
get
(
'CSRFtoken'
);
}
public
static
function
checkHeaders
()
{
$origin
=
FALSE
;
if
(
!
empty
(
$_SERVER
[
'HTTP_ORIGIN'
]))
{
$origin
=
$_SERVER
[
'HTTP_ORIGIN'
];
}
elseif
(
!
empty
(
$_SERVER
[
'HTTP_REFERER'
]))
{
$origin
=
$_SERVER
[
'HTTP_REFERER'
];
}
if
(
$origin
)
{
$origin
=
preg_replace
(
'|^[^/]+://([^/]+)(/.*)?$|'
,
'\1'
,
$origin
);
$target
=
FALSE
;
if
(
!
empty
(
$_SERVER
[
'HTTP_X_FORWARDED_HOST'
]))
{
$target
=
$_SERVER
[
'HTTP_X_FORWARDED_HOST'
];
}
else
if
(
!
empty
(
$_SERVER
[
'HTTP_HOST'
]))
{
$target
=
$_SERVER
[
'HTTP_HOST'
];
}
if
(
$target
)
{
if
(
!
hash_equals
(
$origin
,
$target
))
{
throw
new
Exception
(
'CSRF detected: origin and target are not matching ('
.
$origin
.
' != '
.
$target
.
')'
);
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets