Skip to content

[SECURITY] AbstractAuthenticationListener.php error instead info. #28462

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

Closed
wants to merge 3 commits into from
Closed

[SECURITY] AbstractAuthenticationListener.php error instead info. #28462

wants to merge 3 commits into from

Conversation

Warxcell
Copy link
Contributor

@Warxcell Warxcell commented Sep 13, 2018

[2018-09-13 20:43:38] security.INFO: Authentication request failed. {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\AuthenticationServiceException(code: 0): An exception occurred while executing
 ...
 Doctrine\\DBAL\\Driver\\PDOException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 't0.phone' in 'field list' at

Definitely I think this is NOT info, but error.
And since it's info, it's not logged in production because of fingers_crossed with action_level: error - so to actually see the real error behind Authentication request could not be processed due to a system problem. I had to debug on production. Very bad practice IMHO.

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no I think
Deprecations? no
Tests pass? yes
Fixed tickets ...
License MIT

```
[2018-09-13 20:43:38] security.INFO: Authentication request failed. {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\AuthenticationServiceException(code: 0): An exception occurred while executing
 ...
 Doctrine\\DBAL\\Driver\\PDOException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 't0.phone' in 'field list' at
```

Defenitely I think this is NOT info, but error.

| Q             | A
| ------------- | ---
| Branch?       | 3.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no I think
| Deprecations? | no
| Tests pass?   | yes 
| Fixed tickets | ...
| License       | MIT
@jvasseur
Copy link
Contributor

This means all failed authentication attempts will now be logged as error which is not right either. We need to differentiate between errors in the authentication process and failed authentication attempts to determine the logging level here.

@Warxcell
Copy link
Contributor Author

Warxcell commented Sep 13, 2018

@jvasseur thank you for your response.

How do we do that? What are exceptions for non-errors?

What about that:

if ($failed instanceof \Symfony\Component\Security\Core\Exception\AuthenticationServiceException) {
      $this->logger->error('Authentication request failed.', array('exception' => $failed));
} else {
      $this->logger->info('Authentication request failed.', array('exception' => $failed));
}

at the top of that exception it says:

AuthenticationServiceException is thrown when an authentication request could not be processed due to a system problem.

@jvasseur
Copy link
Contributor

@Warxcell checking if the exception is an instance of AuthenticationServiceException could be a good solution yes.

Use  Symfony\Component\Security\Core\Exception\AuthenticationServiceException to determine logging level
@Warxcell
Copy link
Contributor Author

Warxcell commented Sep 13, 2018

What I would do is in case of AuthenticationServiceException just rethrow error - so it would result in 500 Error on page, like everywhere else. (and easier debugging on dev)

But that means BC-Break - so I'm just changing the logging level.

@linaori
Copy link
Contributor

linaori commented Sep 14, 2018

I've done a quick search where this exception is being used.

UserAuthenticationProvider

This is extended by the LdapBindAuthenticationprovider and DaoAuthenticationProvider. While being an AuthenticationServiceException, this would in the future be caught by return types as it specifies @return UserInterface on retrieveUser.

One small note for this, the Dao is something that should be removed in my opinion and the Ldap variant should be re-made in Guard, but that's another issue.

Conclusion: This one should trigger an ERROR level

DaoAuthenticationProvider

Throws it twice, once when the return contract is broken (return is not a UserInteface) and once when a generic exception is thrown. Both of them are triggered when something is broken as the generic exception catch is superseded by a catch on UsernameNotFoundException.

Conclusion: Both should trigger an ERROR level

DigestAuthenticationListener

This implementation specifies that it's an ERROR level: "Digest User provider returned null, which is an interface contract violation"

Conclusion: This one should trigger an ERROR level

UnsupportedUserException

  • Caught in the ChainUserProvider
  • Caught in the ContextListener
  • Caught in the AbstractRememberMeServices

Conclusion: these are often implemented by the end-user, but we cannot guarantee they are a 500 error. According to the class itself:

This exception is thrown when an account is reloaded from a provider which doesn't support the passed implementation of UserInterface.

Which I already see being abused here. My suggestion would be to follow the class doc and make it an ERROR as well.

Final conclusion

This particular exception should in my opinion trigger an ERROR in the logs. However, it should not do this for the Authentication Failed log. That means the logging has to be adapted in a way where both can be logged separately. Perhaps this can be done via getParent() on the Exception?

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Sep 18, 2018
@nicolas-grekas
Copy link
Member

@iltar would you be able to provide a patch doing so to help @Warxcell? (or maybe it's not needed?)

@linaori
Copy link
Contributor

linaori commented Sep 18, 2018

I can help with a patch (reviewing), but I do not have time myself to do this in-between at the moment

@Warxcell
Copy link
Contributor Author

So what should be done? If it's error log in app channel, if not - log in security channel?

@nicolas-grekas
Copy link
Member

@iltar I think we need your help here :)

@linaori
Copy link
Contributor

linaori commented Oct 21, 2018

So what should be done? If it's error log in app channel, if not - log in security channel?

That's actually not a bad idea at all 😮

@Warxcell
Copy link
Contributor Author

Warxcell commented Nov 1, 2018

@iltar how can this be done? sending 2 different loggers with tag monolog.logger ?

@fabpot fabpot added the Help wanted Issues and PRs which are looking for volunteers to complete them. label Mar 4, 2019
@fabpot
Copy link
Member

fabpot commented Mar 25, 2019

@linaori Might be a great PR for the upcoming hackaton :)

