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

Lockout guides pilot #512

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
989e479
Initial push
rachelnabors Nov 7, 2023
13c1c86
Initial push
rachelnabors Nov 7, 2023
aae4a59
Add user_lockout info under /docs/custom-flows/error-handling and loc…
yourtallness Nov 10, 2023
51b66c0
moving file to right folder
rachelnabors Nov 10, 2023
8376c84
introducing the 5 W's of user lockout
rachelnabors Nov 10, 2023
e650804
adding more configuration guides and images. The images don't show fo…
rachelnabors Nov 10, 2023
4ad9050
Merge branch 'main' into lockout-docs
rachelnabors Nov 10, 2023
b51a973
Adding links to pre-reqs
rachelnabors Nov 10, 2023
83875cf
Add a /custom-flows/account-lockout page to cover custom usage of loc…
yourtallness Nov 13, 2023
b0a93da
Fix typo in useOrganizationList (#492)
cmayoracurzio Nov 13, 2023
5a2bd9b
Use <TutorialHero /> component in NextJS quickstart header (#478)
alexisintech Nov 14, 2023
d651436
Update sign-out-button.mdx (#484)
singhjatin297 Nov 14, 2023
df6a22d
feat: Add note about MDP for LinkedIn OAuth provider (#489)
kostaspt Nov 14, 2023
6f5230e
Restore missing image (#491)
kostaspt Nov 14, 2023
b09bc8a
Added status information to both hooks (#403)
royanger Nov 15, 2023
c3eec4a
Update organization-switcher.mdx (#493)
jshek-clerk Nov 16, 2023
df6c26e
Fix Expo SIgn Up Example (#497)
JustMendex Nov 17, 2023
fd45f73
adding the final bit on overriding a lockout
rachelnabors Nov 20, 2023
63f2bdf
adding the last screenshot and numbered listing
rachelnabors Nov 20, 2023
3b2255e
Merge branch 'main' into lockout-docs
rachelnabors Nov 20, 2023
b5855d0
updating picture names
rachelnabors Nov 20, 2023
df6ac5d
converting pre-reqs to info callout
rachelnabors Nov 20, 2023
bcd2a1b
making the step-by-step instructions more concise
rachelnabors Nov 20, 2023
21c2a3b
updating the naming convention and editing the custom flow doc
rachelnabors Nov 20, 2023
fd308e6
adding unlocking via profile
rachelnabors Nov 21, 2023
c3d5371
updating language for user locks
rachelnabors Nov 22, 2023
0d8e088
adding guide section and grouping the user lock docs into one section
rachelnabors Nov 23, 2023
cdcd710
fixing borked links
rachelnabors Nov 23, 2023
5aa22c7
updating title
rachelnabors Nov 23, 2023
2138a87
updating title
rachelnabors Nov 23, 2023
db92b49
fix url type
rachelnabors Nov 23, 2023
e04eb8b
updating phrasing
rachelnabors Nov 23, 2023
4a2b6b8
small updates
rachelnabors Nov 23, 2023
485aaab
giving all meta descriptions
rachelnabors Nov 23, 2023
c29f5a1
Updating links and images locations
rachelnabors Nov 29, 2023
a329946
updating screenshots
rachelnabors Nov 29, 2023
ed9ad99
Merge branch 'main' into lockout-docs
rachelnabors Nov 29, 2023
2c7fe22
relocating images to security folder
rachelnabors Nov 29, 2023
1273c91
updating screenshots
rachelnabors Nov 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion docs/custom-flows/error-handling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,31 @@ const signIn = await client.signIn.create({
.then((result) => console.log("result", result))
.catch((err) => console.error("error", err.errors[0].message));
```
</CodeBlockTabs>
</CodeBlockTabs>

## Special error cases

### User locked

If you have Account Lockout enabled on your instance and the user reaches the maximum allowed attempts for password or
backup code verification, you will receive an HTTP status of 403 (Forbidden) and the following error payload:


```json
{
"errors": [
{
"message": "Account locked",
"long_message": "Your account is locked. You will be able to try again in 30 minutes. For more information, please contact support.",
"code": "user_locked",
"meta": {
"duration_in_seconds": 1800
}
}
]
}
```

Note: Actual remaining duration will vary depending on your configuration.
rachelnabors marked this conversation as resolved.
Show resolved Hide resolved

You can opt to render the error message returned as-is or format the supplied `duration_in_seconds` as per your liking.
35 changes: 35 additions & 0 deletions docs/guides/customize-user-lockout.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: Customize max login attempts and duration of user lockout
description:
---

# Customize the max attempts before getting locked out and duration of lock out

<Callout type="info">
This feature is only available for user accounts that use [passwords](https://dashboard.clerk.com/last-active?path=user-authentication/email-phone-username) and [backup codes](https://dashboard.clerk.com/last-active?path=user-authentication/multi-factor).
rachelnabors marked this conversation as resolved.
Show resolved Hide resolved
</Callout>

1. In your [Clerk Dashboard](https://dashboard.clerk.com/), navigate to **User & Authentication > [Attack Protection](https://dashboard.clerk.com/last-active?path=user-authentication/attack-protection)**.
2. To change the number of failed attempts before a user is locked out, under **Maximum attempts,** select "Custom attempts" and enter a new number of failed attempts allowed. (The default is 100 attempts.)
3. To change the duration, under **Duration,** select "Custom duration" and select the unit of time (minutes/hours/days/years) and enter the number of units you want lockouts to last.
4. Select "Apply changes" to apply your settings.

<Images
width={1512}
height={914}
src="/docs/images/guides/userlock_custom-attempts-and-duration.png"
alt=" "
/>

## Lock a user account forever until an admin unlocks the account

1. In your [Clerk Dashboard](https://dashboard.clerk.com/), navigate to **User & Authentication > [Attack Protection](https://dashboard.clerk.com/last-active?path=user-authentication/attack-protection)**.
2. Under **Duration,** select "Indefinitely."
3. Select "Apply changes" to apply your settings.

<Images
width={1512}
height={914}
src="/docs/images/guides/userlock_indefinite.png"
alt=" "
/>
8 changes: 8 additions & 0 deletions docs/guides/overview.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Clerk Guides
description: Learn how to use Clerk's components, APIs and the Clerk Dashboard together to protect your users and authenticate your application.
---

# Clerk Guides

Clerk provides a suite of [prebuilt components](/docs/components/overview) for getting your app authenticated fast, the [Clerk Dashboard](https://dashboard.clerk.com/) for managing your users' accounts and identies, and a [backend API](https://clerk.com/docs/reference/backend-api) for tailoring custom flows to your design and app needs. These guides show you how to use these features together to build delightful, safe, and secure experiences.
33 changes: 33 additions & 0 deletions docs/guides/programmatically-lock-user-accounts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: Programmatically locking and unlocking user accounts
description: Lock users to prevent them from signing in based on your own custom criteria.
---

# Programmatically locking and unlocking user accounts

## Unlocking a user programmatically

You can programmatically unlock a user using the [UnlockUser](https://clerk.com/docs/reference/backend-api/tag/Users#operation/LockUser) Backend API operation.

## Usecases

### "Unlock button"

Your custom sign-in page could expose a button or link to request an unlock token when they are locked out of their account.

* Your app should be able to generate a random unlock token and associate it with the user.
* The unlock token can be sent to the user via email or SMS.
* After successful entry of the unlock token, your app's backend can issue an unlock request to the Clerk Backend API.

### Send an unlock request to an admin

If your app supports users submitting admin requests, it could expose a way of requesting an admin unlock.

* A request for unlock could arrive in your app's admin dashboard.
* If an admin reviews the request and decides to grant access back to the user, they can request an unlock from your app's backend, which should in turn call the Clerk Backend API.

# Locking a user programmatically

You can programmatically lock a user based on your own custom criteria, e.g. if they are violating your app's code of conduct.

You can do so via the [LockUser](https://clerk.com/docs/reference/backend-api/tag/Users#operation/LockUser) Backend API operation. Keep in mind that Clerk will still lock the user based on failed verification attempts.
33 changes: 33 additions & 0 deletions docs/guides/unlock-user-accounts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: Unlock user accounts from the Clerk Dashboard
description:
---

# Unlock user accounts from the Clerk Dashboard

<Callout type="info">
This feature is only available for user accounts that use [passwords](https://dashboard.clerk.com/last-active?path=user-authentication/email-phone-username) and [backup codes](https://dashboard.clerk.com/last-active?path=user-authentication/multi-factor).
</Callout>

Users with admin roles can override lockouts through the Clerk dashboard.

1. In your [Clerk Dashboard](https://dashboard.clerk.com/), navigate to **[Users](https://dashboard.clerk.com/last-active?path=users)**.
2. Locate the locked user by looking for a "locked" badge next to their username/email.
3. Open the admin menu (three little dots).
4. Select "Unlock" to unlock the user account.

<Images
width={1512}
height={914}
src="/docs/images/guides/userlock_dashboard.png"
alt=" "
/>

Alternatively, you can unlock a user's account on their profile page by scrolling to the "Unlock user" section and selecting "Unlock user."

<Images
width={1512}
height={914}
src="/docs/images/guides/userlock_profile.png"
alt=" "
/>
37 changes: 37 additions & 0 deletions docs/guides/user-lock-guide.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: Brute force attacks and locking user accounts
description:
---

# Brute force attacks and locking user accounts

User accounts are a vector for malicious attacks for many reasons from impersonation to collecting personally identifiable information (PII). One method is a "brute force" attack, where a script will attempt many different passwords to log into an account. One line of defense against these attacks is to temporarily deny attempts to log into accounts that attempt too many failed logins in a short period of time. Locking out login attempts disrupts the attack and makes the account a less attractive target.

## How Clerk protects against brute force attacks

**Account Lockout** is a Clerk feature that enables you to protect your users from brute-force attacks on static credentials such as passwords and backup codes. If enabled on your instance, Clerk will automatically track users' failed verification attempts when they try to authenticate via password on backup code.
rachelnabors marked this conversation as resolved.
Show resolved Hide resolved

### How Account Lockout works

If the maximum allowed attempts are reached, the user will be locked out from signing in again until the lockout duration lapses. Lockout can also be [configured to never expire](/docs/guides/customize-user-lockout#lock-a-user-account-forever-until-an-admin-unlocks-the-account), in which case the user will not be able to sign in unless an admin unlocks them.

An admin can [unlock a user before the expiry of the lockout period via the Clerk dashboard](/docs/guides/unlock-user-accounts).

### Defaults

By default, Clerk applications with will lock user accounts after 100 failed login attempts and require a one hour cool down period before anyone can attempt to log into that account again. (While 100 attempts may seem like a lot to a human, it is very easy to reach this maximum for a bot!)

## What a locked out user sees

When a user exceeds the maximum login attempts, the Clerk [`<SignIn />`](/docs/components/authentication/sign-in) component will inform them how long they've been locked out and to contact support for more information.

<Images
width={1512}
height={914}
src="/docs/images/guides/userlock_login.png"
alt="The Clerk component login form with a red alert stating 'Your account is locked. You will be able to try again in 59 minutes. For more information, please contact support.'"
/>

<Callout type="info">
Currently, users cannot unlock their own account or submit a request to the admin to be unlocked ("self-service unlock"). This is an upcoming feature, so please check our [changelog](https://clerk.com/blog) periodically to find out when it is available. Until then, you can [programmatically lock and unlock user accounts with a custom flow](/docs/guides/programmatically-lock-user-accounts).
</Callout>
1 change: 1 addition & 0 deletions docs/integrations/webhooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Below is an example of a webhook payload for a `user.created` event:
"gender": "",
"id": "user_29w83sxmDNGwOuEthce5gg56FcC",
"last_name": "Example",
"locked": false,
"last_sign_in_at": 1654012591514,
"object": "user",
"password_enabled": true,
Expand Down
17 changes: 16 additions & 1 deletion docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@
["Fastify", "/quickstarts/fastify"]
]
],
[
{
"title": "Guides",
"icon": "book-open",
"root": "guides"
},
[ ["Overview","/guides/overview"],
"# Protect accounts from attacks",
["Brute force attacks and locking user accounts","/guides/user-lock-guide"],
["Customize user lockout duration and login attempts limits", "/guides/customize-user-lockout"],
["Unlock accounts from the Clerk Dashboard", "/guides/unlock-user-accounts"],
["Programmatically lock and unlock accounts", "/guides/programmatically-lock-user-accounts"]
]
],
"---",
[
{
Expand Down Expand Up @@ -293,7 +307,7 @@
],
[
{
"title": "Migrations & Deployments",
"title": "Deployments & Migrations",
"icon": "rocket",
"root": "deployments"
},
Expand Down Expand Up @@ -341,6 +355,7 @@
["Email Deliverability", "/troubleshooting/email-deliverability"],
["Script Loading", "/troubleshooting/script-loading"],
"# Help & Support",
["Create a minimal reproduction", "/troubleshooting/create-a-minimal-reproduction"],
["Community Discord", "https://clerk.com/discord"],
["Contact Support", "https://clerk.com/support"]
]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/guides/userlock_dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/guides/userlock_indefinite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/guides/userlock_login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/guides/userlock_profile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.