Skip to content
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

[security] /api behind a firewall trigger an AccessDeniedException that is then transformed into a InsufficientAuthenticationException #519

Closed
Rebolon opened this issue Jan 15, 2018 · 6 comments
Labels

Comments

@Rebolon
Copy link

Rebolon commented Jan 15, 2018

I'm trying to secure the api and i configured the security.yaml like this:

security:
    encoders:
        # @todo should use password encoding, more info here: https://symfony.com/doc/current/security.html#c-encoding-the-user-s-password
        Symfony\Component\Security\Core\User\User: plaintext
    # https://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
    providers:
        in_memory:
            memory:
                users:
                    test:
                        password:           test
                        roles:              ROLE_USER
                    admin:
                        password:           admin
                        roles:              [ROLE_USER, ROLE_ADMIN]

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        vuejs:
            pattern: ^/(demo/login/(json|json/isloggedin|json/logout))|api)
            anonymous: ~
            json_login:
                check_path: /demo/login/json
            logout:
                path:   demo_login_json_logout
                target: index
                invalidate_session: true

An i configure my entities with that kind of annotations:

/*
 * @ApiResource(
 *     iri="http://schema.org/author",
 *     attributes={"access_control"="is_granted('ROLE_USER')"}
 * )
 * @ORM\Entity
 */
class Author { ... }

When i try to access to /api/authors?page=1 then i expect an HTTP 403 but i get an HTTP 500 sent from Symfony\Component\Security\Core\Exception\InsufficientAuthenticationException

If i look at the stack i can see that the original Exception is an Symfony\Component\Security\Core\Exception\AccessDeniedException thornw by the api-platform\core\src\Security\EventListener\DenyAccessListener.php

When i look at the Symfony Security Component documentation i see that i have to setup the status_code to get an HTTPException, or i'll get an AccessDeniedException.

So, is it possible to ask API-Platform to return a 403 ? and how can i do this ?

My setup is always a Symfony 4, with Flex, recipes Annotations, and bundles Security, SensioExtraFramework, a,d component api-platform from master

Thanks for help

@dunglas
Copy link
Member

dunglas commented Jan 15, 2018

We probably to add this exception there: https://github.com/api-platform/core/blob/master/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php#L245-L248

Would you mind opening a pull request?

@Rebolon
Copy link
Author

Rebolon commented Jan 15, 2018

I'll look at this tomorrow to try the modification and test it

@Rebolon
Copy link
Author

Rebolon commented Jan 16, 2018

I also opened an issue on symfony there is a bug with the json_login security system that can impact api-platform: symfony/symfony#25806

@asimonf
Copy link

asimonf commented Oct 1, 2018

@dunglas seeing as the PR didn't get anywhere and this doesn't seem to be getting anywhere on the Symfony issue, what is the proper course of action here to get it fixed mainline?

@dunglas
Copy link
Member

dunglas commented Oct 1, 2018

@asimonf IMO it should be fixed upstream in Symfony. I think that a PR would be very welcome.

@alanpoulain
Copy link
Member

Fixed in Symfony: symfony/symfony#28801.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants