Giter VIP home page Giter VIP logo

ccdnusersecuritybundle's Introduction

[NO LONGER SUPPORTED] CCDNUser SecurityBundle README.

SensioLabsInsight Build Status Scrutinizer Quality Score Code Coverage Latest Stable Version Total Downloads Stories in Ready

Notes:

This is no longer supported or worked on. If you wish to continue using this and wish to take over let me know.

This bundle is for the symfony framework and requires Symfony ~2.4 and PHP >=5.3.2

This project uses Doctrine >=2.1 and so does not require any specific database.

This file is part of the CCDNUser bundles(s)

© CCDN © CodeConsortium

Available on:

For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

SensioLabsInsight knpbundles.com

Description:

Use this bundle to mitigate brute force dictionary attacks on your sites. Excessive failed logins will force users to recover their account, additional attempts to circumvent that will block the user from specified webpages by returning an HTTP 500 response on all specified routes.

You can use this bundle with any User Bundle you like.

This bundle does NOT provide user registration/login/logout etc features. This bundle is for brute force dictionary attack mitigation only. Use this bundle in conjunction with your preferred user bundle.

Features.

SecurityBundle Provides the following features:

  1. Prevent brute force attacks being carried out by limiting number of login attempts:
    1. When first limit is reached, redirect to an account recovery page.
    2. When secondary limit is reached, return an HTTP 500 status to block login pages etc.
  2. All limits are configurable.
  3. Routes to block are configurable.
  4. Route for account recovery page is configurable.
  5. Decoupled from UserBundle specifics. You can use this with any user bundle you like.
  6. Redirect user to last page they were on upon successful login.
  7. Redirect user to last page they were on upon successful logout.

Documentation.

Documentation can be found in the Resources/doc/index.md file in this bundle:

Read the Documentation.

Installation.

All the installation instructions are located in documentation.

License.

This software is licensed under the MIT license. See the complete license file in the bundle:

Resources/meta/LICENSE

Read the License.

About.

CCDNUser SecurityBundle is free software from Code Consortium. See also the list of contributors.

Reporting an issue or feature request.

Issues and feature requests are tracked in the Github issue tracker.

Discussions and debates on the project can be further discussed at Code Consortium.

ccdnusersecuritybundle's People

Contributors

arthurpetit avatar christianbaer avatar craue avatar jhkchan avatar krizon avatar mo25 avatar potherca avatar reecefowell avatar ricbra avatar rstrash avatar waffle-with-pears avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ccdnusersecuritybundle's Issues

Support for Doctrine ORM 2.5

The composer.json imposes a limit of "doctrine/orm": "~2.2,>=2.2.3" - is the upper bound strictly necessary?

Doctrine 2.5 offers a lot of improvements, and whilst it's not going to be the default in Symfony for ages (even 3.0), upgrading to it was painless with zero BC breaks in my relatively large Symfony project.

Any thoughts?

Check if we are in the "force_account_recovery" period

There is a way to check if the login redirect is active... ? So after we have reached the number of failed logins to be able to redirect the user to a "too many login attempts" route / page where I would like to be able to output some message to make visitor aware why is it not able to see the login page again:

{% if ( 'admin/login' in app.request.headers.get('referer') ) or
( 'admin/dashboard' in app.request.headers.get('referer') ) %}

Too many login attempts


....

However first time the twig is displaying my message as the referer is the admin/login route ... in my case, but if I will refresh that landing page the message is no longer displayed... so can I check a session var or something to be able to accomplish this ?

Thank you for sharing your code

Brute force attack using different IPs

This bundle doesn't take into consideration that different IP addresses might be used to brute force a specific username. However, blocking the account based on multiple attempts for a specific username, irrespective of the IP address, creates another problem i.e. user A can attempt to log in as user B, hence blocking access for user B. To overcome this, we need to make sure that access for user B is allowed from a pre-saved/whitelisted IP address.

Do you have any opinion/thoughts on the matter?

Clean previous session after user requested new password.

The scenario:

  1. "duration_in_minutes" was set to "15 minutes"
  2. The lockout was triggered and the user was redirected to the password recovery.
  3. User requested a new password and successfully logged in to the site.
  4. User logged out.
  5. User will not be able to login again since the previous session is still active.

