-
Notifications
You must be signed in to change notification settings - Fork 513
docs: Document Turnstile fraud protection and new sign-up rule conditions #1278
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
Changes from all commits
aa6c473
592ad1e
910646e
9f85689
abdccaa
0dab510
81bec2a
a5f516f
e811d40
7e4861c
d8eda3d
4277e58
17a6676
46ea0af
eed6935
c0c9faa
3c966ae
8479581
9c2e51a
c7b72b6
e5aef62
11f62de
f37e7f7
49e9e4f
6b0c3e9
1b7a5ea
a47bbde
12ca89a
4e576ab
3f3bd1e
73fdf38
9eec41c
c1abfee
21ca337
0abd502
29e1d93
4887d80
b3c0a61
3ece21f
4c38c8b
bb1d92e
6dc205e
8d6d068
e6d6102
9843dd4
3142013
bfbbc3d
91ea98e
a6eaa9a
a372402
17f8c4c
8f58373
452fb1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| --- | ||
| title: Self-host | ||
| lastModified: "2026-01-10" | ||
| lastModified: "2026-03-20" | ||
| --- | ||
|
|
||
| <Info type="danger"> | ||
|
|
@@ -121,3 +121,23 @@ To manage your dashboard configs with this account, manually go into the databas | |
| Go back to the dashboard, refresh the page, and you should see the "Stack Dashboard" project. We recommend disabling new user sign-ups to your internal project to avoid unauthorized account and project creations. | ||
|
|
||
| Now, create a new project for your app and follow the [normal setup process](../getting-started/setup.mdx). Add `NEXT_PUBLIC_STACK_API_URL=https://your-backend-url.com` to your app's environment variables so that it connects to your API backend instead of the default Stack Auth API backend (https://api.stack-auth.com). | ||
|
|
||
| ## Bot protection (Turnstile) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Citation: Turnstile environment variables documented based on |
||
|
|
||
| Stack Auth uses Cloudflare Turnstile to protect sign-up flows from bots. By default, self-hosted instances use Cloudflare's development test keys, which always pass without showing a challenge. | ||
|
|
||
| For production, configure your own Turnstile keys from the [Cloudflare Dashboard](https://dash.cloudflare.com/?to=/:account/turnstile): | ||
|
|
||
| | Environment Variable | Description | | ||
| |---------------------|-------------| | ||
| | `NEXT_PUBLIC_STACK_BOT_CHALLENGE_SITE_KEY` | Turnstile site key for visible challenges. | | ||
| | `NEXT_PUBLIC_STACK_BOT_CHALLENGE_INVISIBLE_SITE_KEY` | Turnstile site key for invisible challenges. | | ||
| | `STACK_TURNSTILE_SECRET_KEY` | Turnstile secret key for server-side verification. | | ||
|
|
||
| Optional settings: | ||
|
|
||
| | Environment Variable | Description | | ||
| |---------------------|-------------| | ||
| | `STACK_DISABLE_BOT_CHALLENGE` | Set to `true` to disable Turnstile entirely. | | ||
| | `STACK_ALLOW_SIGN_UP_ON_VISIBLE_BOT_CHALLENGE_FAILURE` | Set to `true` to allow sign-ups even when the visible challenge fails (not recommended for production). | | ||
| | `STACK_TRUSTED_PROXY` | Set to `vercel` or `cloudflare` to trust the respective reverse proxy for reading client IP addresses. Required for accurate IP-based fraud detection when running behind a proxy. | | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1609,14 +1609,16 @@ The `ServerUser` object contains most `CurrentUser` properties and methods with | |
|
|
||
| ### Table of Contents | ||
|
|
||
| <ClickableTableOfContents | ||
| <ClickableTableOfContents | ||
| title="ServerUser Table of Contents" | ||
| code={`type ServerUser = | ||
| code={`type ServerUser = | ||
| // Inherits most functionality from CurrentUser | ||
| & Omit<CurrentUser, "getAuthJson" | "signOut"> //$stack-link-to:#currentuser | ||
| & { | ||
| lastActiveAt: Date; //$stack-link-to:#serveruserlastactiveat | ||
| serverMetadata: Json; //$stack-link-to:#serveruserservermetadata | ||
| countryCode: string | null; //$stack-link-to:#serverusercountrycode | ||
| riskScores: { signUp: { bot: number; freeTrialAbuse: number } }; //$stack-link-to:#serveruserriskscores | ||
|
|
||
| update(data): Promise<void>; //$stack-link-to:#serveruserupdate | ||
|
|
||
|
|
@@ -1656,6 +1658,41 @@ code={`type ServerUser = | |
| </MethodLayout> | ||
| </CollapsibleTypesSection> | ||
|
|
||
| <CollapsibleTypesSection type="serverUser" property="countryCode" defaultOpen={false}> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Citation: New |
||
| <MethodLayout> | ||
| <MethodContent> | ||
| The ISO 3166-1 alpha-2 country code detected at sign-up (e.g., `US`, `DE`, `JP`). Returns `null` if the country could not be determined. | ||
| </MethodContent> | ||
| <MethodAside title="Type Definition"> | ||
|
|
||
| ```typescript | ||
| declare const countryCode: string | null; | ||
| ``` | ||
| </MethodAside> | ||
| </MethodLayout> | ||
| </CollapsibleTypesSection> | ||
|
|
||
| <CollapsibleTypesSection type="serverUser" property="riskScores" defaultOpen={false}> | ||
| <MethodLayout> | ||
| <MethodContent> | ||
| Risk scores calculated at sign-up for fraud protection. Contains: | ||
| - `signUp.bot`: Bot risk score from 0-100. Higher values indicate higher likelihood of automated sign-up attempts. | ||
| - `signUp.freeTrialAbuse`: Free trial abuse risk score from 0-100. Higher values indicate abuse patterns like disposable emails or repeated sign-ups. | ||
| </MethodContent> | ||
| <MethodAside title="Type Definition"> | ||
|
|
||
| ```typescript | ||
| declare const riskScores: { | ||
| signUp: { | ||
| bot: number; | ||
| freeTrialAbuse: number; | ||
| }; | ||
| }; | ||
| ``` | ||
| </MethodAside> | ||
| </MethodLayout> | ||
| </CollapsibleTypesSection> | ||
|
|
||
| <CollapsibleTypesSection type="serverUser" property="update" signature="data" defaultOpen={false}> | ||
| <MethodLayout> | ||
| <MethodContent> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Citation: Added
countryCodeandriskScoresconditions based on the newSignUpRuleContexttype inapps/backend/src/lib/cel-evaluator.tswhich now includescountryCode,riskScores.bot, andriskScores.free_trial_abusefields for fraud protection rule evaluation.View source