@linaori
Copy link
Contributor

linaori commented Mar 25, 2019

Do we have a label for the hackathon? It might be nice to tag a bunch of issues so we can plow through them.

@javiereguiluz
Copy link
Member

@linaori yes, we've created a special label for that event:

image

@curry684
Copy link
Contributor

curry684 commented Apr 6, 2019

@linaori I've just read the entire discussion and your well researched arguments, and I'm now thinking why we're not raising the log level to ERROR as a whole as indeed our existing implementations act like that and the class is documented to work like that. I don't see the INFO case any more other than to maintain some kind of fake B/C with existing applications and bundles that somehow count on it being info.

To be honest, I don't consider that a B/C breakage as the docs were there to indicate it always should have been an error.

@nicolas-grekas
Copy link
Member

(rebase needed)

berezuev added a commit to berezuev/symfony that referenced this pull request May 20, 2019
@fabpot fabpot closed this Jul 8, 2019
berezuev added a commit to berezuev/symfony that referenced this pull request Jul 8, 2019
berezuev added a commit to berezuev/symfony that referenced this pull request Jul 8, 2019
fabpot added a commit that referenced this pull request Jul 8, 2019
…stead info. Rebase of #28462 (berezuev)

This PR was merged into the 4.4 branch.

Discussion
----------

[SECURITY] AbstractAuthenticationListener.php error instead info. Rebase of #28462

| Q             | A
| ------------- | ---
| Branch? | 4.4
| -- | --
| Bug fix? | yes
| New feature? | no
| BC breaks? | no I think
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | ...
| License | MIT

Rebase of #28462. Origin description:
> ```
> [2018-09-13 20:43:38] security.INFO: Authentication request failed. {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\AuthenticationServiceException(code: 0): An exception occurred while executing
>  ...
>  Doctrine\\DBAL\\Driver\\PDOException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 't0.phone' in 'field list' at
> ```
>
> Definitely I think this is NOT info, but error.
> And since it's info, it's not logged in production because of `fingers_crossed` with `action_level: error` - so to actually see the real error behind `Authentication request could not be processed due to a system problem.` I had to debug on production. Very bad practice IMHO.

Commits
-------

867eb78 [SECURITY] AbstractAuthenticationListener.php error instead info. Rebase of #28462
This was referenced Nov 12, 2019
@Fl0ux
Copy link

Fl0ux commented Dec 5, 2019

Something seems to wrong with this commit. Now every failed login attempts are logged as errors.

[2019-12-05T11:47:47.157808+01:00] security.ERROR: Authentication request failed. {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\BadCredentialsException(code: 0): Bad credentials. at /home/foulques/PhpstormProjects/MonAvisCitoyenV2/vendor/symfony/security-core/Authentication/Provider/UserAuthenticationProvider.php:68)\n[previous exception] [object] (Symfony\\Component\\Security\\Core\\Exception\\UsernameNotFoundException(code: 0): User \"18691mac@yopmail.com\" not found. at /home/foulques/PhpstormProjects/MonAvisCitoyenV2/vendor/symfony/doctrine-bridge/Security/User/EntityUserProvider.php:65)"} []

... and every time I receive a mail to warn me about this...

@Warxcell
Copy link
Contributor Author

Warxcell commented Dec 5, 2019

@Fl0ux it's not because of that. As you can see - it's closed, not merged.

@nicolas-grekas
Copy link
Member

It's merged in 87a6f04 actually.
But commenting on a closed PR will likely be ignored as there is no way to track them.

@Fl0ux
Copy link

Fl0ux commented Dec 5, 2019

Ok, I will create a new bug report in this case.

@Warxcell
Copy link
Contributor Author

Warxcell commented Dec 5, 2019

@nicolas-grekas but it's slightly different from my PR. I excluded these exceptions. I was logging only system errors, not every failed login because of credentials.

MolloKhan added a commit to MolloKhan/symfony that referenced this pull request Dec 12, 2019
nicolas-grekas pushed a commit to MolloKhan/symfony that referenced this pull request Dec 13, 2019
nicolas-grekas added a commit that referenced this pull request Dec 13, 2019
…r instead info" (larzuk91)

This PR was submitted for the master branch but it was merged into the 4.4 branch instead.

Discussion
----------

[Security] Revert "AbstractAuthenticationListener.php error instead info"

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34836
| License       | MIT

This reverts commit 867eb78.

After that change, every failed login attempt is logged as an error. It's flooding our errors log channel

Commits
-------

9d306f9 [SECURITY] Revert "AbstractAuthenticationListener.php error instead info. Rebase of #28462"
nicolas-grekas added a commit that referenced this pull request Dec 16, 2019
* 4.4: (21 commits)
  fix merge
  CS
  [FrameworkBundle][ContainerLintCommand] Improve messages when the kernel or the container is not supported
  [Serializer] Skip uninitialized (PHP 7.4) properties in PropertyNormalizer and ObjectNormalizer
  stop using deprecated Doctrine persistence classes
  [Cache] Fix wrong classname in deprecation message
  Fix regex lookahead syntax in ApplicationTest
  Fixed syntax in comment
  [SecurityBundle][FirewallMap] Remove unused property
  [Messenger][AMQP] Use delivery_mode=2 by default
  [FrameworkBundle][DependencyInjection] Skip removed ids in the lint container command and its associated pass
  [SECURITY] Revert "AbstractAuthenticationListener.php error instead info. Rebase of #28462"
  [FrameworkBundle][Secrets] Hook configured local dotenv file
  [DI] Improve performance of processDefinition
  fix redis multi host dsn not recognized
  fix constructor argument type declaration
  Fix invalid Windows path normalization
  [Validator][ConstraintValidator] Safe fail on invalid timezones
  [DoctrineBridge] Fixed submitting invalid ids when using queries with limit
  [FrameworkBundle] Add info & example to auto_mapping config
  ...
