8000 [HttpFoundation] `#[IsSignatureValid]` attribute by santysisi · Pull Request #60395 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpFoundation] #[IsSignatureValid] attribute #60395

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

Open
wants to merge 1 commit into
base: 7.3
Choose a base branch
from

Conversation

santysisi
Copy link
Contributor
@santysisi santysisi commented May 9, 2025
Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
Issues Feature #60189
License MIT

✨ New Feature: #[IsSignatureValid] Attribute

This attribute simplifies signature verification by applying it declaratively at the controller level.

✅ Usage Examples

#[IsSignatureValid] // Default behavior: returns 404 on failure
public function someAction(): Response
#[IsSignatureValid(validationFailedStatusCode: 401)] // Customize failure status code
public function someAction(): Response

🔥 Advanced Usage (with #60102)

When throw: true is passed, exceptions are thrown instead of returning responses directly:

#[IsSignatureValid(throw: true)]
public function someAction(): Response

@santysisi santysisi requested a review from chalasr as a code owner May 9, 2025 21:24
@carsonbot carsonbot added this to the 7.3 milestone May 9, 2025
@santysisi santysisi force-pushed the feature/verify-signature-attribute branch 5 times, most recently from 4730169 to c72ef83 Compare May 9, 2025 22:27
@santysisi
Copy link
Contributor Author
santysisi commented May 9, 2025

Hi 👋
I'll update this version 7.3 to 7.4 once the new minor dev version is released.

Edit: I updated this version to 7.3 because I need this method from UriSigner.


public static function getSubscribedEvents(): array
{
return [KernelEvents::CONTROLLER_ARGUMENTS => ['onKernelControllerArguments', 30]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this 30 why this value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @94noni , thanks for your comment! ❤️

I set the priority to 30 because I want the IsSignatureValid validation to be executed first, before IsCsrfTokenValidAttributeListener and IsGrantedAttributeListener.
But maybe I'm wrong, and one of those validations should actually run first, please let me know if the priority needs to be changed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont know on my side the proper priority but I wanted to know why you chose 30 that all
hope other review will confirm this choice :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • IsCsrfTokenValidAttributeListener: priority 25
  • IsGrantedAttributeListener: priority 20

30 makes sense to me if we want it run first, which I think we do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I too think it should run before any auth-related check that might open a session.

@kbond
Copy link
Member
kbond commented May 12, 2025

This is looking great @santysisi! I'll give it a more thorough review after 7.3 is released.

@santysisi santysisi force-pushed the feature/verify-signature-attribute branch from c72ef83 to 85320cf Compare May 18, 2025 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0