@stacksjs/defaults 0.75.573 → 0.75.575
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ai/skills/stacks-auth/SKILL.md +24 -0
- package/ai/skills/stacks-forms/SKILL.md +8 -0
- package/ai/skills/stacks-middleware/SKILL.md +2 -0
- package/ai/skills/stacks-native/CATALOG.md +5 -5
- package/app/Actions/Auth/RegisterAction.ts +26 -5
- package/app/Actions/SendWelcomeEmail.ts +5 -1
- package/app/Middleware/Honeypot.ts +64 -0
- package/app/Middleware.ts +1 -0
- package/functions/honeypot.ts +42 -0
- package/ide/vscode/package.json +1 -1
- package/package.json +3 -3
- package/resources/components/Dashboard/Auth/Register.stx +8 -0
- package/routes/auth.ts +5 -1
- package/types/dashboard.ts +4 -0
- package/vcs/github/workflows/deploy.yml +5 -0
- package/vcs/github/workflows/preview.yml +4 -0
|
@@ -480,6 +480,30 @@ overrides.
|
|
|
480
480
|
|
|
481
481
|
- `register(credentials: NewUser): Promise<{ token: AuthToken }>`
|
|
482
482
|
|
|
483
|
+
### Registration hardening
|
|
484
|
+
|
|
485
|
+
`register()` refuses a display name that is not a name: no link or web address
|
|
486
|
+
(`bit.ly/x`, `example.com`, `www.`, a scheme, `/`, `@`), no markup, no control
|
|
487
|
+
characters, only letters, digits, spaces and `. , ' - ( )`, at most
|
|
488
|
+
`DISPLAY_NAME_MAX_LENGTH` (80) characters. It answers 422 with a sentence for
|
|
489
|
+
the person, and stores the name whitespace-tidied. The rule lives in
|
|
490
|
+
`@stacksjs/auth/display-name` (`displayNameProblem`, `displayNameMessage`,
|
|
491
|
+
`normalizeDisplayName`).
|
|
492
|
+
|
|
493
|
+
Mail that greets someone reads the name through `greetingName(name)`: a first
|
|
494
|
+
name, or `undefined` when the stored value would not pass registration. Use it
|
|
495
|
+
in every mail of your own that goes to an address the recipient has not
|
|
496
|
+
confirmed. `RegisterAction` already passes `user:registered` listeners the
|
|
497
|
+
greeting name rather than the stored one.
|
|
498
|
+
|
|
499
|
+
`POST /register` is limited three ways: the route's 3 a minute per client, and
|
|
500
|
+
inside the action 20 an hour per client address and 5 an hour per email
|
|
501
|
+
(`config.auth.registration.rateLimit: { perIp, perEmail }`, `false` to turn
|
|
502
|
+
one off). It also carries the `honeypot` middleware (see `stacks-forms`).
|
|
503
|
+
|
|
504
|
+
`buddy user:audit` lists accounts whose stored name would be refused today,
|
|
505
|
+
with the reason and whether the address was ever verified. It only lists.
|
|
506
|
+
|
|
483
507
|
## User Helpers (user.ts)
|
|
484
508
|
|
|
485
509
|
- `authUser(): Promise<UserModel | undefined>`
|
|
@@ -36,6 +36,14 @@ from `@stacksjs/forms/spam`: `honeypot` (answer as if it worked, store nothing),
|
|
|
36
36
|
same check with `config.forms.spam`. No CAPTCHA, no third-party script; still
|
|
37
37
|
rate-limit per address or IP.
|
|
38
38
|
|
|
39
|
+
The same check is a route middleware: `.middleware('honeypot')` reads `_hp`
|
|
40
|
+
and `_renderedMs` from the body, answers 422 for a filled trap and 429 for a
|
|
41
|
+
form sent too fast, and passes a request that sends neither (so API clients
|
|
42
|
+
keep working). `createHoneypot()` from `functions/honeypot` supplies the two
|
|
43
|
+
fields on the form side: feed its `set()` from a hidden input and spread its
|
|
44
|
+
`fields()` into the submission. `POST /register` carries it by default, and
|
|
45
|
+
`components/Dashboard/Auth/Register.stx` is the worked example.
|
|
46
|
+
|
|
39
47
|
## Uploads, notifications, and paid forms
|
|
40
48
|
|
|
41
49
|
Use resolveUploadLimits, checkUpload, fileFieldNamed, formUploadPrefix and
|
|
@@ -96,6 +96,7 @@ export default defineMiddleware({
|
|
|
96
96
|
'abilities': 'Abilities',
|
|
97
97
|
'can': 'Can',
|
|
98
98
|
'throttle': 'Throttle',
|
|
99
|
+
'honeypot': 'Honeypot',
|
|
99
100
|
'signed': 'Signed',
|
|
100
101
|
'env': 'Env',
|
|
101
102
|
'env:local': 'EnvLocal',
|
|
@@ -210,6 +211,7 @@ Parameters are stored on `request._middlewareParams[middlewareName]` and parsed
|
|
|
210
211
|
| `team` | Team | 3 | Ensures user belongs to a team (parameterized: `team:teamId`) |
|
|
211
212
|
| `verified` | EnsureEmailIsVerified | 4 | Verifies email is confirmed |
|
|
212
213
|
| `throttle` | Throttle | - | Rate limiting (parameterized: `throttle:60,1` or `throttle:100,5m`) |
|
|
214
|
+
| `honeypot` | Honeypot | 2 | Refuses a submission whose hidden `_hp` field is filled or whose `_renderedMs` is under `config.forms.spam.minSubmitSeconds`; passes requests that send neither |
|
|
213
215
|
| `env:local` | EnvLocal | - | Only allows local environment |
|
|
214
216
|
| `env:development` / `env:dev` | EnvDevelopment | - | Only allows development |
|
|
215
217
|
| `env:staging` | EnvStaging | - | Only allows staging |
|
|
@@ -18,10 +18,10 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
|
|
|
18
18
|
| `@stacksjs/api` | [`stacks-api`](../stacks-api/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/api/src/index.ts) | 12 |
|
|
19
19
|
| `@stacksjs/arrays` | [`stacks-arrays`](../stacks-arrays/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/arrays/src/index.ts) | 12 |
|
|
20
20
|
| `@stacksjs/audio` | [`stacks-audio`](../stacks-audio/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/audio/src/index.ts) | 3 |
|
|
21
|
-
| `@stacksjs/auth` | [`stacks-auth`](../stacks-auth/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/index.ts) |
|
|
21
|
+
| `@stacksjs/auth` | [`stacks-auth`](../stacks-auth/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/index.ts) | 134 |
|
|
22
22
|
| `@stacksjs/browser` | [`stacks-browser`](../stacks-browser/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/browser/src/index.ts) | 10 |
|
|
23
23
|
| `@stacksjs/browser-extension` | [`stacks-browser-extension`](../stacks-browser-extension/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/browser-extension/src/index.ts) | 9 |
|
|
24
|
-
| `@stacksjs/buddy` | [`stacks-buddy`](../stacks-buddy/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/index.ts) |
|
|
24
|
+
| `@stacksjs/buddy` | [`stacks-buddy`](../stacks-buddy/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/index.ts) | 196 |
|
|
25
25
|
| `@stacksjs/build` | [`stacks-build`](../stacks-build/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/build/src/index.ts) | 7 |
|
|
26
26
|
| `@stacksjs/cache` | [`stacks-cache`](../stacks-cache/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cache/src/index.ts) | 24 |
|
|
27
27
|
| `@stacksjs/calendar-api` | [`stacks-calendar`](../stacks-calendar/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/calendar-api/src/index.ts) | 5 |
|
|
@@ -188,9 +188,9 @@ Guidance: [`stacks-auth`](../stacks-auth/SKILL.md). Source: [storage/framework/c
|
|
|
188
188
|
|
|
189
189
|
Declared runtime exports: `DEFAULT_ROLE_PACKS`, `adminEmails`, `createBqbRbacStore`, `databaseAdminAccounts`, `generateTOTP`, `generateTOTPSecret`, `nameFromEmail`, `provisionAdmins`, `requestImpersonation`, `seedDefaultRoles`, `totpKeyUri`, `verifyTOTP`.
|
|
190
190
|
|
|
191
|
-
Local source modules: [src/admins.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/admins.ts), [src/authentication.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/authentication.ts), [src/authenticator.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/authenticator.ts), [src/authorizable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/authorizable.ts), [src/browser-session-store.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/browser-session-store.ts), [src/browser-session.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/browser-session.ts), [src/client.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/client.ts), [src/cookie-auth.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/cookie-auth.ts), [src/credential-user.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/credential-user.ts), [src/email-verification.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/email-verification.ts), [src/gate.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/gate.ts), [src/impersonation-auth.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/impersonation-auth.ts), [src/impersonation-store.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/impersonation-store.ts), [src/impersonation.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/impersonation.ts), [src/magic-link.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/magic-link.ts), [src/middleware.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/middleware.ts), [src/oauth-authorization-codes.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-authorization-codes.ts), [src/oauth-authorization-endpoint.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-authorization-endpoint.ts), [src/oauth-authorization-requests.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-authorization-requests.ts), [src/oauth-authorization-response.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-authorization-response.ts), [src/oauth-authorization.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-authorization.ts), [src/oauth-browser-session.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-browser-session.ts), [src/oauth-client-registration.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-client-registration.ts), [src/oauth-consent.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-consent.ts), [src/oauth-delegated-access.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-delegated-access.ts), [src/oauth-dynamic-registration.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-dynamic-registration.ts), [src/oauth-grants.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-grants.ts), [src/oauth-introspection.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-introspection.ts), [src/oauth-metadata.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-metadata.ts), [src/oauth-pkce.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-pkce.ts), [src/oauth-protected-resource.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-protected-resource.ts), [src/oauth-provider.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-provider.ts), [src/oauth-pruning.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-pruning.ts), [src/oauth-revocation.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-revocation.ts), [src/oauth-server.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-server.ts), [src/oauth-token-endpoint.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-token-endpoint.ts), [src/oauth-token-exchange.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-token-exchange.ts), [src/oauth-token-request.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-token-request.ts), [src/oauth-token-response.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-token-response.ts), [src/oauth-userinfo.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-userinfo.ts), [src/page-gate.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/page-gate.ts), [src/passkey.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/passkey.ts), [src/passkeys.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/passkeys.ts), [src/password/reset-token.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/password/reset-token.ts), [src/password/reset.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/password/reset.ts), [src/permissions.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/permissions.ts), [src/policy.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/policy.ts), [src/rate-limiter.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/rate-limiter.ts), [src/rbac-seed.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/rbac-seed.ts), [src/rbac-store-bqb.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/rbac-store-bqb.ts), [src/rbac.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/rbac.ts), [src/referrals.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/referrals.ts), [src/register.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/register.ts), [src/request-token.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/request-token.ts), [src/session-auth.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/session-auth.ts), [src/session-handoff.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/session-handoff.ts), [src/socials.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/socials.ts), [src/team.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/team.ts), [src/tokens.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/tokens.ts), [src/two-factor-recovery-codes.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/two-factor-recovery-codes.ts), [src/two-factor.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/two-factor.ts), [src/user.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/user.ts).
|
|
191
|
+
Local source modules: [src/admins.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/admins.ts), [src/authentication.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/authentication.ts), [src/authenticator.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/authenticator.ts), [src/authorizable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/authorizable.ts), [src/browser-session-store.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/browser-session-store.ts), [src/browser-session.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/browser-session.ts), [src/client.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/client.ts), [src/cookie-auth.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/cookie-auth.ts), [src/credential-user.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/credential-user.ts), [src/display-name.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/display-name.ts), [src/email-verification.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/email-verification.ts), [src/gate.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/gate.ts), [src/impersonation-auth.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/impersonation-auth.ts), [src/impersonation-store.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/impersonation-store.ts), [src/impersonation.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/impersonation.ts), [src/magic-link.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/magic-link.ts), [src/middleware.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/middleware.ts), [src/oauth-authorization-codes.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-authorization-codes.ts), [src/oauth-authorization-endpoint.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-authorization-endpoint.ts), [src/oauth-authorization-requests.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-authorization-requests.ts), [src/oauth-authorization-response.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-authorization-response.ts), [src/oauth-authorization.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-authorization.ts), [src/oauth-browser-session.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-browser-session.ts), [src/oauth-client-registration.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-client-registration.ts), [src/oauth-consent.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-consent.ts), [src/oauth-delegated-access.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-delegated-access.ts), [src/oauth-dynamic-registration.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-dynamic-registration.ts), [src/oauth-grants.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-grants.ts), [src/oauth-introspection.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-introspection.ts), [src/oauth-metadata.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-metadata.ts), [src/oauth-pkce.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-pkce.ts), [src/oauth-protected-resource.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-protected-resource.ts), [src/oauth-provider.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-provider.ts), [src/oauth-pruning.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-pruning.ts), [src/oauth-revocation.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-revocation.ts), [src/oauth-server.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-server.ts), [src/oauth-token-endpoint.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-token-endpoint.ts), [src/oauth-token-exchange.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-token-exchange.ts), [src/oauth-token-request.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-token-request.ts), [src/oauth-token-response.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-token-response.ts), [src/oauth-userinfo.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/oauth-userinfo.ts), [src/page-gate.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/page-gate.ts), [src/passkey.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/passkey.ts), [src/passkeys.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/passkeys.ts), [src/password/reset-token.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/password/reset-token.ts), [src/password/reset.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/password/reset.ts), [src/permissions.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/permissions.ts), [src/policy.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/policy.ts), [src/rate-limiter.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/rate-limiter.ts), [src/rbac-seed.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/rbac-seed.ts), [src/rbac-store-bqb.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/rbac-store-bqb.ts), [src/rbac.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/rbac.ts), [src/referrals.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/referrals.ts), [src/register.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/register.ts), [src/request-token.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/request-token.ts), [src/session-auth.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/session-auth.ts), [src/session-handoff.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/session-handoff.ts), [src/socials.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/socials.ts), [src/team.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/team.ts), [src/tokens.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/tokens.ts), [src/two-factor-recovery-codes.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/two-factor-recovery-codes.ts), [src/two-factor.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/two-factor.ts), [src/user.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/user.ts).
|
|
192
192
|
|
|
193
|
-
Evidence directory: [
|
|
193
|
+
Evidence directory: [134 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
194
194
|
|
|
195
195
|
### @stacksjs/browser
|
|
196
196
|
|
|
@@ -220,7 +220,7 @@ Read the entrypoint and package export map for re-exported or type-only surfaces
|
|
|
220
220
|
|
|
221
221
|
Local source modules: [src/commands/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/commands/index.ts).
|
|
222
222
|
|
|
223
|
-
Evidence directory: [
|
|
223
|
+
Evidence directory: [196 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
224
224
|
|
|
225
225
|
### @stacksjs/build
|
|
226
226
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Action } from '@stacksjs/actions/runtime'
|
|
2
|
-
import { Auth, authCookieForBrowserSession, register, resolveBrowserSessionPolicy } from '@stacksjs/auth'
|
|
2
|
+
import { Auth, authCookieForBrowserSession, DISPLAY_NAME_MAX_LENGTH, DISPLAY_NAME_MIN_LENGTH, greetingName, normalizeAuthEmail, register, resolveBrowserSessionPolicy } from '@stacksjs/auth'
|
|
3
|
+
import { config } from '@stacksjs/config'
|
|
3
4
|
import { dispatch } from '@stacksjs/events'
|
|
4
|
-
import { response } from '@stacksjs/router'
|
|
5
|
+
import { rateLimit, response } from '@stacksjs/router'
|
|
5
6
|
import { schema } from '@stacksjs/validation/runtime'
|
|
6
7
|
import { PASSWORD_MAX_LENGTH, PASSWORD_MIN_LENGTH, PASSWORD_POLICY_MESSAGE } from '../../password-policy'
|
|
7
8
|
|
|
@@ -20,8 +21,10 @@ export default new Action({
|
|
|
20
21
|
message: PASSWORD_POLICY_MESSAGE,
|
|
21
22
|
},
|
|
22
23
|
name: {
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
// Length only. What a name may contain (no links, markup or control
|
|
25
|
+
// characters) is `register()`'s rule, so it holds for every caller.
|
|
26
|
+
rule: schema.string().min(DISPLAY_NAME_MIN_LENGTH).max(DISPLAY_NAME_MAX_LENGTH).required(),
|
|
27
|
+
message: `Name must be between ${DISPLAY_NAME_MIN_LENGTH} and ${DISPLAY_NAME_MAX_LENGTH} characters.`,
|
|
25
28
|
},
|
|
26
29
|
},
|
|
27
30
|
|
|
@@ -31,6 +34,19 @@ export default new Action({
|
|
|
31
34
|
const name = request.get('name')
|
|
32
35
|
const policy = resolveBrowserSessionPolicy(request.get('remember'))
|
|
33
36
|
|
|
37
|
+
// Hourly budgets, before the bcrypt hash and the insert. The route's
|
|
38
|
+
// 3-a-minute limit stops a burst and still lets one address create four
|
|
39
|
+
// thousand accounts a day; these are what make bulk sign-up slow. The
|
|
40
|
+
// email budget also caps how often one mailbox can be sent a welcome by
|
|
41
|
+
// somebody guessing at it.
|
|
42
|
+
const limits = config.auth?.registration?.rateLimit
|
|
43
|
+
const perIp = limits?.perIp ?? 20
|
|
44
|
+
const perEmail = limits?.perEmail ?? 5
|
|
45
|
+
if (perIp !== false)
|
|
46
|
+
await rateLimit('register-ip', perIp).per('hour')
|
|
47
|
+
if (perEmail !== false && typeof email === 'string')
|
|
48
|
+
await rateLimit('register-email', perEmail, { identity: `email:${normalizeAuthEmail(email)}` }).per('hour')
|
|
49
|
+
|
|
34
50
|
const referralCode = request.get('referralCode')
|
|
35
51
|
const result = await register(
|
|
36
52
|
{ email, password, name, referralCode: typeof referralCode === 'string' ? referralCode : undefined },
|
|
@@ -48,10 +64,15 @@ export default new Action({
|
|
|
48
64
|
// `to` is what SendWelcomeEmail addresses the mail to, so it has to be
|
|
49
65
|
// a string; the registering address is the honest fallback if the
|
|
50
66
|
// freshly-created user could not be read back.
|
|
67
|
+
//
|
|
68
|
+
// `name` is the first name a mail may print, or nothing: the address
|
|
69
|
+
// has not been confirmed, so whatever the listener sends goes to
|
|
70
|
+
// someone who may never have asked for it. Listeners that need the
|
|
71
|
+
// stored name read the user by `id`.
|
|
51
72
|
dispatch('user:registered', {
|
|
52
73
|
id: user?.id,
|
|
53
74
|
email: user?.email ?? email,
|
|
54
|
-
name: user?.name,
|
|
75
|
+
name: greetingName(user?.name),
|
|
55
76
|
to: user?.email ?? email,
|
|
56
77
|
})
|
|
57
78
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Action } from '@stacksjs/actions/runtime'
|
|
2
|
+
import { greetingName } from '@stacksjs/auth'
|
|
2
3
|
import { config } from '@stacksjs/config'
|
|
3
4
|
import { mail } from '@stacksjs/email'
|
|
4
5
|
|
|
@@ -15,13 +16,16 @@ export default new Action<string, undefined, '', WelcomeEmailParams>({
|
|
|
15
16
|
|
|
16
17
|
async handle({ to, name }: WelcomeEmailParams) {
|
|
17
18
|
const appName = config.app.name || 'our app'
|
|
19
|
+
// Untrusted: the address is unconfirmed and the name is whatever was
|
|
20
|
+
// typed at sign-up. A first name, or no name at all.
|
|
21
|
+
const greeting = greetingName(name) || 'there'
|
|
18
22
|
const url = config.app.url || 'https://localhost:5173'
|
|
19
23
|
|
|
20
24
|
await mail.sendOrFail({
|
|
21
25
|
to,
|
|
22
26
|
subject: `Welcome to ${appName}!`,
|
|
23
27
|
text: `
|
|
24
|
-
Hello ${
|
|
28
|
+
Hello ${greeting},
|
|
25
29
|
|
|
26
30
|
Welcome to ${appName}! We're excited to have you on board.
|
|
27
31
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { config } from '@stacksjs/config'
|
|
2
|
+
import { HttpError } from '@stacksjs/error-handling'
|
|
3
|
+
import { checkSubmissionSpam } from '@stacksjs/forms/spam'
|
|
4
|
+
import { Middleware } from '@stacksjs/router'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Honeypot Middleware
|
|
8
|
+
*
|
|
9
|
+
* Refuses a submission that a form-filling bot gave away, on any route that
|
|
10
|
+
* takes one. It reads the two fields the framework's forms already send
|
|
11
|
+
* (`defaults/routes/forms.ts`, `createHoneypot()`):
|
|
12
|
+
*
|
|
13
|
+
* - `_hp`: the value of an input people never see. Bots fill every input, so
|
|
14
|
+
* any value in it means a bot.
|
|
15
|
+
* - `_renderedMs`: how long the form was open before it was sent. Nobody
|
|
16
|
+
* reads a form and types a name, an address and a password in under
|
|
17
|
+
* `config.forms.spam.minSubmitSeconds` (3 by default).
|
|
18
|
+
*
|
|
19
|
+
* A request that carries neither field passes: an API client, a native app or
|
|
20
|
+
* a form written before this existed is not a bot for lacking them. So the
|
|
21
|
+
* middleware is safe to put on a route before its form sends the fields, and
|
|
22
|
+
* it is one signal among others, not the gate. A rate limit is still the
|
|
23
|
+
* route's job.
|
|
24
|
+
*
|
|
25
|
+
* `config.forms.spam.honeypot: false` and `minSubmitSeconds: 0` turn the two
|
|
26
|
+
* checks off, here as on CMS forms.
|
|
27
|
+
*
|
|
28
|
+
* Usage:
|
|
29
|
+
* route.post('/register', 'Actions/Auth/RegisterAction').middleware('honeypot')
|
|
30
|
+
* route.post('/contact', 'Actions/ContactAction').middleware('honeypot')
|
|
31
|
+
*
|
|
32
|
+
* In the form, `createHoneypot()` from `functions/honeypot` supplies the two
|
|
33
|
+
* fields; `components/Dashboard/Auth/Register.stx` is the worked example.
|
|
34
|
+
*/
|
|
35
|
+
export default new Middleware({
|
|
36
|
+
name: 'honeypot',
|
|
37
|
+
priority: 2,
|
|
38
|
+
|
|
39
|
+
handle(request) {
|
|
40
|
+
const body = honeypotBody(request)
|
|
41
|
+
const signal = checkSubmissionSpam(
|
|
42
|
+
{ honeypot: body._hp, renderedAtMs: body._renderedMs },
|
|
43
|
+
(config as { forms?: { spam?: { honeypot?: boolean, minSubmitSeconds?: number } } }).forms?.spam ?? {},
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
// The same sentence either way, and the one a refused registration
|
|
47
|
+
// already answers with: a bot learns nothing about which field gave it
|
|
48
|
+
// away, and a person who really was that fast is told what to do.
|
|
49
|
+
if (signal === 'honeypot')
|
|
50
|
+
throw new HttpError(422, 'This could not be completed. Please check your details and try again.')
|
|
51
|
+
if (signal === 'too_fast')
|
|
52
|
+
throw new HttpError(429, 'That was submitted too quickly. Please wait a moment and try again.')
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
function honeypotBody(request: unknown): { _hp?: unknown, _renderedMs?: unknown } {
|
|
57
|
+
const req = request as { all?: () => unknown, get?: (key: string) => unknown, body?: unknown }
|
|
58
|
+
const all = typeof req.all === 'function' ? req.all() : undefined
|
|
59
|
+
if (all && typeof all === 'object')
|
|
60
|
+
return all as Record<string, unknown>
|
|
61
|
+
if (typeof req.get === 'function')
|
|
62
|
+
return { _hp: req.get('_hp'), _renderedMs: req.get('_renderedMs') }
|
|
63
|
+
return req.body && typeof req.body === 'object' && !(req.body instanceof ReadableStream) ? req.body as Record<string, unknown> : {}
|
|
64
|
+
}
|
package/app/Middleware.ts
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client half of the `honeypot` middleware.
|
|
3
|
+
*
|
|
4
|
+
* A form creates one when it renders, feeds it whatever lands in its hidden
|
|
5
|
+
* input, and spreads `fields()` into what it submits:
|
|
6
|
+
*
|
|
7
|
+
* const honeypot = createHoneypot()
|
|
8
|
+
* <input type="text" name="website" tabindex="-1" autocomplete="off" aria-hidden="true" class="hidden" @input="honeypot.set($event.target.value)">
|
|
9
|
+
* await register({ ...values, ...honeypot.fields() })
|
|
10
|
+
*
|
|
11
|
+
* `_hp` is what a bot typed into the input nobody can see, and `_renderedMs`
|
|
12
|
+
* is how long the form was open. The route's `honeypot` middleware reads both
|
|
13
|
+
* (`app/Middleware/Honeypot.ts`); the names are the ones CMS forms already
|
|
14
|
+
* send. Nothing here touches the page, a signal or the network, so it works
|
|
15
|
+
* in any script and a test can drive the clock.
|
|
16
|
+
*/
|
|
17
|
+
export interface HoneypotFields {
|
|
18
|
+
/** The hidden input's value. Empty for a person. */
|
|
19
|
+
_hp: string
|
|
20
|
+
/** Milliseconds between creating the honeypot and reading these fields. */
|
|
21
|
+
_renderedMs: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface HoneypotTrap {
|
|
25
|
+
/** Record the hidden input's value. */
|
|
26
|
+
set: (value: unknown) => void
|
|
27
|
+
/** The two fields to send with the submission. */
|
|
28
|
+
fields: () => HoneypotFields
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function createHoneypot(now: () => number = Date.now): HoneypotTrap {
|
|
32
|
+
const openedAt = now()
|
|
33
|
+
let value = ''
|
|
34
|
+
return {
|
|
35
|
+
set(next) {
|
|
36
|
+
value = typeof next === 'string' ? next : ''
|
|
37
|
+
},
|
|
38
|
+
fields() {
|
|
39
|
+
return { _hp: value, _renderedMs: Math.max(0, now() - openedAt) }
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
}
|
package/ide/vscode/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"publisher": "Stacks",
|
|
3
3
|
"name": "vscode-stacks",
|
|
4
4
|
"displayName": "Stacks",
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.575",
|
|
6
6
|
"description": "Stacks, built into VS Code: stx templates, pickier linting and formatting, encrypted env files, the dev server preview and every buddy command. No other extensions required.",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"funding": "https://github.com/sponsors/chrisbbreuer",
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/defaults",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.575",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/stacksjs/stacks.git",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@iconify-json/f7": "^1.2.2",
|
|
47
47
|
"@iconify-json/hugeicons": "^1.2.35",
|
|
48
|
-
"@stacksjs/mobile": "0.75.
|
|
48
|
+
"@stacksjs/mobile": "0.75.575",
|
|
49
49
|
"@stacksjs/sanitizer": "^0.2.864",
|
|
50
50
|
"@stacksjs/stx": "^0.2.864",
|
|
51
|
-
"@stacksjs/strings": "0.75.
|
|
51
|
+
"@stacksjs/strings": "0.75.575",
|
|
52
52
|
"@xterm/addon-fit": "^0.11.0",
|
|
53
53
|
"@xterm/xterm": "^6.0.0",
|
|
54
54
|
"ts-qr-codes": "^0.1.8"
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
@import('../UI/Input', '../UI/Button')
|
|
2
2
|
|
|
3
3
|
<script client>
|
|
4
|
+
import { createHoneypot } from '../../../../functions/honeypot'
|
|
5
|
+
|
|
4
6
|
const emit = defineEmits(['submit'])
|
|
7
|
+
// A hidden input and a clock, read by the `honeypot` middleware on /register.
|
|
8
|
+
const honeypot = createHoneypot()
|
|
5
9
|
const title = useReactiveProp<string>('title', 'Create an account')
|
|
6
10
|
const subtitle = useReactiveProp<string>('subtitle', 'Get started with your free account')
|
|
7
11
|
const icon = useReactiveProp<string>('icon', 'i-hugeicons-cube')
|
|
@@ -97,6 +101,7 @@ function handleSubmit(): void {
|
|
|
97
101
|
email: email(),
|
|
98
102
|
password: password(),
|
|
99
103
|
password_confirmation: passwordConfirmation(),
|
|
104
|
+
...honeypot.fields(),
|
|
100
105
|
})
|
|
101
106
|
}
|
|
102
107
|
</script>
|
|
@@ -181,6 +186,9 @@ function handleSubmit(): void {
|
|
|
181
186
|
/>
|
|
182
187
|
</div>
|
|
183
188
|
|
|
189
|
+
<!-- Honeypot: hidden from people, filled by bots. See app/Middleware/Honeypot.ts. -->
|
|
190
|
+
<input type="text" name="website" tabindex="-1" autocomplete="off" aria-hidden="true" class="hidden" @input="honeypot.set($event.target.value)">
|
|
191
|
+
|
|
184
192
|
<!-- Terms Checkbox -->
|
|
185
193
|
<div class="mb-6">
|
|
186
194
|
<label class="flex gap-2 items-start cursor-pointer">
|
package/routes/auth.ts
CHANGED
|
@@ -45,7 +45,11 @@ const oauthMetadataPath = oauthProvider
|
|
|
45
45
|
// tokens until the row TTL. Userland that overrides any of these in
|
|
46
46
|
// `routes/api.ts` (user routes win) gets to pick its own limits.
|
|
47
47
|
route.post('/login', 'Actions/Auth/LoginAction').rateLimit(5, 'minute')
|
|
48
|
-
route
|
|
48
|
+
// Registration is the one route here an anonymous visitor writes through, so
|
|
49
|
+
// it carries the honeypot (a no-op for clients that send neither field) and,
|
|
50
|
+
// inside the action, hourly limits per address and per email on top of this
|
|
51
|
+
// burst limit.
|
|
52
|
+
route.post('/register', 'Actions/Auth/RegisterAction').middleware('honeypot').rateLimit(3, 'minute')
|
|
49
53
|
// OAuth authorization-server token exchange. The action remains a 404 unless
|
|
50
54
|
// config.auth.oauthProvider.enabled is explicitly true. PKCE or HTTP Basic is
|
|
51
55
|
// the endpoint's credential boundary, so the action opts out of browser CSRF.
|
package/types/dashboard.ts
CHANGED
|
@@ -70,6 +70,10 @@ export interface AuthUser {
|
|
|
70
70
|
export interface RegisterCredentials extends AuthUser {
|
|
71
71
|
name: string
|
|
72
72
|
password_confirmation: string
|
|
73
|
+
/** The hidden honeypot input's value (`createHoneypot().fields()`). */
|
|
74
|
+
_hp?: string
|
|
75
|
+
/** Milliseconds the form was open before it was sent. */
|
|
76
|
+
_renderedMs?: number
|
|
73
77
|
}
|
|
74
78
|
|
|
75
79
|
export interface ErrorResponse {
|
|
@@ -115,6 +115,11 @@ jobs:
|
|
|
115
115
|
- name: Setup Pantry
|
|
116
116
|
if: steps.check.outputs.configured == 'true'
|
|
117
117
|
uses: pantry-pm/pantry/packages/action@cdb82193cb344c2b881a88ea79f88243f5522e0f # v0.11.75
|
|
118
|
+
# The CLI only, as in ci.yml. Installing the app's system packages here
|
|
119
|
+
# pulls in the local mail catcher too, which has no Linux download, and
|
|
120
|
+
# a deploy needs none of them: Bun comes from the step above.
|
|
121
|
+
with:
|
|
122
|
+
install: 'false'
|
|
118
123
|
|
|
119
124
|
- name: Install dependencies
|
|
120
125
|
if: steps.check.outputs.configured == 'true'
|
|
@@ -68,6 +68,10 @@ jobs:
|
|
|
68
68
|
- name: Setup Pantry
|
|
69
69
|
if: steps.check.outputs.configured == 'true'
|
|
70
70
|
uses: pantry-pm/pantry/packages/action@cdb82193cb344c2b881a88ea79f88243f5522e0f # v0.11.75
|
|
71
|
+
# The CLI only, as in ci.yml: a preview deploy needs none of the app's
|
|
72
|
+
# system packages, and one of them has no Linux download.
|
|
73
|
+
with:
|
|
74
|
+
install: 'false'
|
|
71
75
|
|
|
72
76
|
- name: Install dependencies
|
|
73
77
|
if: steps.check.outputs.configured == 'true'
|