Controller for cross-domain iframes added
This commit is contained in:
@ -4,38 +4,49 @@
|
||||
include_once('../include/lucidAuth.functions.php');
|
||||
|
||||
// Start with checking $_REQUEST['ref']
|
||||
// What do we need?
|
||||
// token again?
|
||||
|
||||
// approach 1:
|
||||
// origin domain, so we can intersect with $settings->Session['CookieDomains'] and iterate through the remaining domains, serving them in one page (which contains iframes already)
|
||||
// this might be slower because it means one additional roundtrip between client and server
|
||||
|
||||
// approach 2:
|
||||
// let the client setup multiple iframes for all domains other than origin domains
|
||||
// this requires passing an array of domains to the client in asynchronous reply; which feels insecure
|
||||
|
||||
if (!empty($_REQUEST['ref'])) {
|
||||
try {
|
||||
$queryString = json_decode(base64_decode($_REQUEST['ref']), JSON_OBJECT_AS_ARRAY);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
// Silently fail, unless explicitly specified otherwise
|
||||
header("HTTP/1.1 400 Bad Request");
|
||||
if ($settings->Debug['Verbose']) throw new Exception($e);
|
||||
exit;
|
||||
}
|
||||
|
||||
switch ($queryString['action']) {
|
||||
case 'login':
|
||||
if (validateToken($queryString['token'])['status'] === "Success") {
|
||||
// This request appears valid; store a cookie
|
||||
$httpHost = $_SERVER['HTTP_HOST'];
|
||||
$cookieDomain = array_values(array_filter($settings->Session['CookieDomains'], function ($value) use ($httpHost) {
|
||||
// Check if $_SERVER['HTTP_HOST'] matches any of the configured domains (either explicitly or as a subdomain)
|
||||
// This might seem backwards, but relying on $_SERVER directly allows spoofed values with potential security risks
|
||||
return (strlen($value) > strlen($httpHost)) ? false : (0 === substr_compare($httpHost, $value, -strlen($value)));
|
||||
}))[0];
|
||||
if ($cookieDomain && setcookie('JWT', $queryString['token'], (time() + $settings->Session['Duration']), '/', '.' . $cookieDomain)) {
|
||||
header("HTTP/1.1 202 Accepted");
|
||||
exit;
|
||||
}
|
||||
else {
|
||||
header("HTTP/1.1 400 Bad Request");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
else {
|
||||
header("HTTP/1.1 401 Unauthorized");
|
||||
exit;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
header("HTTP/1.1 400 Bad Request");
|
||||
exit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
include_once('../include/lucidAuth.template.php');
|
||||
|
||||
echo sprintf($pageLayout['bare'],
|
||||
'// iFrames go here'
|
||||
);
|
||||
else {
|
||||
header("HTTP/1.1 400 Bad Request");
|
||||
exit;
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user