mirror of
https://github.com/nextcloud/server.git
synced 2026-06-19 13:39:40 -04:00
feat(ocm-add-share): add validation to detect idn homograph attacks
Signed-off-by: Cristian Scheid <cristianscheid@gmail.com>
This commit is contained in:
parent
5ae0ed355e
commit
b6064a64c1
1 changed files with 22 additions and 0 deletions
|
|
@ -180,6 +180,28 @@ class RequestHandlerController extends Controller {
|
|||
$sharedByDisplayName = $ownerDisplayName;
|
||||
}
|
||||
|
||||
$ownerDomain = str_contains($owner, '@') ? substr(strrchr($owner, '@'), 1) : null;
|
||||
$sharedByDomain = str_contains($sharedBy, '@') ? substr(strrchr($sharedBy, '@'), 1) : null;
|
||||
$domainsToCheck = array_unique(array_filter([$ownerDomain, $sharedByDomain]));
|
||||
if (count($domainsToCheck) !== 0) {
|
||||
$spoofChecker = new \Spoofchecker();
|
||||
foreach ($domainsToCheck as $domain) {
|
||||
// detect suspicious chars (e.g. "pаypаl" spelled with Cyrillic "а" characters)
|
||||
// see https://www.php.net/manual/en/spoofchecker.issuspicious.php
|
||||
if ($spoofChecker->isSuspicious($domain)) {
|
||||
$response = new JSONResponse(
|
||||
[
|
||||
'message' => 'Suspicious domain detected on owner or sharedBy field',
|
||||
'validationErrors' => [],
|
||||
],
|
||||
Http::STATUS_BAD_REQUEST
|
||||
);
|
||||
$response->throttle();
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
|
||||
$share = $this->factory->getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, '', $shareType, $resourceType);
|
||||
|
|
|
|||
Loading…
Reference in a new issue