2

I have a firewall rule which together with annotations allows only access to actions as specific user.

Additionally I would love to block ANY login if it is not coming from a certain network. Searching for a solution I came across additional access_control rules following this guide.

The problem there is, if I restrict my login page via IP rules. I always get an ERR_TOO_MANY_REDIRECTSerror if someone tries to reach it. I would rather love to have a "Page not Found" message to not even make someone from outside aware there could be any login.

How can I do this with Symfony?

security.yml:

security:
    ...

    firewalls:
        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false

        default:
            form_login:
                provider: fos_userbundle
                login_path: /login
                use_forward: false
            logout:       true
            anonymous:    true

    access_control:
        - { path: ^/logout$, role: ROLE_ADMIN }
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https, ips: [127.0.0.1, fe80::1, ::1]}
        - { path: ^/login$, roles: ROLE_NO_ACCESS }
        - { path: ^/admin, role: ROLE_ADMIN, requires_channel: https}
3
  • what happened in apache error.log ? Nov 11, 2015 at 16:16
  • Nothing, just Child: Starting 150 worker threads., which is the restart message. You can only see something in the access.log where 31 times 127.0.0.1 - - [11/Nov/2015:17:20:47 +0100] "GET /login HTTP/1.1" 302 344is writen
    – lony
    Nov 11, 2015 at 16:23
  • when you removing 'requires_channel: https' infinite loop still exists ? Nov 11, 2015 at 16:24

1 Answer 1

1

If I am not mistaken, what Symfony does here, is try and match the role of the user to what is required for the path. If it doesn't match one of those roles, it sends the user to the login page.

The problem is, the login page is where the user has just come from. Thus the user gets into an infinite loop as their condition can never be met.

I would suggest putting the login page itself outside of the firewall and just put the IP check within the code of the LOGIN page and if not met, dump out somewhere else, which isn't within the firewall.

4
  • How can I do this presenting just a 404 status code?
    – lony
    Nov 11, 2015 at 17:12
  • This has a good example for you: symfony.com/doc/2.3/book/…
    – Adi
    Nov 11, 2015 at 19:32
  • Thanks, and how can I get Symfony to redirect to my 404 page if the given IP is not matching?
    – lony
    Nov 12, 2015 at 8:21
  • 1
    Create an event listender for 404 events: symfony.com/doc/current/cookbook/event_dispatcher/… Use this condition within it: if ( $exception instanceof NotFoundHttpException ) and within that, set your IP check. If it doesn't match, set the response to be return new RedirectResponse( $newURL ); You will need to hook the event listener page up in the service.yml
    – Adi
    Nov 12, 2015 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.