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] $attributes can be anything, but RoleVoter assumes strings#19725

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

Merged
fabpot merged 1 commit intosymfony:2.7frommaennchen:hotfix/18042_support_mixed_types
Oct 6, 2016
Merged

[Security] $attributes can be anything, but RoleVoter assumes strings#19725

fabpot merged 1 commit intosymfony:2.7frommaennchen:hotfix/18042_support_mixed_types
Oct 6, 2016

Conversation

@maennchen
Copy link

@maennchenmaennchen commentedAug 24, 2016
edited
Loading

QA
Branch?2.7
Bug fix?yes
New feature?no
BC breaks?yes
Deprecations?no
Tests pass?yes
Fixed tickets#18042
LicenseMIT
Doc PRreference to the documentation PR, if any

vstm reacted with thumbs up emoji
@linaori
Copy link
Contributor

Considering this has most likely never worked, I think attributes should be hinted as string instead.

@maennchen
Copy link
Author

maennchen commentedAug 24, 2016
edited
Loading

@iltar I don't think that this is a good idea.

I have a use case where i want to check if some operations (attributes) can be applied on an object (subject).

For sure those operations could be flattened into a string, but one would have to parse them in the voter again which is total nonsense.

Type Hinting for string would be a BC break since one can supply objects as attributes already, but only if the objects implements a__toString() method.

@linaori
Copy link
Contributor

I guess implementing__toString() is already a debatable feature on its own. For the other cases, you have examples of how this would be used? I can't imagine because it's not how it's documented.

@Gladhon
Copy link

@iltar i think its basically a good idea to allow objects there, cause in that case you can easy check if your voter is responsible or not. Like ExpressionVoter:https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Core/Authorization/Voter/ExpressionVoter.php#L60

Of course you also can do that with strings, and prefix strings, and hope that there are no conflicts ... but who want this?

@maennchen
Copy link
Author

@iltar I only implemented the__toString to maintain backwards compatibility. In my opinion I'd rather remove that.

But there are already examples in Symfony itself using non string values. (See@Gladhon's comment) TheExpressionVoter only works because theExpression implements__toString.

@hhamon
Copy link
Contributor

hhamon commentedAug 26, 2016
edited
Loading

I think we should not rely on the__toString() method because you usually want to use it to return a "display" value. For instance, returningAdministrators label for an associatedROLE_ADMIN role. The security system requires that any objects to be used as a role must implement theRoleInterface. So theRoleVoter should probably be upgraded to check it the$attribute is an instance ofRoleInterface instance, so that you can convert it to a string with itsgetRole() method.

vstm, maennchen, Gladhon, and sstok reacted with thumbs up emoji

@hhamon
Copy link
Contributor

Otherwise you must implement your custom voter that support your custom type of attribute.

@hhamon
Copy link
Contributor

Btw, the border between bug and new feature is really close in this case. I think it's better to consider it a new feature and submit the PR against themaster branch.

@maennchen
Copy link
Author

@hhamon I'd like your proposed solution. I implemented the__toString() thing to avoid BC breaks.

@maennchen
Copy link
Author

I think that it's definitely a bug since the interface clearly says that mixed is accepted. (Which is currently only if you implement__toString.
Could we implement this as a bug and introduce a new feature for master which cleans the behaviour up?

@sstok
Copy link
Contributor

supportsAttribute for RoleVoter should only allow a string or Role(Interface) (Role is actually the only one that is officially supported, because of the string promise).

But when the attributes of a not supported type, the de decision should be abstained?
When passing an unsupported attribute it would have failed with an php error, no?

@maennchen
Copy link
Author

@sstok Two times yes.

@maennchen
Copy link
Author

AlsosupportsAttribute does not exist anymore in>= 3.0 I think.

@hhamon
Copy link
Contributor

hhamon commentedAug 26, 2016
edited
Loading

YessupportAttributes as a "public" method was removed from theVoterInterface in Symfony 3.0 because this method was never called by the Security component in Symfony 2. But its piece of logic still resides in theRoleVoter class.

@maennchen
Copy link
Author

Should I change to check if the attribute is instance of RoleInterface instead of __toString? This will be a small BC break.

@ro0NL
Copy link
Contributor

@maennchen why exactly do you want to remove__toString support? Imo we should first check forRoleInterface then string/string-object.

That would still be a BC break, but personally i consider it a bugfix.

returnfalse;
}

return0 ===strpos($attribute,$this->prefix);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be simply(string) $attribtute as well. No need for the above statements... it should crash for invalid values by design.

Copy link
Author

Choose a reason for hiding this comment

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

An attribute is mixed by design. It shouldn't crash for non string values. It should abstain. Why should it be a convention that every object passed as an attribute can be converted to a string.

I implemented a Voter, that was designed to vote for Operations on a subject when I encountered the error. Why should those operations which are not by any means strings have a toString method? That makes no sense for something that is by design mixed.

(By the way: strpos will automatically do a string casting. No string cast needed for that.)

Copy link
Author

Choose a reason for hiding this comment

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

I'd change the code to check if$attribute instanceof RoleInterface, if yes do agetRole() on it. If it is no string or RoleInterface, I'd continue / ABSTAIN.

Copy link
Contributor

Choose a reason for hiding this comment

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

It shouldn't crash for non string values. It should abstain

Sorry, you're right. However i think for 2.7supportAttribute should also considerRoleInterface due mixed attribute support.

@maennchen
Copy link
Author

I refactored it with specific checks forRoleInterface.

I personally don't really care if there is support for objects having a__toString() method. In my opinion it's cleaner just to handle strings &RoleInterface, but with__toString() support there is no BC break.


foreach ($attributesas$attribute) {
if ($attributeinstanceof RoleInterface) {
$attribute =$attribute->getRole();
Copy link
Member

Choose a reason for hiding this comment

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

We should not callsupportAttribute if the return value ofgetRole() isnull as it means that there is no good representation of the role as a string.

Copy link
Member

Choose a reason for hiding this comment

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

nevermind, that's already covered insupportsAttribute() via theis_string() check.

@fabpot
Copy link
Member

Thank you@maennchen.

@fabpotfabpot merged commitad3ac95 intosymfony:2.7Oct 6, 2016
fabpot added a commit that referenced this pull requestOct 6, 2016
…mes strings (Jonatan Männchen)This PR was merged into the 2.7 branch.Discussion----------[Security] $attributes can be anything, but RoleVoter assumes strings| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | yes| New feature?  | no| BC breaks?    | yes| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#18042| License       | MIT| Doc PR        | reference to the documentation PR, if anyCommits-------ad3ac95 bug#18042 [Security] $attributes can be anything, but RoleVoter assumes strings
@maennchenmaennchen deleted the hotfix/18042_support_mixed_types branchOctober 6, 2016 07:59
@fabpotfabpot mentioned this pull requestOct 27, 2016
This was referencedOct 27, 2016
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot left review comments

+1 more reviewer

@ro0NLro0NLro0NL left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

8 participants

@maennchen@linaori@Gladhon@hhamon@sstok@ro0NL@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp