Skip to content

[6.x] Elevated Sessions #11688

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

Merged
merged 35 commits into from
Apr 25, 2025
Merged

[6.x] Elevated Sessions #11688

merged 35 commits into from
Apr 25, 2025

Conversation

duncanmcclean
Copy link
Member

@duncanmcclean duncanmcclean commented Apr 10, 2025

This pull request introduces the concept of "elevated sessions", which prompts you for your password before allowing you to take certain actions. Similar to GitHub's sudo mode.

CleanShot 2025-04-24 at 16 21 39

After "starting" an elevated session, you won't be prompted for your password again until the session expires. By default, elevated sessions last for 15 minutes.

For now, I've implemented this in front of the following actions:

  • Changing another user's password
  • Copying a password reset link
  • Updating permissions on a role
  • Impersonating a user

We'll also use this in #11664 before allowing you to view recovery codes, or deactivate 2FA on your account.

Extending

Addon developers can require elevated sessions in their code by applying the RequireElevatedSession middleware to applicable routes, and using the requireElevatedSession JS function.

Route::get('foo', [FooController::class, 'index'])
  ->middleware(RequireElevatedSession::class);
import { requireElevatedSession } from '@statamic';

methods: {
    submit() {
        requireElevatedSession()
            .then(() => this.actuallySubmit())
            .catch(() => {});
    },
    actuallySubmit() {
        // ...
    }
}

Otherwise, `$user->password()` will error out when storing users in a database.
…rd. When you update your own you have to enter your own password anyway.
If we want to use that for reasons other than testing, a timestamp is more accurate.
- When middleware is on a route that is accessed directly, redirect to a form page.
- Middleware throws an exception
- The exception will render json or perform appropriate redirect
- Middleware test uses an actual route so redirects can be tested
…checking ...

Say you have the expiration set to 1 hour.
Someone elevates. Their expiry is 1 hour in the future.
You change the config to 15 minutes.
The user is still elevated for the whole hour.

This change allows the config to be changed and existing sessions will comply.
This was added to confirm passwords while impersonating.

If you have permission to impersonate anyway, it's not really preventing anything.
@jasonvarga jasonvarga marked this pull request as ready for review April 25, 2025 16:13
@jasonvarga jasonvarga merged commit 74adbaf into master Apr 25, 2025
19 checks passed
@jasonvarga jasonvarga deleted the elevated-sessions branch April 25, 2025 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants