Skip to content

Commit

Permalink
Fix BackURL redirect with strict or lax session cookie security.
Browse files Browse the repository at this point in the history
Should fix silverstripe#45
  • Loading branch information
mateusz committed Jan 10, 2024
1 parent 89e10e7 commit 79d866c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Control/SAMLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ protected function getRedirect()
return $this->redirect($this->getRequest()->getSession()->get('BackURL'));
}

// In SAMLHelper, we pass the BackURL to be returned to us in RelayState.
// If only assertion is signed, RelayState cannot be trusted. Prevent open relay
// as in // https://github.com/SAML-Toolkits/php-saml#avoiding-open-redirect-attacks
$relayState = $this->owner->getRequest()->postVar('RelayState');
if ($relayState && Director::is_site_url($relayState)) {
$this->redirect($relayState);
}

// Spoofing attack, redirect to homepage instead of spoofing url
if ($back && !Director::is_site_url($back)) {
return $this->redirect(Director::absoluteBaseURL());
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/SAMLHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function redirect(RequestHandler $requestHandler = null, HTTPRequest $req
$additionalGetQueryParams = $this->getAdditionalGETQueryParameters();

try {
$auth->login(Director::absoluteBaseURL() . 'saml/', $additionalGetQueryParams);
$auth->login($backURL, $additionalGetQueryParams);
} catch (Exception $e) {
/** @var LoggerInterface $logger */
$logger = Injector::inst()->get(LoggerInterface::class);
Expand Down

0 comments on commit 79d866c

Please sign in to comment.