Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] check if openididentifier exists before emtit external call #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion Classes/OpenidService.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public function processLoginData(array &$loginData, $passwordTransmissionStrateg
$loginData['uident_openid'] = $this->normalizeOpenID($loginData['uname']);
$isProcessed = true;
}
$this->isValidOpenID($loginData['uident_openid']);
} catch (\Exception $exception) {
$this->logger->error(
sprintf('[%d] "%s" %s',
Expand Down Expand Up @@ -217,7 +218,20 @@ public function getUser()
}
}
} elseif (!empty($this->loginData['uident_openid'])) {
$this->sendOpenIDRequest($this->loginData['uident_openid']);
try {
$this->isValidOpenID($this->loginData['uident_openid']);
$this->sendOpenIDRequest($this->loginData['uident_openid']);
} catch (Exception $exception) {
// This should never happen and generally means hack attempt.
// We just log it and do not return any records.
$this->logger->error(
sprintf('[%d] "%s" %s',
$exception->getCode(),
$exception->getMessage(),
$exception->getTraceAsString()
)
);
}
}
return $userRecord;
}
Expand Down Expand Up @@ -492,6 +506,35 @@ protected function getSignature($parameter)
return GeneralUtility::hmac($parameter, $this->extKey);
}

/**
* Checks if openIDIdentifier belongs to any user in the system.
* Used to prevent a server side request forgery attack.
*
* @param string $openIDIdentifier OpenID identifier to check
* @return void
* @throws Exception
*/
protected function isValidOpenID($openIDIdentifier)
{
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->authenticationInformation['db_user']['table']);
$queryBuilder->getRestrictions()->removeAll();
$row = $queryBuilder
->select('tx_openid_openid')
->from($this->authenticationInformation['db_user']['table'])
->where(
$queryBuilder->expr()->eq('tx_openid_openid', $queryBuilder->createNamedParameter($openIDIdentifier))
)
->execute()
->fetch();

if (!is_array($row)) {
// This only happens when the OpenIdentifier not valid for the local system
throw new Exception('Trying to authenticate with OpenID but identifier is neither found in a user record.', 1662578993);
}
}


/**
* Implement normalization according to OpenID 2.0 specification
* See http://openid.net/specs/openid-authentication-2_0.html#normalization
Expand Down