Is this normal? I'm thinking of once the user successfully logged in to the site, the previous session should be cleared already.

User Entity is never used

Hi,

we just integrated CCDNUserSecurityBundle into a legacy application where we do not yet use the FOSUserBundle, nor do we have a (doctrine) entity for our user class.

So we where stuck a bit, because we did not now, what value we could provide for this configuration key:

ccdn_user_security:
    entity:
        user:
            class: Acme\YourUserBundle\Entity\User # Required

After greping through the code we came to the conclusion that this configuration value is never used. So we left the example value in there and everything worked fine.

Is it right, that this configuration key should be removed from CCDNUserSecurityBundle

update to support symfony 2.5

The dependencies defined for this bundle have an upper bound on the supported Symfony version. It should however work without changes with symfony 2.5 too. I've seen no backwards incompatible chanes from 2.4 to 2.5 that should affect this bundle.

Blocking doesn't work correctly when force_account_recovery is disabled

Given this config:

ccdn_user_security:
    entity:
        user:
            class: Netvlies\WbBundle\Entity\User
    route_referer:
        enabled: false
    login_shield:
        route_login:
            name:                  netvlies_wb_security_login
            params:                []
        force_account_recovery:    # Specify all routes to block after attempt limit is reached, and account recovery route to force browser redirect.
            enabled:               false
        block_pages:               # Specify all routes to block after attempt limit is reached.
            enabled:               true
            after_attempts:        5
            duration_in_minutes:   30
            routes:
                - netvlies_wb_security_login
                - login
                - login_check
                - logout

Also on our homepage (/ route) there is a small login form on top of the page. We don't want to add the homepage to the blocked routes list.

Now lets imagine a user tries 5 times to login with the wrong credentials. What we expect to happen:

  • user cannot visit /login route
  • user cannot trigger a login attempt any more

But what actually happens is that the of course can't open the /login route anymore but is still able to post to /login_check. When the credentials are false a 403 blocked page is shown, but when the credentials are correct the user is successfully logged in. In other words: its still possible to brute force accounts. When showing a small login form on your homepage, this actually is very easy for anyone.

I've been digging in the code and have found what causes this: the BlockingLoginListener has a lower priority then Symfony's Symfony\Component\Security\Http\Firewall listener. The Firewall is registered with a priority of 8 on the kernel.request.

To fix the brute force problem I've changed the priority of the BlockingLoginListener to 9. With force_account_recovery set to false everything works as expected. Unfortunately with force_account_recovery set to true (as in the Behat suite) this breaks things.

If we increase the priority of the BlockingLoginListener before the Firewall and we enable force_account_recovery then as soon as after_attempts is reached, the $event->stopPropagation() prevents the Firewall listener to actually trigger a (failure) login. This makes it impossible to reach the blocking level:

        if ($result == $securityManager::ACCESS_DENIED_DEFER) {
            $event->stopPropagation();

            $redirectUrl = $this->router->generate(
                $this->forceAccountRecovery['route_recover_account']['name'],
                $this->forceAccountRecovery['route_recover_account']['params']
            );

            $event->setResponse(new RedirectResponse($redirectUrl));
        }

I think in order to solve this problem we need to refactor BlockingLoginListener into two listeners: BlockingLoginListener with priority 9 on kernel.request and ForceAccountRecoveryListener with a lower priority then 8.
And perhaps split up the ClientLoginVoter into separate voters too.

Any thoughts on this @reecefowell ?

If I've some spare time I'm willing to do the refactoring. But not before we agree on the solution 😄 .

Reset account still not allowed to login

When a user got locked out due to exceeding number of failed attempts and proceed to reset their account and click the link, change password and so on, user still unable to get to the login page immediately and have to wait until the configured force_account_recovery duration. Is there not a way to reset the previous failed attempts once the customer successfully reset their password?

Unable to access Post data in site securitymanager.php

$request = $this->requestStack->getMasterRequest();
var_export($request->request->all());

returning empty array, even if we have posted a form with username and password.

Any thoughts?

FILE:
D:\xampp\htdocs\staging\vendor\codeconsortium\ccdn-user-security-bundle\CCDNUser\SecurityBundle\Component\Authorisation\SecurityManager.php

php version requirement mismatch

the composer.json says >= 5.3.2, but the readme says 5.4. If it really is 5.4, is there any way it could be adjusted for >=5.3.2 ?

Disable SecurityManager voter for commands

I use isGranted method inside a Symfony command:

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        ...
        $this->getContainer()->get('security.context')->isGranted(...)
        ...
    }

and I get this error:

PHP Fatal error: Call to a member function get() on a non-object in ...\vendor\codeconsortium\ccdn-user-security-bundle\CCDNUser\SecurityBundle\Component\Authorisation\SecurityManager.php on line 101

It seems Synfony call your CCDNUser\SecurityBundle\Component\Authorisation\SecurityManager voter and there is no request as no HTTP request is being done.

How can I disable CCDNUserSecurityBundle with commands? if it´s not possible, is there a way to avoid this problem?

Document minimal usage of CCDNUserSecurityBundle without FOSUserBundle

We introduced CCDNUserSecurityBundle in our project without using FOSUserBundle and it works. I think it would be helpful also for others to provide a documentation section that starts from a minimal introduction of CCDNUserSecurityBundle and adds features (and configuration) step by step.
(Pull Requests welcome, I assume...)

Block Page on Mobile Device

I do have
ccdn_user_security:
entity:
user:
class: Application\SonataUserBundle\Entity\User # Required
login_shield:
route_login:
name: sonata_user_admin_security_login
params: []
force_account_recovery: # Specify all routes to block after attempt limit is reached, and account recovery route to force browser redirect.
enabled: true
after_attempts: 2
# !!! check also the Default controller for timing the cookie also
duration_in_minutes: 2
route_recover_account:
name: help
params: []
routes:
- fos_user_security_login
- fos_user_security_check
- fos_user_security_logout
block_pages: # Specify all routes to block after attempt limit is reached.
enabled: true
after_attempts: 3
duration_in_minutes: 3
...
and also

  • sonata_user_admin_security_login

under block pages...

It seems to work correctly under chrome browser on laptops but on Android device Chrome does not block the page after 3-10 wrong logins...

Any ideea how to fix it ?

Provide a method to clean the session table

The cc_security_session table accumulates all failed login attempts but is never cleaned so it grows without bounds. This might also be a privacy issue because this table can contain IP adresses from legitimate users too, who just forgot their password.

Is there a standard method in Symfony to distribute cronjobs in a Symfony bundle? Maybe one could provide some command that can be executed once an hour or day to delete old entries from the cc_security_session table.

Symfony 2.7

The composer.json imposes a limit of "symfony/symfony": "~2.5" - is the upper bound strictly necessary?

Symfony 2.7 is the current LTS.

Symfony 2.7 ready?

Hi,

Symfony 2.7 was just released and bundle have <2.7 constraint.

Regards.

Depend on individual Symfony components

Before we used CCDNUserSecurityBundle, we had a list of the individual Symfony components that we depend on. Since CCDNUserSecurityBundle has a dependency on Symfony/Symfony we had to finally make the step to depend on the full Symfony distribution.
It was not such a problem in our case, but it might be for others. So maybe it would be better if CCDNUserSecurityBundle would depend just on the Symfony components that are real dependencies.

What is the purpose of the login/logout handlers?

The LoginFailureHandler adds the failed login attempts to the cc_security_session table. But couldn't that be done in a listener?

And the redirection logic in all the handlers, isn't this a code duplication with what is already provided by Symfony? Plain Symfony already provides means to redirect the user to the last seen page before the login attempt.

MappingException when running PHPUnit

Hi,

I face a problem when running PHPUnit tests with PHP5.6 under Jenkins, it returns me this error :
Doctrine\Common\Persistence\Mapping\MappingException: Invalid mapping file "CCDNUser.SecurityBundle.Entity.Session.orm.yml" for class "CCDNUser\SecurityBundle\Entity\Session" at n/a in /var/lib/jenkins/jobs/MyProject/workspace/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php line 86

Do you have any idea of why this happens?
The schema seems to be valid, in sync with the entity.

Thanks,
Nicolas

Support error messages of login form from FOSUserBundle

Currently error messages of login form from FOSUserBundle are missing when using this bundle, because the logic of handling error message shall be handled from handler implementing AuthenticationFailureHandlerInterface. Error messages shall be set to session appropriately in the failure handler.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.