Skip to content

Commit 7fafe69

Browse files
committed
drop the ability to configure a signer with the IsSignatureValid attribute
1 parent 4d58fa7 commit 7fafe69

File tree

9 files changed

+11
-123
lines changed

9 files changed

+11
-123
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ CHANGELOG
1111
* Add `assertEmailAddressNotContains()` to the `MailerAssertionsTrait`
1212
* Add `framework.type_info.aliases` option
1313
* Add `KernelBrowser::getSession()`
14-
* Add autoconfiguration tag `kernel.uri_signer` to `Symfony\Component\HttpFoundation\UriSigner`
1514
* Add support for configuring workflow places with glob patterns matching consts/backed enums
1615

1716
7.3

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class UnusedTagsPass implements CompilerPassInterface
6161
'kernel.fragment_renderer',
6262
'kernel.locale_aware',
6363
'kernel.reset',
64-
'kernel.uri_signer',
6564
'ldap',
6665
'mailer.transport_factory',
6766
'messenger.bus',

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
use Symfony\Component\HttpClient\ThrottlingHttpClient;
102102
use Symfony\Component\HttpClient\UriTemplateHttpClient;
103103
use Symfony\Component\HttpFoundation\Request;
104-
use Symfony\Component\HttpFoundation\UriSigner;
105104
use Symfony\Component\HttpKernel\Attribute\AsController;
106105
use Symfony\Component\HttpKernel\Attribute\AsTargetedValueResolver;
107106
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
@@ -767,8 +766,6 @@ public function load(array $configs, ContainerBuilder $container): void
767766
->addTag('mime.mime_type_guesser');
768767
$container->registerForAutoconfiguration(LoggerAwareInterface::class)
769768
->addMethodCall('setLogger', [new Reference('logger')]);
770-
$container->registerForAutoconfiguration(UriSigner::class)
771-
->addTag('kernel.uri_signer');
772769

773770
$container->registerAttributeForAutoconfiguration(AsEventListener::class, static function (ChildDefinition $definition, AsEventListener $attribute, \ReflectionClass|\ReflectionMethod $reflector) {
774771
$tagAttributes = get_object_vars($attribute);

src/Symfony/Bundle/FrameworkBundle/Resources/config/web.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@
152152
->set('controller.is_signature_valid_attribute_listener', IsSignatureValidAttributeListener::class)
153153
->args([
154154
service('uri_signer'),
155-
tagged_locator('kernel.uri_signer'),
156155
])
157156
->tag('kernel.event_subscriber')
158157

src/Symfony/Component/HttpKernel/Attribute/IsSignatureValid.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,13 @@ final class IsSignatureValid
2929
{
3030
/** @var string[] */
3131
public readonly array $methods;
32-
public readonly ?string $signer;
3332

3433
/**
3534
* @param string[]|string $methods HTTP methods that require signature validation. An empty array means that no method filtering is done
36-
* @param string $signer The ID of the UriSigner service to use for signature validation. Defaults to 'uri_signer'
3735
*/
3836
public function __construct(
3937
array|string $methods = [],
40-
?string $signer = null,
4138
) {
4239
$this->methods = (array) $methods;
43-
$this->signer = $signer;
4440
}
4541
}

src/Symfony/Component/HttpKernel/EventListener/IsSignatureValidAttributeListener.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\HttpKernel\EventListener;
1313

14-
use Psr\Container\ContainerInterface;
1514
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1615
use Symfony\Component\HttpFoundation\UriSigner;
1716
use Symfony\Component\HttpKernel\Attribute\IsSignatureValid;
@@ -27,7 +26,6 @@ class IsSignatureValidAttributeListener implements EventSubscriberInterface
2726
{
2827
public function __construct(
2928
private readonly UriSigner $uriSigner,
30-
private readonly ContainerInterface $container,
3129
) {
3230
}
3331

@@ -44,17 +42,7 @@ public function onKernelControllerArguments(ControllerArgumentsEvent $event): vo
4442
continue;
4543
}
4644

47-
if (null === $attribute->signer) {
48-
$this->uriSigner->verify($request);
49-
continue;
50-
}
51-
52-
$signer = $this->container->get($attribute->signer);
53-
if (!$signer instanceof UriSigner) {
54-
throw new \LogicException(\sprintf('The service "%s" is not an instance of "%s".', $attribute->signer, UriSigner::class));
55-
}
56-
57-
$signer->verify($request);
45+
$this->uriSigner->verify($request);
5846
}
5947
}
6048

src/Symfony/Component/HttpKernel/Tests/EventListener/IsSignatureValidAttributeListenerTest.php

Lines changed: 10 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,16 @@
1111

1212
namespace Symfony\Component\HttpKernel\Tests\EventListener;
1313

14-
use PHPUnit\Framework\Attributes\RequiresMethod;
1514
use PHPUnit\Framework\TestCase;
16-
use Psr\Container\ContainerInterface;
1715
use Symfony\Component\HttpFoundation\Exception\UnsignedUriException;
1816
use Symfony\Component\HttpFoundation\Request;
1917
use Symfony\Component\HttpFoundation\UriSigner;
2018
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
2119
use Symfony\Component\HttpKernel\EventListener\IsSignatureValidAttributeListener;
2220
use Symfony\Component\HttpKernel\HttpKernelInterface;
23-
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtendedSigner;
2421
use Symfony\Component\HttpKernel\Tests\Fixtures\IsSignatureValidAttributeController;
2522
use Symfony\Component\HttpKernel\Tests\Fixtures\IsSignatureValidAttributeMethodsController;
2623

27-
#[RequiresMethod(UriSigner::class, 'verify')]
2824
class IsSignatureValidAttributeListenerTest extends TestCase
2925
{
3026
public function testInvokableControllerWithValidSignature()
@@ -34,8 +30,6 @@ public function testInvokableControllerWithValidSignature()
3430
$signer = $this->createMock(UriSigner::class);
3531
$signer->expects($this->once())->method('verify')->with($request);
3632
$kernel = $this->createMock(HttpKernelInterface::class);
37-
$container = $this->createMock(ContainerInterface::class);
38-
$container->expects($this->never())->method('get');
3933

4034
$event = new ControllerArgumentsEvent(
4135
$kernel,
@@ -45,16 +39,15 @@ public function testInvokableControllerWithValidSignature()
4539
null
4640
);
4741

48-
$listener = new IsSignatureValidAttributeListener($signer, $container);
42+
$listener = new IsSignatureValidAttributeListener($signer);
4943
$listener->onKernelControllerArguments($event);
5044
}
5145

5246
public function testNoAttributeSkipsValidation()
5347
{
5448
$kernel = $this->createMock(HttpKernelInterface::class);
5549
$signer = $this->createMock(UriSigner::class);
56-
$container = $this->createMock(ContainerInterface::class);
57-
$container->expects($this->never())->method('get');
50+
$signer->expects($this->never())->method('verify');
5851

5952
$event = new ControllerArgumentsEvent(
6053
$kernel,
@@ -64,7 +57,7 @@ public function testNoAttributeSkipsValidation()
6457
null
6558
);
6659

67-
$listener = new IsSignatureValidAttributeListener($signer, $container);
60+
$listener = new IsSignatureValidAttributeListener($signer);
6861
$listener->onKernelControllerArguments($event);
6962
}
7063

@@ -74,8 +67,6 @@ public function testDefaultCheckRequestSucceeds()
7467
$signer = $this->createMock(UriSigner::class);
7568
$signer->expects($this->once())->method('verify')->with($request);
7669
$kernel = $this->createMock(HttpKernelInterface::class);
77-
$container = $this->createMock(ContainerInterface::class);
78-
$container->expects($this->never())->method('get');
7970

8071
$event = new ControllerArgumentsEvent(
8172
$kernel,
@@ -85,7 +76,7 @@ public function testDefaultCheckRequestSucceeds()
8576
null
8677
);
8778

88-
$listener = new IsSignatureValidAttributeListener($signer, $container);
79+
$listener = new IsSignatureValidAttributeListener($signer);
8980
$listener->onKernelControllerArguments($event);
9081
}
9182

@@ -95,8 +86,6 @@ public function testCheckRequestFailsThrowsHttpException()
9586
$signer = $this->createMock(UriSigner::class);
9687
$signer->expects($this->once())->method('verify')->willThrowException(new UnsignedUriException());
9788
$kernel = $this->createMock(HttpKernelInterface::class);
98-
$container = $this->createMock(ContainerInterface::class);
99-
$container->expects($this->never())->method('get');
10089

10190
$event = new ControllerArgumentsEvent(
10291
$kernel,
@@ -106,7 +95,7 @@ public function testCheckRequestFailsThrowsHttpException()
10695
null
10796
);
10897

109-
$listener = new IsSignatureValidAttributeListener($signer, $container);
98+
$listener = new IsSignatureValidAttributeListener($signer);
11099

111100
$this->expectException(UnsignedUriException::class);
112101
$listener->onKernelControllerArguments($event);
@@ -119,8 +108,6 @@ public function testMultipleAttributesAllValid()
119108
$signer = $this->createMock(UriSigner::class);
120109
$signer->expects($this->exactly(2))->method('verify')->with($request);
121110
$kernel = $this->createMock(HttpKernelInterface::class);
122-
$container = $this->createMock(ContainerInterface::class);
123-
$container->expects($this->never())->method('get');
124111

125112
$event = new ControllerArgumentsEvent(
126113
$kernel,
@@ -130,7 +117,7 @@ public function testMultipleAttributesAllValid()
130117
null
131118
);
132119

133-
$listener = new IsSignatureValidAttributeListener($signer, $container);
120+
$listener = new IsSignatureValidAttributeListener($signer);
134121
$listener->onKernelControllerArguments($event);
135122
}
136123

