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

feat: add magic link force login config #1135

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

warcooft
Copy link

@warcooft warcooft commented Jun 22, 2024

Description

This feature provides config for developers so that the behavior when checking user sessions in the startLogin function can be easily controlled. So the user does not need to log out to assign a new user session.

We also set the default value in that configuration to false to preserve the previous behavior

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

// Check if already logged in.
if ($userId !== null) {
// Check if already logged in and magic link force login config.
if ($userId !== null && config('Auth')->allowMagicLinkForceLogin === false) {
Copy link
Member

Choose a reason for hiding this comment

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

This seems to invalidate the following security check.
So I think this is a security hole.

Copy link
Author

@warcooft warcooft Jun 22, 2024

Choose a reason for hiding this comment

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

should we delete the old session and then continue its state safely?

@@ -23,6 +23,15 @@ in the **app/Config/Auth.php** file.
public int $magicLinkLifetime = HOUR;
```

### Magic Link Force Login

By default, Magic Link will throw Logic exception if current user session is exist. If you want replace existing user session with new user session change it to `true`
Copy link
Member

Choose a reason for hiding this comment

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

LogicException means, "your code has a bug, so please fix it".
So I never accept a flag to disable LogicException.
This PR seems to be wrong implementation.

First of all, why a logged in user uses magic link login?

Copy link
Author

@warcooft warcooft Jun 22, 2024

Choose a reason for hiding this comment

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

I submit a magicLink request using the incognito browser, then the magicLink sends an email to my my gmail in main browser. when opened it will cause a LogicException because in my main browser I am already logged in.

Copy link
Author

Choose a reason for hiding this comment

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

But this scenario rarely happens in real cases. this case often occurs when development involves switching accounts with specific roles.

@kenjis
Copy link
Member

kenjis commented Jun 24, 2024

I submit a magicLink request using the incognito browser, then the magicLink sends an email to my my gmail in main browser. when opened it will cause a LogicException because in my main browser I am already logged in.

This could happen rarely.
In this case, the CodeIgniter\Shield\Exceptions\LogicException should not happen.
But I don't think you should be logged out automatically and logged in with the magic link.
Because this scenario is not a normal use case.
Showing the message with "you are already logged in as ..." is better?

@kenjis
Copy link
Member

kenjis commented Jun 24, 2024

this case often occurs when development involves switching accounts with specific roles.

Shield does not have a feature to switch accounts.
When you are logged in, if you navigate to login or login/magic-link, you will be redirected.

@kenjis kenjis added the bug Something isn't working label Jun 24, 2024
@warcooft
Copy link
Author

I submit a magicLink request using the incognito browser, then the magicLink sends an email to my my gmail in main browser. when opened it will cause a LogicException because in my main browser I am already logged in.

This could happen rarely. In this case, the CodeIgniter\Shield\Exceptions\LogicException should not happen. But I don't think you should be logged out automatically and logged in with the magic link. Because this scenario is not a normal use case. Showing the message with "you are already logged in as ..." is better?

I agree instead of displaying exception/whoops page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants