Files
Heimdall/vendor/aws/aws-sdk-php/src/Auth/AuthSelectionMiddleware.php
T
KodeStar f69cbba6cd Update dependencies flagged by security advisories and require PHP 8.4
Bumps the packages reported by CVE/GHSA scans in #1564 to their patched
releases (with transitive dependencies):

- symfony/http-foundation 7.3.1 -> 7.4.14 (CVE-2025-64500 / GHSA-3rg7-wf37-54rm)
- phpunit/phpunit 10.5.47 -> 10.5.64 (CVE-2026-24765 / GHSA-vvj3-c3rp-c85p)
- aws/aws-sdk-php 3.349.3 -> 3.388.0 (GHSA-27qh-8cxx-2cr5)
- enshrined/svg-sanitize 0.21.0 -> 0.22.0 (GHSA-22wq-q86m-83fh)

Some transitive dependencies now require PHP 8.4, which matches the runtime
shipped in the official LinuxServer image, so the composer requirement is
raised to ^8.4, CI is pinned to PHP 8.4, and the readme is updated to match.

The remaining advisories in the report (php84, curl, libpq, git, sqlite,
busybox, coreutils) come from the LinuxServer base image, not this
repository, and are addressed by rebuilding the image on an updated base.

Refs #1564
2026-07-08 16:30:22 +01:00

160 lines
5.0 KiB
PHP

<?php
namespace Aws\Auth;
use Aws\Api\Service;
use Aws\Auth\Exception\UnresolvedAuthSchemeException;
use Aws\CommandInterface;
use Closure;
use GuzzleHttp\Promise\Promise;
/**
* Handles auth scheme resolution. If a service models and auth scheme using
* the `auth` trait and the operation or metadata levels, this middleware will
* attempt to select the first compatible auth scheme it encounters and apply its
* signature version to the command's `@context` property bag.
*
* IMPORTANT: this middleware must be added to the "build" step.
*
* @internal
*/
class AuthSelectionMiddleware
{
/** @var callable */
private $nextHandler;
/** @var AuthSchemeResolverInterface */
private $authResolver;
/** @var Service */
private $api;
/** @var array|null */
private ?array $configuredAuthSchemes;
/**
* Create a middleware wrapper function
*
* @param AuthSchemeResolverInterface $authResolver
* @param Service $api
* @param array|null $configuredAuthSchemes
*
* @return Closure
*/
public static function wrap(
AuthSchemeResolverInterface $authResolver,
Service $api,
?array $configuredAuthSchemes
): Closure
{
return function (callable $handler) use (
$authResolver,
$api,
$configuredAuthSchemes
) {
return new self($handler, $authResolver, $api, $configuredAuthSchemes);
};
}
/**
* @param callable $nextHandler
* @param AuthSchemeResolverInterface $authResolver
* @param Service $api
* @param array|null $configuredAuthSchemes
*/
public function __construct(
callable $nextHandler,
AuthSchemeResolverInterface $authResolver,
Service $api,
?array $configuredAuthSchemes = null
)
{
$this->nextHandler = $nextHandler;
$this->authResolver = $authResolver;
$this->api = $api;
$this->configuredAuthSchemes = $configuredAuthSchemes;
}
/**
* @param CommandInterface $command
*
* @return Promise
*/
public function __invoke(CommandInterface $command)
{
$nextHandler = $this->nextHandler;
$serviceAuth = $this->api->getMetadata('auth') ?: [];
$operation = $this->api->getOperation($command->getName());
$operationAuth = $operation['auth'] ?? [];
$unsignedPayload = $operation['unsignedpayload'] ?? false;
$resolvableAuth = $operationAuth ?: $serviceAuth;
if (!empty($resolvableAuth)) {
if (isset($command['@context']['auth_scheme_resolver'])
&& $command['@context']['auth_scheme_resolver'] instanceof AuthSchemeResolverInterface
){
$resolver = $command['@context']['auth_scheme_resolver'];
} else {
$resolver = $this->authResolver;
}
try {
$authSchemeList = $this->buildAuthSchemeList(
$resolvableAuth,
$command['@context']['auth_scheme_preference']
?? null,
);
$selectedAuthScheme = $resolver->selectAuthScheme(
$authSchemeList,
['unsigned_payload' => $unsignedPayload]
);
if (!empty($selectedAuthScheme)) {
$command['@context']['signature_version'] = $selectedAuthScheme;
}
} catch (UnresolvedAuthSchemeException $ignored) {
// There was an error resolving auth
// The signature version will fall back to the modeled `signatureVersion`
// or auth schemes resolved during endpoint resolution
}
}
return $nextHandler($command);
}
/**
* Prioritizes auth schemes according to user preference order.
* User-preferred schemes that are available will be placed first,
* followed by remaining available schemes.
*
* @param array $resolvableAuthSchemeList Available auth schemes
* @param array|null $commandConfiguredAuthSchemes Command-level preferences (overrides config)
*
* @return array Reordered auth schemes with user preferences first
*/
private function buildAuthSchemeList(
array $resolvableAuthSchemeList,
?array $commandConfiguredAuthSchemes,
): array
{
$userConfiguredAuthSchemes = $commandConfiguredAuthSchemes
?? $this->configuredAuthSchemes;
if (empty($userConfiguredAuthSchemes)) {
return $resolvableAuthSchemeList;
}
$prioritizedAuthSchemes = array_intersect(
$userConfiguredAuthSchemes,
$resolvableAuthSchemeList
);
// Get remaining schemes not in user preferences
$remainingAuthSchemes = array_diff(
$resolvableAuthSchemeList,
$prioritizedAuthSchemes
);
return array_merge($prioritizedAuthSchemes, $remainingAuthSchemes);
}
}