@@ -141,8 +128,6 @@ public function testValidationWithStringMethod()
141128
$signer = $this->createMock(UriSigner::class);
142129
$signer->expects($this->once())->method('verify')->with($request);
143130
$kernel = $this->createMock(HttpKernelInterface::class);
144-
$container = $this->createMock(ContainerInterface::class);
145-
$container->expects($this->never())->method('get');
146131

147132
$event = new ControllerArgumentsEvent(
148133
$kernel,
@@ -152,7 +137,7 @@ public function testValidationWithStringMethod()
152137
null
153138
);
154139

155-
$listener = new IsSignatureValidAttributeListener($signer, $container);
140+
$listener = new IsSignatureValidAttributeListener($signer);
156141
$listener->onKernelControllerArguments($event);
157142
}
158143

@@ -163,8 +148,6 @@ public function testValidationWithArrayMethods()
163148
$signer = $this->createMock(UriSigner::class);
164149
$signer->expects($this->once())->method('verify')->with($request);
165150
$kernel = $this->createMock(HttpKernelInterface::class);
166-
$container = $this->createMock(ContainerInterface::class);
167-
$container->expects($this->never())->method('get');
168151

169152
$event = new ControllerArgumentsEvent(
170153
$kernel,
@@ -174,7 +157,7 @@ public function testValidationWithArrayMethods()
174157
null
175158
);
176159

177-
$listener = new IsSignatureValidAttributeListener($signer, $container);
160+
$listener = new IsSignatureValidAttributeListener($signer);
178161
$listener->onKernelControllerArguments($event);
179162
}
180163

@@ -184,8 +167,7 @@ public function testValidationSkippedForNonMatchingMethod()
184167

185168
$kernel = $this->createMock(HttpKernelInterface::class);
186169
$signer = $this->createMock(UriSigner::class);
187-
$container = $this->createMock(ContainerInterface::class);
188-
$container->expects($this->never())->method('get');
170+
$signer->expects($this->never())->method('verify');
189171

190172
$event = new ControllerArgumentsEvent(
191173
$kernel,
@@ -195,51 +177,7 @@ public function testValidationSkippedForNonMatchingMethod()
195177
null
196178
);
197179

198-
$listener = new IsSignatureValidAttributeListener($signer, $container);
199-
$listener->onKernelControllerArguments($event);
200-
}
201-
202-
public function testValidationWithSigner()
203-
{
204-
$request = new Request();
205-
$signer = $this->createMock(UriSigner::class);
206-
$customSigner = $this->createMock(UriSigner::class);
207-
$customSigner->expects($this->once())->method('verify')->with($request);
208-
$kernel = $this->createMock(HttpKernelInterface::class);
209-
$container = $this->createMock(ContainerInterface::class);
210-
$container->expects($this->once())->method('get')->with('app.test.signer')->willReturn($customSigner);
211-
212-
$event = new ControllerArgumentsEvent(
213-
$kernel,
214-
[new IsSignatureValidAttributeMethodsController(), 'withCustomSigner'],
215-
[],
216-
$request,
217-
null
218-
);
219-
220-
$listener = new IsSignatureValidAttributeListener($signer, $container);
221-
$listener->onKernelControllerArguments($event);
222-
}
223-
224-
public function testValidationWithExtendedSigner()
225-
{
226-
$request = new Request();
227-
$signer = $this->createMock(UriSigner::class);
228-
$extendedSigner = $this->createMock(ExtendedSigner::class);
229-
$extendedSigner->expects($this->once())->method('verify')->with($request);
230-
$kernel = $this->createMock(HttpKernelInterface::class);
231-
$container = $this->createMock(ContainerInterface::class);
232-
$container->expects($this->once())->method('get')->with('app.test.extended_signer')->willReturn($extendedSigner);
233-
234-
$event = new ControllerArgumentsEvent(
235-
$kernel,
236-
[new IsSignatureValidAttributeMethodsController(), 'withCustomExtendedSigner'],
237-
[],
238-
$request,
239-
null
240-
);
241-
242-
$listener = new IsSignatureValidAttributeListener($signer, $container);
180+
$listener = new IsSignatureValidAttributeListener($signer);
243181
$listener->onKernelControllerArguments($event);
244182
}
245183
}

src/Symfony/Component/HttpKernel/Tests/Fixtures/ExtendedSigner.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/Symfony/Component/HttpKernel/Tests/Fixtures/IsSignatureValidAttributeMethodsController.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,4 @@ public function withPostOnly()
3939
public function withGetAndPost()
4040
{
4141
}
42-
43-
#[IsSignatureValid(signer: 'app.test.signer')]
44-
public function withCustomSigner()
45-
{
46-
}
47-
48-
#[IsSignatureValid(signer: 'app.test.extended_signer')]
49-
public function withCustomExtendedSigner()
50-
{
51-
}
5242
}

0 commit comments

Comments
 (0)