nicolas-grekas added a commit that referenced this pull request Dec 16, 2019
* 5.0: (21 commits)
  fix merge
  CS
  [FrameworkBundle][ContainerLintCommand] Improve messages when the kernel or the container is not supported
  [Serializer] Skip uninitialized (PHP 7.4) properties in PropertyNormalizer and ObjectNormalizer
  stop using deprecated Doctrine persistence classes
  [Cache] Fix wrong classname in deprecation message
  Fix regex lookahead syntax in ApplicationTest
  Fixed syntax in comment
  [SecurityBundle][FirewallMap] Remove unused property
  [Messenger][AMQP] Use delivery_mode=2 by default
  [FrameworkBundle][DependencyInjection] Skip removed ids in the lint container command and its associated pass
  [SECURITY] Revert "AbstractAuthenticationListener.php error instead info. Rebase of #28462"
  [FrameworkBundle][Secrets] Hook configured local dotenv file
  [DI] Improve performance of processDefinition
  fix redis multi host dsn not recognized
  fix constructor argument type declaration
  Fix invalid Windows path normalization
  [Validator][ConstraintValidator] Safe fail on invalid timezones
  [DoctrineBridge] Fixed submitting invalid ids when using queries with limit
  [FrameworkBundle] Add info & example to auto_mapping config
  ...
raneomik pushed a commit to raneomik/symfony that referenced this pull request Dec 16, 2019
hultberg pushed a commit to hultberg/symfony that referenced this pull request Sep 17, 2021
* 4.4: (21 commits)
  fix merge
  CS
  [FrameworkBundle][ContainerLintCommand] Improve messages when the kernel or the container is not supported
  [Serializer] Skip uninitialized (PHP 7.4) properties in PropertyNormalizer and ObjectNormalizer
  stop using deprecated Doctrine persistence classes
  [Cache] Fix wrong classname in deprecation message
  Fix regex lookahead syntax in ApplicationTest
  Fixed syntax in comment
  [SecurityBundle][FirewallMap] Remove unused property
  [Messenger][AMQP] Use delivery_mode=2 by default
  [FrameworkBundle][DependencyInjection] Skip removed ids in the lint container command and its associated pass
  [SECURITY] Revert "AbstractAuthenticationListener.php error instead info. Rebase of symfony#28462"
  [FrameworkBundle][Secrets] Hook configured local dotenv file
  [DI] Improve performance of processDefinition
  fix redis multi host dsn not recognized
  fix constructor argument type declaration
  Fix invalid Windows path normalization
  [Validator][ConstraintValidator] Safe fail on invalid timezones
  [DoctrineBridge] Fixed submitting invalid ids when using queries with limit
  [FrameworkBundle] Add info & example to auto_mapping config
  ...
hultberg pushed a commit to hultberg/symfony that referenced this pull request Sep 17, 2021
* 5.0: (21 commits)
  fix merge
  CS
  [FrameworkBundle][ContainerLintCommand] Improve messages when the kernel or the container is not supported
  [Serializer] Skip uninitialized (PHP 7.4) properties in PropertyNormalizer and ObjectNormalizer
  stop using deprecated Doctrine persistence classes
  [Cache] Fix wrong classname in deprecation message
  Fix regex lookahead syntax in ApplicationTest
  Fixed syntax in comment
  [SecurityBundle][FirewallMap] Remove unused property
  [Messenger][AMQP] Use delivery_mode=2 by default
  [FrameworkBundle][DependencyInjection] Skip removed ids in the lint container command and its associated pass
  [SECURITY] Revert "AbstractAuthenticationListener.php error instead info. Rebase of symfony#28462"
  [FrameworkBundle][Secrets] Hook configured local dotenv file
  [DI] Improve performance of processDefinition
  fix redis multi host dsn not recognized
  fix constructor argument type declaration
  Fix invalid Windows path normalization
  [Validator][ConstraintValidator] Safe fail on invalid timezones
  [DoctrineBridge] Fixed submitting invalid ids when using queries with limit
  [FrameworkBundle] Add info & example to auto_mapping config
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Help wanted Issues and PRs which are looking for volunteers to complete them. Security Status: Needs Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants