-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[Security] Add $methods support to #[IsGranted] to restrict access by HTTP method
#61359
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
Merged
fabpot
merged 1 commit into
symfony:7.4
from
santysisi:feature/isgranted-methods-support
Aug 20, 2025
Merged
[Security] Add $methods support to #[IsGranted] to restrict access by HTTP method
#61359
fabpot
merged 1 commit into
symfony:7.4
from
santysisi:feature/isgranted-methods-support
Aug 20, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
santysisi
commented
Aug 7, 2025
Contributor
Author
|
This is not a bug fix. |
66c7bd5 to
4cc3417
Compare
4cc3417 to
739e36e
Compare
Comment on lines
50
to
51
| $methods = array_map('strtoupper', $attribute->methods); | ||
| if ($methods && !\in_array($request->getMethod(), $methods, true)) { |
Member
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
| $methods = array_map('strtoupper', $attribute->methods); | |
| if ($methods && !\in_array($request->getMethod(), $methods, true)) { | |
| if ($attribute->methods && !\in_array($request->getMethod(), array_map('strtoupper', $attribute->methods), true)) { |
nicolas-grekas
approved these changes
Aug 19, 2025
stof
reviewed
Aug 19, 2025
739e36e to
128a973
Compare
…s by HTTP method
128a973 to
68f0fca
Compare
Contributor
Author
|
Hi 👋 Thanks to both of you for the suggestions! |
fabpot
approved these changes
Aug 20, 2025
Member
|
Thank you @santysisi. |
This was referenced Oct 27, 2025
Merged
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds support for restricting
#[IsGranted]validation to specific HTTP methods via a new$methodsargument.What's New
You can now define access control per HTTP method directly in the
#[IsGranted]attribute. This allows greater flexibility when securing controller actions that handle multiple HTTP verbs.This change aligns
#[IsGranted]more closely with other HTTP-aware attributes like:#[IsCsrfTokenValid]#[IsSignatureValid](currently under review)