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] Trigger a deprecation when a voter is missing the VoterInterface#22629

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

Closed
linaori wants to merge6 commits intosymfony:3.4fromlinaori:feature/voter-interface-restrictions
Closed

[Security] Trigger a deprecation when a voter is missing the VoterInterface#22629

linaori wants to merge6 commits intosymfony:3.4fromlinaori:feature/voter-interface-restrictions

Conversation

@linaori
Copy link
Contributor

@linaorilinaori commentedMay 4, 2017
edited
Loading

QA
Branch?3.4
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?yes
Tests pass?yes
Fixed tickets~
LicenseMIT
Doc PR~

Right now it's possible to add voters to the access decision manager that do not have aVoterInterface.

  • No Interface, novote() method, and it will give a PHP error.
  • No Interface, butvote() method, it will still work.
  • If I don't implement the interfaceand have novote() method, I will get weird exception that's not meaningful:Attempted to call an undefined method named "vote" of class "App\Voter\MyVoter".

This PR will deprecate the ability to use voters without the interface, it will also throw a proper exception when missing the interfaceand thevote() method. Why when using and not when setting? Due to the fact that the voters can be set lazily via theIteratorArgument. The SecurityBundle will trigger a deprecation if the interface is not implemented and an exception if there's not even avote() method present (to prevent exceptions at run-time).

This should have full backwards compatibility with 3.3, but give more meaningful errors. The only behavioral difference, might be that the container will throw an exception instead of maybe succeeding in voting when 1 voter would be broken at the end of the list (based on strategy). This case however, will be detected during development and deployment, rather than run-time.

Hanmac, vamsiikrishna, ogizanagi, ro0NL, yceruto, dmaicher, Koc, and Nek- reacted with thumbs up emojijvasseur reacted with confused emoji
}

foreach ($votersas$voter) {
$class =$container->getDefinition($voter->__toString())->getClass();
Copy link
Member

Choose a reason for hiding this comment

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

use a string cast instead.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Are you sure? That's harder to trace back (I'm not sure why toString is used either way)


if (!method_exists($class,'vote')) {
// in case the vote method is completely missing, to prevent exceptions when voting
thrownewLogicException(sprintf('%s should implement the %s class when used as voter.',$class, VoterInterface::class));
Copy link
Member

Choose a reason for hiding this comment

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

it is an interface, not a class

linaori and vamsiikrishna reacted with thumbs up emoji

if (!is_a($class, VoterInterface::class,true)) {
@trigger_error(sprintf('Using a security.voter tag on a class without implementing the %1$s is deprecated as of 3.4 and will be removed in 4.0. Implement the %1$s instead.', VoterInterface::class),E_USER_DEPRECATED);
$container->log($this,sprintf('Detected usage of security.voter for class "%s" without implementing the %s.',$class, VoterInterface::class));
Copy link
Member

Choose a reason for hiding this comment

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

this log should be removed, as the deprecation is logged too already

linaori reacted with thumbs up emoji
@vamsiikrishna
Copy link

vamsiikrishna commentedMay 4, 2017
edited
Loading

I have got some Voters which are tagged as voters but don't implementVoterInterface .
Thanks for addressing this and adhering to BC promise .

Security
--------

* Using voters in the`AccessDecisionManager` without`VoterInterface` is now
Copy link
Member

Choose a reason for hiding this comment

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

[...] that do not implement theVoterInterface [...]

Security
--------

* Using voters that do not implement the`VoterInterface`, are now deprecated
Copy link
Member

Choose a reason for hiding this comment

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

"is" and you can remove the comma

return$voter->vote($token,$subject,$attributes);
}

thrownew \BadMethodCallException(sprintf('%s should implement the %s interface when used as voter.',get_class($voter), VoterInterface::class));
Copy link
Contributor

Choose a reason for hiding this comment

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

I would still qualify it a\LogicException :) it's only possible by violating the contract. So technically this is a safeguard.. do we need it? Given the validation during compilation. 👍 for that.

linaori and ogizanagi reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I would like to have it because it's a component that can be used without the DIC

Copy link
Contributor

Choose a reason for hiding this comment

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

It's still a safeguard :) sure it adds some DX value, but nowhere near the value added by the pass (validation at compile time). Practically for the component this is just creating cosmetic errors, which we dont do elsewhere really.

* TokenInterface vote proxy method.
*
* Acts as a BC layer when the VoterInterface is not implemented on the voter.
*/
Copy link
Member

Choose a reason for hiding this comment

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

I would add a note to remove this method in 4.0 (to avoid forgetting about it).

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I could make the method itself deprecated with a full-fledged warning, even though it's private. Would make it easier to detect.


if (method_exists($this,'expectException')) {
$this->expectException($exception);
$this->expectExceptionMessage($message);
Copy link
Contributor

Choose a reason for hiding this comment

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

What about using the annotations?

@fabpotfabpot added this to the3.4 milestoneMay 11, 2017
@nicolas-grekasnicolas-grekas changed the base branch frommaster to3.4May 23, 2017 16:55
@fabpotfabpot closed thisJun 14, 2017
@linaori
Copy link
ContributorAuthor

@fabpot while you approved it, you also closed it but I don't see another commit in the list for 3.4 (as it usually does), I think something went wrong

@fabpot
Copy link
Member

@iltar Weird, not sure what happened. Merging now!

linaori and vamsiikrishna reacted with thumbs up emoji

@fabpot
Copy link
Member

Thank you@iltar.

vamsiikrishna reacted with thumbs up emoji

fabpot added a commit that referenced this pull requestJun 15, 2017
…ng the VoterInterface (iltar)This PR was squashed before being merged into the 3.4 branch (closes#22629).Discussion----------[Security] Trigger a deprecation when a voter is missing the VoterInterface| Q             | A| ------------- | ---| Branch?       | 3.4| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | yes| Tests pass?   | yes| Fixed tickets | ~| License       | MIT| Doc PR        | ~Right now it's possible to add voters to the access decision manager that do not have a `VoterInterface`. - No Interface, no `vote()` method, and it will give a PHP error. - No Interface, but `vote()` method, it will still work. - If I don't implement the interface _and_ have no `vote()` method, I will get weird exception that's not meaningful: `Attempted to call an undefined method named "vote" of class "App\Voter\MyVoter".`This PR will deprecate the ability to use voters without the interface, it will also throw a proper exception when missing the interface _and_ the `vote()` method. Why when using and not when setting? Due to the fact that the voters can be set lazily via the `IteratorArgument`. The SecurityBundle will trigger a deprecation if the interface is not implemented and an exception if there's not even a `vote()` method present (to prevent exceptions at run-time).This should have full backwards compatibility with 3.3, but give more meaningful errors. The only behavioral difference, might be that the container will throw an exception instead of maybe succeeding in voting when 1 voter would be broken at the end of the list (based on strategy). This case however, will be detected during development and deployment, rather than run-time.Commits-------9c253e1 [Security] Trigger a deprecation when a voter is missing the VoterInterface
This was referencedOct 18, 2017
@linaorilinaori deleted the feature/voter-interface-restrictions branchFebruary 8, 2019 13:38
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@xabbuhxabbuhxabbuh left review comments

@stofstofstof requested changes

@fabpotfabpotfabpot approved these changes

+2 more reviewers

@ro0NLro0NLro0NL left review comments

@ogizanagiogizanagiogizanagi approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.4

Development

Successfully merging this pull request may close these issues.

9 participants

@linaori@vamsiikrishna@fabpot@stof@ro0NL@xabbuh@ogizanagi@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp