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

IBX-5361: Implemented handling of NotCompromisedPassword constraint #221

Merged
merged 11 commits into from
Apr 18, 2023

Conversation

glye
Copy link
Contributor

@glye glye commented Mar 21, 2023

Question Answer
JIRA issue IBX-5361
Type feature
Target Ibexa version v4.5
BC breaks no

Implement the https://haveibeenpwned.com/ API, to verify that passwords do not exist in known password dumps from security breaches, using Symfony's NotCompromisedPassword constraint. Disabled by default, for BC and for not doing requests to this external API without the knowledge of the site owners.

Admin UI for this: ibexa/admin-ui#750

Documentation
The password rules page would need documentation for this feature.

Limitations
Since this is done in the password validator, and passwords are only validated when created or changed, there is no warning message when already existing bad passwords are used to log in. That could also be useful, but it means a whole lot more requests to this API, most of which would be pointless repetitions. We could limit it to only one check per password hash, and unset that bit when the hash changes. But if the check is enabled, further login checks are again pointless, so we'd need to take that into account too, and it gets complicated. Might be better to just add an extra button to the login form: "Check if my password has been exposed". Then the users have the choice. But let's do that in a separate PR, if at all.

Our permission to use the API
AFAICT, while you need to buy an API key to use the email/username based haveibeenpwned search, there is no such requirement for the password based search. There is also no rate limiting or attribution requirement, as they say: "In order to help maximise adoption, there is no licencing or attribution requirements on the Pwned Passwords API, although it is welcomed if you would like to include it." https://haveibeenpwned.com/API/v3
It would be nice of us to attribute them anyway, and donate/sponsor, of course.

Checklist:

Screenshot
screenshot

@adamwojs
Copy link
Member

@glye Could you please take a look on CI failure ?

@glye glye force-pushed the ibx5361-use_NotCompromisedPassword_constraint branch 4 times, most recently from 94c5607 to 0d5b5bc Compare March 24, 2023 15:27
@glye glye marked this pull request as draft March 28, 2023 12:03
@adamwojs
Copy link
Member

@adamwojs You agree the feature is useful, right?

Indeed, but please ensure that we can safety use https://haveibeenpwned.com/ (from company product/perspective)

I'm stuck on getting CI to inject the Symfony @validator service, CI can't find it. I thought it would be simple since the Generic fieldtype already uses the validator, but no such luck

Probably you have to create validator service definition on your own. Some tips:

@glye
Copy link
Contributor Author

glye commented Mar 28, 2023

@adamwojs Added notes on our permission to use the API in the description. It is free and open.
I also avoided injecting it altogether, so there is no need for a service. This seemed sensible to me for such a limited usecase.

@glye glye force-pushed the ibx5361-use_NotCompromisedPassword_constraint branch 2 times, most recently from 880ee86 to 93db3d8 Compare March 29, 2023 17:00
@glye glye force-pushed the ibx5361-use_NotCompromisedPassword_constraint branch from cc6b4b3 to 3c661ed Compare March 30, 2023 13:22
@glye
Copy link
Contributor Author

glye commented Mar 30, 2023

The sonarcloud failure is only due to duplicated lines, and is wrong in this case imho.

@glye glye marked this pull request as ready for review March 30, 2023 13:51
@glye glye added Doc needed The changes require some documentation Ready for review and removed Work in progress labels Mar 30, 2023
@alongosz alongosz requested review from alongosz and a team March 30, 2023 13:58
@konradoboza konradoboza requested a review from a team March 31, 2023 09:59
Copy link
Member

@alongosz alongosz left a comment

Choose a reason for hiding this comment

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

The sonarcloud failure is only due to duplicated lines, and is wrong in this case imho.

It's not wrong. We have exactly the same configuration expectation for unit & integration test duplicated and redundant. By modifying these lines of code we increase technical debt.

What needs to be done here is extracting that configuration into a common provider.

For example:

declare(strict_types=1);

namespace Ibexa\Tests\Core\FieldType\DataProvider;

/**
 * @internal
 */
final class UserValidatorConfigurationSchemaProvider
{
    /**
     * @return array<string, array<string, array{type: string, default: ?scalar}>>
     */
    public function getExpectedValidatorConfigurationSchema(): array
    {
        return [
            'PasswordValueValidator' => [
                // ... duplicated code
            ],
        ];
    }
}

And then use it in:

  • \Ibexa\Tests\Core\FieldType\UserTest::getValidatorConfigurationSchemaExpectation
  • \Ibexa\Tests\Core\FieldType\DataProvider\UserValidatorConfigurationSchemaProvider::getExpectedValidatorConfigurationSchema
    as:
        return (new UserValidatorConfigurationSchemaProvider())
            ->getExpectedValidatorConfigurationSchema();

src/lib/FieldType/User/Type.php Outdated Show resolved Hide resolved
@glye
Copy link
Contributor Author

glye commented Apr 17, 2023

What needs to be done here is extracting that configuration into a common provider.

@alongosz Done, thanks.

@glye glye requested a review from alongosz April 17, 2023 15:00
@alongosz alongosz force-pushed the ibx5361-use_NotCompromisedPassword_constraint branch from 5d83065 to 36c6bdf Compare April 18, 2023 10:22
@sonarcloud
Copy link

sonarcloud bot commented Apr 18, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@alongosz alongosz changed the title IBX-5361: Use NotCompromisedPassword constraint IBX-5361: Implemented handling of NotCompromisedPassword constraint Apr 18, 2023
@alongosz alongosz merged commit ee822d8 into main Apr 18, 2023
@alongosz alongosz deleted the ibx5361-use_NotCompromisedPassword_constraint branch April 18, 2023 11:33
@alongosz
Copy link
Member

Thank you @glye 🎉

@DominikaK DominikaK removed the Doc needed The changes require some documentation label Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature request QA approved
Projects
None yet