Use an EventSubscriber to protect one time login links

Created on 8 October 2023, over 1 year ago

Problem/Motivation

Prior to SA-CONTRIB-2023-030 we had no protection for one-time-login links.

In SA-CONTRIB-2023-030 we extended the UserController class (which is @internal) and replaced the controller with the TfaUserController.

This makes us very tightly coupled to Core API. In the existing fix we already have multiple classes to deal with different signatures based on the version of core deployed. Because of this it was decided to not roll into 2.x and instead look for an alternative method.

Switching to an EventSubscriber we will still have a minor coupling to core API, however the route name is to my knowledge @api so that it should not change between minor or patch releases.

Our remaining coupling would be with regards to internal token names and route paramters. Our existing deployment in 1.x is already sensitive to token names.

Converting to an event subscriber should allow us to significantly de-couple from core compared to our existing implementation.

The largest concern is does an EventSubscriber provide reasonable protection.
As it currently exists in the 1.x branch we overwrite the controller route so that our class initially processes all requests for password resets. The current risks are that an additional route could be added, or that another module could override the route removing our controller class.

With an event controller:
We have a risk of additional routes potentially being added that we may not protect. This risk is similar to what already exists with the 1.x implementation.
That another EventSubscriber could act on the request prior to our subscriber. This is a new risk, however for this to cause an issue the subscriber would need to render the page without calling the remainder of the stack, this would be unlikely for a contrib module to do so.

Steps to reproduce

N/A

Proposed resolution

Patch

Remaining tasks

Patch

User interface changes

Entryform will be prompted for One Time Login links in 2.x, this is parity with 1.x

API changes

No public API changes.

Data model changes

πŸ“Œ Task
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States cmlara

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @cmlara
  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    πŸ“Œ Move TfaLoginContextTrait back to a dedicated Class and add factory. Active would make implementing this easier, primarily from a testing point of view less data would need to be mocked.

  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    Opened MR,

    This will use an event subscriber to protect the One Time Login route

    Important notes:
    I'm not 'burning' the One Time when they get redirected to the entry form, instead allowing the existing Core code to do so after login. I believe this is reasonable. Justification for this being the link isn't actually used just by having the link, you still need the second factor to prove your using it. This also helps out with avoiding πŸ› Bingpreview invalidates one time login links Active

    There is no flood protection on the OTP links. I'll leave this one for discussion. We currently match core's lack of having a flood protection on the password reset link, however I wonder if we should go more in depth than core and protect these paths as well.

  • πŸ‡ΊπŸ‡ΈUnited States cmlara
  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    Protection was added in πŸ› Installing contrib modules can lead to TFA accidently being bypassed Fixed .

    This issue only needs to allow access for users which do not require TFA and redirects users that require TFA to the EntryForm.

    The new implementation should be "Fail Secure" as tampering with the new code or adding alternative routes will not allow access.

  • First commit to issue fork.
  • πŸ‡°πŸ‡¬Kyrgyzstan elaman

    elaman β†’ changed the visibility of the branch 3392427-use-an-eventsubscriber-spr to hidden.

  • πŸ‡°πŸ‡¬Kyrgyzstan elaman

    @cmlara I've been working on checking if Simple Reset Password can be made to work with TFA. Created draft MR based on MR, please feel free to check it let me know what needs can be improved to include it in your MR. Thank you

  • Pipeline finished with Failed
    9 months ago
    Total: 231s
    #285569
  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    @elaman My goal in referring you to this issue was to see if there are any changes that does not require implementing module specific workarounds.

    If you can see any other changes to !57 based on your knowledge of Simple Password Resets order of operations that would allow it to function without specific knowledge I would be willing to look at those in this issue.

    If there is no way to allow Simple Password Reset to work without module specific knowledge we will need to return back to ✨ Support Simple Password Reset module Postponed .

  • Pipeline finished with Failed
    9 months ago
    Total: 250s
    #296784
  • Pipeline finished with Failed
    9 months ago
    Total: 182s
    #296861
  • Pipeline finished with Failed
    9 months ago
    Total: 333s
    #296879
  • Pipeline finished with Failed
    9 months ago
    Total: 242s
    #299171
  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    Will need to evaluate if this requires any changes to align with SA-CONTRIB-2024-043

  • Pipeline finished with Failed
    8 months ago
    Total: 178s
    #335429
  • Pipeline finished with Canceled
    8 months ago
    Total: 32s
    #336300
  • Pipeline finished with Canceled
    8 months ago
    Total: 33s
    #336304
  • Pipeline finished with Canceled
    8 months ago
    Total: 33s
    #336306
  • πŸ‡³πŸ‡ΏNew Zealand Gold 20 minutes in the future

    Hey all,

    Just wondering on the status of this ticket. It looks like there's been no movement on MR57 since early Feb. Should this be in a Needs Review state? That is something I can contribute to. :)

  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    Was reviewing this a week ago, the main change I wanted was to make classes final. I have pushed those up today.

    This could use additional eyes.

  • πŸ‡³πŸ‡ΏNew Zealand Gold 20 minutes in the future

    Nice. Functionally, this is doing the job. :)

    I ran it through phpcs and it only raised one minor issue. I don't see that as being enough of a reason to prevent this from being marked RTBC though.

    Thanks @cmlara for the effort on this.

  • πŸ‡³πŸ‡ΏNew Zealand Gold 20 minutes in the future

    Hey all,

    Just back from DrupalSouth and checking up on issues. Just wondering if there is anything I can to do help push this one over the line?

    Cheers,
    Gold

  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    Was primarily allowing a little more time for anyone who might want to provide feedback since this decently significant code.

    This is one the areas that has had security vulnerabilities in the past, including 2 weeks ago (note: the report that triggered two weeks ago would not have been allowed either with existing 2.x branch or the 2.x branch and this code.

    That said I believe this is ready to go in and anything else can be followups.

    Letting final test run occur after removing unused code and will merge.

    Regarding Simple Password Reset:
    Recent data indicates Password Reset Landing Page (PRLP) may be better aligned to API and provides a similar feature set. Currently PRLP does not work with this code however PRLP may be in a better spot than Simple Password Reset to modify their process to work with TFA.

    • cmlara β†’ committed 94411a51 on 2.x
      Issue #3392427 by cmlara, gold: Use an EventSubscriber to process one...
  • πŸ‡ΊπŸ‡ΈUnited States cmlara
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024