@stacksjs/defaults 0.75.572 → 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-browse/scripts/chrome.ts +107 -4
- 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/ai/skills/stacks-testing/SKILL.md +11 -1
- 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>`
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Shared Chrome executable preparation for the standalone skill and testing package.
|
|
2
|
-
import {
|
|
2
|
+
import { createHash } from 'node:crypto'
|
|
3
|
+
import { existsSync, lstatSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, readlinkSync, renameSync, rmSync, writeFileSync } from 'node:fs'
|
|
3
4
|
import { tmpdir } from 'node:os'
|
|
4
5
|
import { basename, join } from 'node:path'
|
|
5
6
|
import process from 'node:process'
|
|
@@ -72,17 +73,111 @@ function frameworkVersions(directory: string): { path: string, identifier: strin
|
|
|
72
73
|
return result
|
|
73
74
|
}
|
|
74
75
|
|
|
76
|
+
/**
|
|
77
|
+
* The framework versions a private copy has no use for: every one that
|
|
78
|
+
* `Versions/Current` does not point at.
|
|
79
|
+
*
|
|
80
|
+
* Chrome's updater keeps the version it replaced beside the new one, for the
|
|
81
|
+
* browser that is still running it, and keeps it until that browser is
|
|
82
|
+
* relaunched. Each is some 700 MB of code. A private copy is always started
|
|
83
|
+
* fresh and only ever loads `Current`, yet every one of them was signed when
|
|
84
|
+
* the copy was made and verified again before each reuse: with two updates
|
|
85
|
+
* pending that was 2.1 GB and 20 to 28 seconds before a browser could start,
|
|
86
|
+
* which is longer than a test waits. A framework with no `Current` link is
|
|
87
|
+
* left whole, since nothing says which of its versions is the one in use.
|
|
88
|
+
*/
|
|
89
|
+
function supersededFrameworkVersions(directory: string): string[] {
|
|
90
|
+
const result: string[] = []
|
|
91
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
92
|
+
if (!entry.isDirectory()) continue
|
|
93
|
+
const child = join(directory, entry.name)
|
|
94
|
+
result.push(...supersededFrameworkVersions(child))
|
|
95
|
+
const versions = join(child, 'Versions')
|
|
96
|
+
if (!entry.name.endsWith('.framework') || !existsSync(versions)) continue
|
|
97
|
+
let current: string
|
|
98
|
+
try { current = basename(readlinkSync(join(versions, 'Current'))) }
|
|
99
|
+
catch { continue }
|
|
100
|
+
if (!existsSync(join(versions, current))) continue
|
|
101
|
+
for (const version of readdirSync(versions, { withFileTypes: true })) {
|
|
102
|
+
if (version.isDirectory() && version.name !== current)
|
|
103
|
+
result.push(join(versions, version.name))
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return result
|
|
107
|
+
}
|
|
108
|
+
|
|
75
109
|
function validSignature(app: string): boolean {
|
|
76
110
|
return Bun.spawnSync(['codesign', '--verify', '--deep', '--strict', app], { stdout: 'pipe', stderr: 'pipe' }).exitCode === 0
|
|
77
111
|
}
|
|
78
112
|
|
|
113
|
+
/**
|
|
114
|
+
* What a copy looked like when its signature was last verified: every file's
|
|
115
|
+
* path, size and modification time, and every link's target, as one digest.
|
|
116
|
+
*
|
|
117
|
+
* Strict verification reads the whole bundle, about 15 seconds for one Chrome
|
|
118
|
+
* version, and every test process that started a browser paid it again for a
|
|
119
|
+
* copy nothing had touched. A copy whose files are all where they were, the
|
|
120
|
+
* size they were and as old as they were is the copy that was verified, so
|
|
121
|
+
* it is reused without being read again. Anything else, a file rewritten,
|
|
122
|
+
* removed by the temp cleaner or added, changes the digest and the copy is
|
|
123
|
+
* verified in full before it is trusted.
|
|
124
|
+
*/
|
|
125
|
+
function bundleFingerprint(app: string): string {
|
|
126
|
+
const lines: string[] = []
|
|
127
|
+
const walk = (directory: string, prefix: string): void => {
|
|
128
|
+
for (const entry of readdirSync(directory, { withFileTypes: true }).sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))) {
|
|
129
|
+
const path = join(directory, entry.name), relative = `${prefix}${entry.name}`
|
|
130
|
+
if (entry.isSymbolicLink()) { lines.push(`${relative}\tlink\t${readlinkSync(path)}`); continue }
|
|
131
|
+
if (entry.isDirectory()) { walk(path, `${relative}/`); continue }
|
|
132
|
+
const stat = lstatSync(path, { bigint: true })
|
|
133
|
+
lines.push(`${relative}\tfile\t${stat.size}\t${stat.mtimeNs}`)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
walk(app, '')
|
|
137
|
+
return createHash('sha256').update(lines.join('\n')).digest('hex')
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Kept beside the copy, never inside it: a file added to a bundle breaks its seal. */
|
|
141
|
+
const stampOf = (app: string): string => `${app}.verified`
|
|
142
|
+
const STAMP_FORMAT = 'stacks-chrome-verified-1'
|
|
143
|
+
|
|
144
|
+
function verifiedUnchanged(app: string): boolean {
|
|
145
|
+
try { return readFileSync(stampOf(app), 'utf8') === `${STAMP_FORMAT}\n${bundleFingerprint(app)}\n` }
|
|
146
|
+
catch { return false }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Record that `app`, as it is now, passed strict verification. Written whole or not at all. */
|
|
150
|
+
function recordVerified(app: string): void {
|
|
151
|
+
const pending = `${stampOf(app)}.${process.pid}`
|
|
152
|
+
try {
|
|
153
|
+
writeFileSync(pending, `${STAMP_FORMAT}\n${bundleFingerprint(app)}\n`)
|
|
154
|
+
renameSync(pending, stampOf(app))
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
// The copy is still valid without its stamp; the next run verifies it again.
|
|
158
|
+
rmSync(pending, { force: true })
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** A cached copy that may be launched: unchanged since it was verified, or verified now. */
|
|
163
|
+
function trustedCopy(app: string): boolean {
|
|
164
|
+
if (verifiedUnchanged(app)) return true
|
|
165
|
+
if (!validSignature(app)) return false
|
|
166
|
+
recordVerified(app)
|
|
167
|
+
return true
|
|
168
|
+
}
|
|
169
|
+
|
|
79
170
|
/**
|
|
80
171
|
* A private clone of a macOS Chrome that GoogleUpdater leaves alone (see the
|
|
81
172
|
* module docs): `cp -cR`, the `KS*` keys deleted from `Info.plist`, its own
|
|
82
173
|
* `CFBundleIdentifier`, and a complete ad-hoc signature. Every framework
|
|
83
174
|
* version shares an explicit designated requirement, as required for a
|
|
84
|
-
* multi-version bundle (Apple TN2206).
|
|
85
|
-
*
|
|
175
|
+
* multi-version bundle (Apple TN2206). Framework versions the updater kept
|
|
176
|
+
* for a browser that is still running are left out of the copy, which only
|
|
177
|
+
* ever runs the current one. Kept in `directory` (default a per-version temp
|
|
178
|
+
* folder) and reused only when it is the copy that passed strict signature
|
|
179
|
+
* validation: unchanged since, by every file's size and age, or validated
|
|
180
|
+
* again now.
|
|
86
181
|
*/
|
|
87
182
|
export function prepareMacChrome(options: { source?: string, directory?: string } = {}): PreparedChrome {
|
|
88
183
|
if (process.platform !== 'darwin') throw new Error('prepareMacChrome is for macOS; elsewhere launch Chrome as installed')
|
|
@@ -99,8 +194,11 @@ export function prepareMacChrome(options: { source?: string, directory?: string
|
|
|
99
194
|
.map(entry => join(directory, entry.name)).sort() : []
|
|
100
195
|
for (const candidate of candidates) {
|
|
101
196
|
const executable = join(candidate, 'Contents/MacOS', executableName), info = join(candidate, 'Contents/Info.plist')
|
|
197
|
+
// A copy made before superseded versions were left out still verifies,
|
|
198
|
+
// slowly. It is passed over, not removed: a browser may be running it.
|
|
102
199
|
if (existsSync(executable) && plist(info, 'Print :CFBundleIdentifier').out === PRIVATE_BUNDLE_ID
|
|
103
|
-
&& plist(info, 'Print :CFBundleShortVersionString').out === version
|
|
200
|
+
&& plist(info, 'Print :CFBundleShortVersionString').out === version
|
|
201
|
+
&& supersededFrameworkVersions(candidate).length === 0 && trustedCopy(candidate))
|
|
104
202
|
return { executable, app: candidate, reused: true }
|
|
105
203
|
}
|
|
106
204
|
|
|
@@ -122,6 +220,9 @@ export function prepareMacChrome(options: { source?: string, directory?: string
|
|
|
122
220
|
const stagedInfo = join(staged, 'Contents/Info.plist')
|
|
123
221
|
for (const key of UPDATER_KEYS) plist(stagedInfo, `Delete :${key}`)
|
|
124
222
|
run(['/usr/libexec/PlistBuddy', '-c', `Set :CFBundleIdentifier ${PRIVATE_BUNDLE_ID}`, stagedInfo], 'Renaming the Chrome bundle')
|
|
223
|
+
// Before signing, so what is left out is neither signed nor sealed into
|
|
224
|
+
// the copy. Only the clone is touched: the installed app keeps them all.
|
|
225
|
+
for (const superseded of supersededFrameworkVersions(staged)) rmSync(superseded, { recursive: true, force: true })
|
|
125
226
|
const versions = frameworkVersions(staged)
|
|
126
227
|
// --deep only signs the current framework version. Prepare the code in
|
|
127
228
|
// every version first, then seal nested frameworks and their parents.
|
|
@@ -138,6 +239,8 @@ export function prepareMacChrome(options: { source?: string, directory?: string
|
|
|
138
239
|
destination = join(directory, `Chrome-${basename(staging)}.app`)
|
|
139
240
|
renameSync(staged, destination)
|
|
140
241
|
}
|
|
242
|
+
// Verified a moment ago, as the staged copy. Moving it changed no file.
|
|
243
|
+
recordVerified(destination)
|
|
141
244
|
return { executable: join(destination, 'Contents/MacOS', executableName), app: destination, reused: false }
|
|
142
245
|
}
|
|
143
246
|
finally {
|
|
@@ -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
|
|
|
@@ -320,9 +320,19 @@ expect(pageAuditClean(report)).toBe(true) // no duplicate /api/ requests, failed
|
|
|
320
320
|
Chrome's bundle id while an update is pending; to a test that looks like a hung page. When
|
|
321
321
|
`CHROME_PATH` is not set, `launch()` runs `prepareMacChrome()`: a `cp -cR` clone in the temp
|
|
322
322
|
directory with the `KS*` updater keys deleted from `Info.plist`, its own `CFBundleIdentifier`,
|
|
323
|
-
and
|
|
323
|
+
and a complete ad-hoc signature, reused per Chrome version. `--use-mock-keychain` is what
|
|
324
324
|
keeps that clone from hanging on an invisible "Chrome Safe Storage" Keychain prompt at its first
|
|
325
325
|
http page. Measured: the installed Chrome closed at 32 s, the clone kept navigating past 60 s.
|
|
326
|
+
- **The clone is made once and then reused in about a tenth of a second** (stacksjs/stacks#3302).
|
|
327
|
+
It leaves out the framework versions the updater keeps for a browser that is still running
|
|
328
|
+
(each about 730 MB; only `Versions/Current` is ever loaded), and a copy that passed
|
|
329
|
+
`codesign --verify --deep --strict` is remembered by a digest of every file's path, size and
|
|
330
|
+
modification time in `Chrome.app.verified` beside it. Unchanged, it is not read again; changed
|
|
331
|
+
in any of those, it is verified in full, and an invalid one gets a replacement generation
|
|
332
|
+
while the old bundle is kept. Before this, strict verification ran before every reuse: 19 to
|
|
333
|
+
28 s with two updates pending, which a test that gives its page 30 s never survived. The first
|
|
334
|
+
browser test after a Chrome update still pays for the copy, about 15 to 30 s once; if that
|
|
335
|
+
test's own deadline is shorter, it fails once and the next browser test finishes the copy.
|
|
326
336
|
- The package's own real-Chrome tests (`core/testing/tests/browser.test.ts`) run wherever a Chrome
|
|
327
337
|
is found, except in CI unless `STACKS_BROWSER_TESTS=1`; `STACKS_BROWSER_TESTS=0` skips them locally.
|
|
328
338
|
|
|
@@ -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'
|