Skip to content

Commit

Permalink
Merge pull request from GHSA-gmrf-99gw-vvwj
Browse files Browse the repository at this point in the history
Co-authored-by: Bartek Wajda <bartlomiej.wajda@ibexa.co>
  • Loading branch information
glye and barw4 committed Mar 9, 2021
1 parent 45d8f1f commit b496f07
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ parameters:
refreshSession:
mediaType: 'UserSession'
href: 'templateRouter.generate("ezpublish_rest_refreshSession", {sessionId: "{sessionId}"})'

# Boundary times in microseconds which the authentication check will be delayed by.
ezpublish_rest.authentication_min_delay_time: 30000
ezpublish_rest.authentication_max_delay_time: 500000
2 changes: 2 additions & 0 deletions eZ/Bundle/EzPublishRestBundle/Resources/config/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ services:
- "@ezpublish.config.resolver"
- "@session.storage"
- "@?logger"
- "%ezpublish_rest.authentication_min_delay_time%"
- "%ezpublish_rest.authentication_max_delay_time%"
abstract: true

ezpublish_rest.security.authentication.logout_handler:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function createSessionAction(Request $request)
)
);
$request->attributes->set('username', $sessionInput->login);
$request->attributes->set('password', $sessionInput->password);
$request->attributes->set('password', (string) $sessionInput->password);

try {
$session = $request->getSession();
Expand Down
22 changes: 21 additions & 1 deletion eZ/Publish/Core/REST/Server/Security/RestAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
*/
class RestAuthenticator implements ListenerInterface, AuthenticatorInterface
{
const DEFAULT_MIN_SLEEP_VALUE = 30000;

const DEFAULT_MAX_SLEEP_VALUE = 500000;

/** @var \Psr\Log\LoggerInterface */
private $logger;

Expand All @@ -59,14 +63,26 @@ class RestAuthenticator implements ListenerInterface, AuthenticatorInterface
/** @var \Symfony\Component\Security\Http\Logout\LogoutHandlerInterface[] */
private $logoutHandlers = [];

/**
* @var int|null
*/
private $minSleepTime;

/**
* @var int|null
*/
private $maxSleepTime;

public function __construct(
TokenStorageInterface $tokenStorage,
AuthenticationManagerInterface $authenticationManager,
$providerKey,
EventDispatcherInterface $dispatcher,
ConfigResolverInterface $configResolver,
SessionStorageInterface $sessionStorage,
LoggerInterface $logger = null
LoggerInterface $logger = null,
$minSleepTime = self::DEFAULT_MIN_SLEEP_VALUE,
$maxSleepTime = self::DEFAULT_MAX_SLEEP_VALUE
) {
$this->tokenStorage = $tokenStorage;
$this->authenticationManager = $authenticationManager;
Expand All @@ -75,6 +91,8 @@ public function __construct(
$this->configResolver = $configResolver;
$this->sessionStorage = $sessionStorage;
$this->logger = $logger;
$this->minSleepTime = !is_int($minSleepTime) ? self::DEFAULT_MIN_SLEEP_VALUE : $minSleepTime;
$this->maxSleepTime = !is_int($maxSleepTime) ? self::DEFAULT_MAX_SLEEP_VALUE : $maxSleepTime;
}

/**
Expand All @@ -89,6 +107,8 @@ public function handle(GetResponseEvent $event)

public function authenticate(Request $request)
{
usleep(random_int($this->minSleepTime, $this->maxSleepTime));

// If a token already exists and username is the same as the one we request authentication for,
// then return it and mark it as coming from session.
$previousToken = $this->tokenStorage->getToken();
Expand Down

0 comments on commit b496f07

Please sign in to comment.