Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Security] Make request always available to#[IsGranted]#48080

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@HypeMC
Copy link
Member

QA
Branch?6.2
Bug fix?no
New feature?yes
Deprecations?no
TicketsFix#48071 (comment)
LicenseMIT
Doc PR-

Currently, the request is only available to the#[IsGranted] attribute when it's a controller argument, eg:

#[IsGranted(attribute:'SOME_ATTRIBUTE', subject:'request')]publicfunctionindex(Request$request){}#[IsGranted(    attribute:'SOME_ATTRIBUTE',    subject:newExpression('args["request"].query.get("foo")'),)]publicfunctionindex(Request$request){}

However, since the$request variable might not always be needed in the controller itself, it seems kind of weird to have to add it as an argument just so the#[IsGranted] attribute could work. With this PR, the request will always be available to the attribute:

#[IsGranted(attribute:'SOME_ATTRIBUTE', subject:'request')]publicfunctionindex(){}#[IsGranted(    attribute:'SOME_ATTRIBUTE',    subject:newExpression('request.query.get("foo")'),)]publicfunctionindex(){}

Don't know if this qualifies as a tweak for 6.2 or feature for 6.3.

@carsonbotcarsonbot changed the title[Security] Make request always available to#[IsGranted]Make request always available to#[IsGranted]Nov 2, 2022
@carsonbotcarsonbot changed the titleMake request always available to#[IsGranted][Security] Make request always available to#[IsGranted]Nov 2, 2022
@nicolas-grekas
Copy link
Member

Thank you@HypeMC.

@nicolas-grekasnicolas-grekas merged commit97e08c3 intosymfony:6.2Nov 2, 2022
@nicolas-grekas
Copy link
Member

@HypeMC can you please send a PR to the doc to mention this?

HypeMC reacted with thumbs up emoji

@HypeMCHypeMC deleted the make-request-always-available-to-isgranted branchNovember 2, 2022 16:32
Copy link
Member

@stofstof left a comment

Choose a reason for hiding this comment

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

the case of using the request variable in an expression is not covered by tests

}

if (!\array_key_exists($subjectRef,$arguments)) {
if ('request' ===$subjectRef) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should add that special case. It can be surprising as strings mean argument names. Having special string values makes things harder to explainrequest means the current request only when you don't have an argument named$request in this code).
To me, voting on the Request object is something that case be solved by using the Expression.

yceruto and wouterj reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Thanks for the feedback, will create a followup PR to address this issue.

@HypeMC
Copy link
MemberAuthor

the case of using the request variable in an expression is not covered by tests

@stof There are two tests that check if the request variable is passed to theevaluate method, shouldn't that cover the usage? Since theExpressionLanguage class is mocked, the expressions are never really evaluated, so it shouldn't matter whether the expression actually contains the request variable or not.

@stof
Copy link
Member

stof commentedNov 3, 2022

indeed, this is probably covered by your update of the existing tests using expressions.

chalasr added a commit that referenced this pull requestNov 4, 2022
…ect (HypeMC)This PR was merged into the 6.2 branch.Discussion----------[Security] Remove special case for `#[IsGranted()]` subject| Q             | A| ------------- | ---| Branch?       | 6.2| Bug fix?      | no| New feature?  | no| Deprecations? | no| Tickets       |Fix#48080 (comment)| License       | MIT| Doc PR        | -Addresses a comment by `@stof`Instead of having `request` as a special case, an expression can be used instead:```diff-#[IsGranted(attribute: 'SOME_ATTRIBUTE', subject: 'request')]+#[IsGranted(attribute: 'SOME_ATTRIBUTE', subject: new Expression('request'))]public function index(){}```Commits-------3e0ac4f [Security] Remove special case for #[IsGranted()] subject
fabpot added a commit to symfony/symfony-docs that referenced this pull requestMar 24, 2023
… (HypeMC)This PR was merged into the 6.2 branch.Discussion----------[Security] Use expression for `#[IsGranted()]` subjectsymfony/symfony#46978symfony/symfony#48080symfony/symfony#48102Commits-------9d4045f [Security] Use expression for #[IsGranted()] subject
weaverryan pushed a commit to symfony/symfony-docs that referenced this pull requestMar 28, 2023
… (HypeMC)This PR was merged into the 6.2 branch.Discussion----------[Security] Use expression for `#[IsGranted()]` subjectsymfony/symfony#46978symfony/symfony#48080symfony/symfony#48102Commits-------9d4045f [Security] Use expression for #[IsGranted()] subject
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@derrabusderrabusderrabus approved these changes

@wouterjwouterjAwaiting requested review from wouterjwouterj is a code owner

@chalasrchalasrAwaiting requested review from chalasrchalasr is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Provide same variables for IsGranted attribute as for SecurityAttribute

5 participants

@HypeMC@nicolas-grekas@stof@derrabus@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp