Skip to content

[SecurityBundle] Empty line starting with dash under "access_control" causes all rules to be skipped #40330

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

Conversation

monteiro
Copy link
Contributor

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #40235 ...
License MIT

When the IDE by mistake puts an empty line in access_control in security.yaml there is no warning that we have an empty row, making the rest of routes defined, to be ignored and possible to be accessed by anyone that can authenticate no matter the role.

How to reproduce the issue

  • git clone git@github.com:monteiro/symfony-issue-40235.git
  • composer install
  • symfony server:start
  • open 127.0.0.1:8000/admin with username: "john_user" and password "123456"
  • Since that user has only ROLE_USER should not be able to access the route... but because there is an empty line in "access_control" in security.yaml, "by mistake" it is possible to access the protected ROLE_ADMIN route.

@carsonbot carsonbot added this to the 4.4 milestone Feb 28, 2021
@monteiro monteiro changed the title Empty line starting with dash under "access_control" causes all rules… Empty line starting with dash under "access_control" causes all rules to be skipped Feb 28, 2021
Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

Looks good, I'm merely nit-picking here. 🙂

@carsonbot carsonbot changed the title Empty line starting with dash under "access_control" causes all rules to be skipped [SecurityBundle] Empty line starting with dash under "access_control" causes all rules to be skipped Feb 28, 2021
@wouterj
Copy link
Member

wouterj commented Mar 1, 2021

Thank you for creating this PR including tests and a reproducer, @monteiro! That's perfect!

After looking at the changes, I'm wondering whether we qualify this as a BC break. More precisely, people may have been using the "empty attributes" feature to exclude some routes from the access control (e.g. a login form). However, this was never documented behavior.

Let's wait a bit for more comments from the core team whether or not this is a BC break. If we qualify it as such, I think it makes all sense to deprecate this in 5.x instead (and introducing this exception in 6.0). IS_AUTHENTICATED_ANONYMOUSLY or PUBLIC_ACCESS should be used instead of an empty array of attributes imho.

@derrabus
Copy link
Member

derrabus commented Mar 1, 2021

After looking at the changes, I'm wondering whether we qualify this as a BC break.

I thought about that as well and could live with going through the deprecation process for that.

More precisely, people may have been using the "empty attributes" feature to exclude some routes from the access control (e.g. a login form). However, this was never documented behavior.

My current understanding of the behavior (please correct me if I'm wrong) is that the empty line simply matches every request without applying any access restrictions. The result is effectively that any subsequent line would become unreachable. That behavior is dangerously surprising imho.

Can we come up with a scenario where this change breaks an application that is not dangerously misconfigured?

@wouterj
Copy link
Member

wouterj commented Mar 1, 2021

Can we come up with a scenario where this change breaks an application that is not dangerously misconfigured?

access_control:
  - { path: ^/login }
  - { path: ^/, roles: ROLE_USER }

I haven't verified it, but as far as I understand the code, this yaml file is equal to doing - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }.

The diff is checking $attributes, which are the roles + allow_if statements from access control.

@derrabus
Copy link
Member

derrabus commented Mar 1, 2021

@wouterj With your example, the exception in this PR should not be triggered. The case that is caught here is this one:

access_control:
  -
  - { path: ^/, roles: ROLE_USER }

@wouterj
Copy link
Member

wouterj commented Mar 1, 2021

@derrabus as indicated with my last sentence, this case is caught by this PR, as the check is done over $attributes, which only contains the values of roles and allow_if. So maybe we should do this check over $access? (not sure how that works, as most options have a default value of null.

@derrabus
Copy link
Member

derrabus commented Mar 1, 2021

@derrabus as indicated with my last sentence, this case is caught by this PR

Okay, that's indeed an issue then.

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

We need to make sure that @wouterj's example still works.

@monteiro monteiro force-pushed the security-issue-if-access-control-empty branch from ebee522 to e99bc3a Compare April 1, 2021 12:01
@monteiro monteiro requested a review from xabbuh April 1, 2021 12:03
@monteiro monteiro requested a review from derrabus April 1, 2021 12:03
@monteiro
Copy link
Contributor Author

monteiro commented Apr 1, 2021

Following @xabbuh advice I fixed this specific edge case and added @wouterj example to the test, so we are sure it is not breaking old behaviour. Let me know what you think.

Thanks for the help!

Copy link
Member

@wouterj wouterj left a comment

Choose a reason for hiding this comment

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

Maybe I was a bit too fast with my approval. I'm not 100% sure if my suggestions make sense.

@monteiro
Copy link
Contributor Author

Let me know if there is anything I can do to help here.

@derrabus derrabus force-pushed the security-issue-if-access-control-empty branch from 9c8f39c to ee26ce5 Compare April 12, 2021 14:25
@derrabus
Copy link
Member

Thank you @monteiro.

@derrabus derrabus merged commit e1f2e81 into symfony:4.4 Apr 12, 2021
@monteiro
Copy link
Contributor Author

Thanks to you @derrabus

@monteiro monteiro deleted the security-issue-if-access-control-empty branch April 12, 2021 14:27
This was referenced May 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants