Skip to content

[Security] Add setVoters() on AccessDecisionManager #14733

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
merged 1 commit into from
Jun 1, 2015

Conversation

nicolas-grekas
Copy link
Member

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets partially #12360
License MIT
Doc PR -

Alternative for #14550

@@ -41,12 +41,8 @@ class AccessDecisionManager implements AccessDecisionManagerInterface
*
* @throws \InvalidArgumentException
*/
public function __construct(array $voters, $strategy = self::STRATEGY_AFFIRMATIVE, $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true)
public function __construct(array $voters = array(), $strategy = self::STRATEGY_AFFIRMATIVE, $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true)
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 see how it would make a difference anyway, but we don't need to make this option - the "old" way would of course also allow an empty array.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not required, but if setting no voters on instantiation is allowed, I thought it would be more consistent to make the argument optional also.

@weaverryan
Copy link
Member

👍 I tested this - it allows for the security.access.decision_manager service to be injected into voters without a circular reference (e.g. so that a voter could check isGranted('ROLE_ADMIN').

For docs: symfony/symfony-docs#5306, I have an issue to doc this.

@linaori
Copy link
Contributor

linaori commented May 24, 2015

@weaverryan wouldn't that lead to potential recursion?

@weaverryan
Copy link
Member

@iltar Recursion where? Do you mean a circular reference? If so, then no - the container is able to create the AccessDecisionManager, then create the voters, then finish the AccessDecisionManager by calling setVoters(). Or do you mean recursion in that AccessDecisionManager refers to voters, which refer back to the AccessDecisionManager? If so, then yes, which isn't really a problem except for garbage collection (see #14550 (comment)), in which case you could call setVoters() with an empty array to clear things if you really needed to. More broadly, I don't think there's another possible way to fix this, rather than giving the voters access to the AccessDecisionManager.

@ogizanagi
Copy link
Contributor

@weaverryan : I think what @iltar means isn't about the circular object graph, but in the case of a voter A calling isGranted on an object and attribute supported by voter B, and voter B calling isGranted on the same object and attribute supported by voter A again. Or A calling itself.
But if there is such a case, I think it's only due to a bad design.

@weaverryan
Copy link
Member

@ogizanagi OOOH, yes, of course - I don't know how I missed that. Yes, it's possible - but I agree with you - that would be an error on the developer, and one that they would suffer during development and fix. And this is already true today if you use a voter to go back through the AccessDecisionManager ("possible" if you inject the container into a voter - it's hacky, hence this PR).

@linaori
Copy link
Contributor

linaori commented May 26, 2015

@weaverryan that's exactly what I meant. Maybe we could somehow make the AccesDecisionManager track what it's voting for, so when it tries to vote again on the same role, it will throw an exception.

@weaverryan
Copy link
Member

I don't think it's possible because it may make sense to call a voter recursively - the attributes or token may be different, or the voter may be holding some state (it shouldn't) that makes it act different the second time. I like the thought - but I'm not sure it's possible

@fabpot
Copy link
Member

fabpot commented Jun 1, 2015

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 3fd7cea into symfony:2.8 Jun 1, 2015
fabpot added a commit that referenced this pull request Jun 1, 2015
…icolas-grekas)

This PR was merged into the 2.8 branch.

Discussion
----------

[Security] Add setVoters() on AccessDecisionManager

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | partially #12360
| License       | MIT
| Doc PR        | -

Alternative for #14550

Commits
-------

3fd7cea [Security] Add setVoters() on AccessDecisionManager
@nicolas-grekas nicolas-grekas deleted the allow-no-voters branch June 2, 2015 23:16
fabpot added a commit that referenced this pull request Sep 24, 2015
… TokenInterface (weaverryan)

This PR was squashed before being merged into the 2.8 branch (closes #15870).

Discussion
----------

Updating AbstractVoter so that the method receives the TokenInterface

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #12360
| License       | MIT
| Doc PR        | not yet

This fixes #12360, and along with already-merged #14733, this would make it possible to make calls back to the `AccessDecisionManager` inside a voter (e.g. you might check to see if `IS_AUTHENTICATED_FULLY` from inside your voter).

We originally passed the User instead of the token to be nice, but it's a limitation, and since we never sanitized the User (i.e. a string may be passed to `AbstractToken::isGranted()`), it's not helpful anyways.

Thanks!

Commits
-------

948ccec Updating AbstractVoter so that the method receives the TokenInterface
@fabpot fabpot mentioned this pull request Nov 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants