@stacksjs/defaults 0.75.691 → 0.75.693
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.
|
@@ -49,7 +49,7 @@ form field never joins an internal list. Outcomes: `subscribed`, `pending`
|
|
|
49
49
|
already on the list gets the same answer a new one would (`pending` on a double
|
|
50
50
|
opt-in list, `subscribed` elsewhere) and no email, so the form cannot be used to
|
|
51
51
|
find out who signed up; `already` is no longer sent. A hidden `website` field is
|
|
52
|
-
a honeypot: filled in, the request is answered as success and stores nothing. Scripts get JSON; a browser form post gets a 303 back to `return`
|
|
52
|
+
a honeypot: filled in, the request is answered as success and stores nothing. `email.newsletter.signup: false` leaves the signup and confirm routes unmounted (unsubscribe always stays), for a deployment that takes no signups. Scripts get JSON; a browser form post gets a 303 back to `return`
|
|
53
53
|
or the Referer. The welcome email carries the membership's own token, so its
|
|
54
54
|
unsubscribe link and RFC 8058 headers leave that list only.
|
|
55
55
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { describe, expect, it, mock } from 'bun:test'
|
|
2
|
+
|
|
3
|
+
class PasskeyError extends Error {}
|
|
4
|
+
let keyCount = 1
|
|
5
|
+
const HASH = 'hash:right'
|
|
6
|
+
|
|
7
|
+
mock.module('./passkey-config', () => ({
|
|
8
|
+
passkeyParty: () => ({ origin: 'https://app.example', name: 'App' }),
|
|
9
|
+
passkeyJSON: (value: unknown) => Response.json(value),
|
|
10
|
+
passkeyFailure: (error: unknown) => {
|
|
11
|
+
if (!(error instanceof PasskeyError)) throw error
|
|
12
|
+
return Response.json({ error: error.message }, { status: 400 })
|
|
13
|
+
},
|
|
14
|
+
}))
|
|
15
|
+
mock.module('@stacksjs/security', () => ({ verifyHash: async (value: string, hash: string) => `hash:${value}` === hash }))
|
|
16
|
+
mock.module('@stacksjs/auth', () => ({
|
|
17
|
+
PasskeyError,
|
|
18
|
+
// The real one's rule: the last passkey goes only with another way in.
|
|
19
|
+
removePasskey: async (_user: number, _id: string, alternative: (row: Record<string, unknown>) => Promise<boolean>) => {
|
|
20
|
+
const other = await alternative({ password: HASH })
|
|
21
|
+
if (keyCount === 1 && !other) throw new PasskeyError('Add a password or another passkey before removing your last passkey.')
|
|
22
|
+
return true
|
|
23
|
+
},
|
|
24
|
+
}))
|
|
25
|
+
|
|
26
|
+
const action = (await import('./PasskeyDestroyAction')).default as unknown as { handle: (request: unknown) => Promise<Response> }
|
|
27
|
+
const request = (password?: string) => ({
|
|
28
|
+
user: async () => ({ id: 1 }),
|
|
29
|
+
getParam: () => 'credential-1',
|
|
30
|
+
get: (key: string) => key === 'password' ? password : undefined,
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
describe('removing a passkey', () => {
|
|
34
|
+
it('removes the last one given the password', async () => {
|
|
35
|
+
keyCount = 1
|
|
36
|
+
expect((await action.handle(request('right'))).status).toBe(200)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('says the password is wrong, not that there is none', async () => {
|
|
40
|
+
keyCount = 1
|
|
41
|
+
const response = await action.handle(request('wrong'))
|
|
42
|
+
expect(response.status).toBe(422)
|
|
43
|
+
expect(await response.json()).toEqual({ error: 'The password is not right.' })
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('removes one of several with the session alone', async () => {
|
|
47
|
+
keyCount = 2
|
|
48
|
+
expect((await action.handle(request())).status).toBe(200)
|
|
49
|
+
})
|
|
50
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Action } from '@stacksjs/actions/runtime'
|
|
2
2
|
import { verifyHash } from '@stacksjs/security'
|
|
3
|
-
import { removePasskey } from '@stacksjs/auth'
|
|
3
|
+
import { PasskeyError, removePasskey } from '@stacksjs/auth'
|
|
4
4
|
import { passkeyParty, passkeyFailure, passkeyJSON } from './passkey-config'
|
|
5
5
|
|
|
6
6
|
export default new Action({
|
|
@@ -14,10 +14,21 @@ export default new Action({
|
|
|
14
14
|
if (!user) return new Response(null, { status: 401 })
|
|
15
15
|
const id = request.getParam('id')
|
|
16
16
|
if (typeof id !== 'string' || !/^[A-Za-z0-9_-]{1,1366}$/.test(id)) return new Response(null, { status: 422 })
|
|
17
|
+
// The password proves another way in. A wrong one is its own answer:
|
|
18
|
+
// reported as "add a password first", it sent an owner who has one
|
|
19
|
+
// looking for a setting rather than retyping it.
|
|
20
|
+
let wrongPassword = false
|
|
17
21
|
return await removePasskey(Number(user.id), id, async row => {
|
|
22
|
+
if (typeof row.password !== 'string' || !row.password) return false
|
|
18
23
|
const password = request.get('password')
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
const proved = typeof password === 'string' && !!password && await verifyHash(password, row.password)
|
|
25
|
+
wrongPassword = !proved
|
|
26
|
+
return proved
|
|
27
|
+
}).catch((error) => {
|
|
28
|
+
if (wrongPassword && error instanceof PasskeyError)
|
|
29
|
+
return Response.json({ error: 'The password is not right.' }, { status: 422, headers: { 'Cache-Control': 'no-store' } })
|
|
30
|
+
throw error
|
|
31
|
+
}).then(removed => removed instanceof Response ? removed : removed ? passkeyJSON({ ok: true }) : new Response(null, { status: 404 }))
|
|
21
32
|
}
|
|
22
33
|
catch (error) { return passkeyFailure(error) }
|
|
23
34
|
},
|
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.693",
|
|
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.693",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/stacksjs/stacks.git",
|
|
@@ -46,14 +46,14 @@
|
|
|
46
46
|
"@iconify-json/f7": "^1.2.2",
|
|
47
47
|
"@iconify-json/hugeicons": "^1.2.35",
|
|
48
48
|
"@stacksjs/desktop": "^0.2.938",
|
|
49
|
-
"@stacksjs/mobile": "0.75.
|
|
49
|
+
"@stacksjs/mobile": "0.75.693",
|
|
50
50
|
"@stacksjs/sanitizer": "^0.2.938",
|
|
51
51
|
"@stacksjs/stx": "^0.2.938",
|
|
52
|
-
"@stacksjs/strings": "0.75.
|
|
52
|
+
"@stacksjs/strings": "0.75.693",
|
|
53
53
|
"@xterm/addon-fit": "^0.11.0",
|
|
54
54
|
"@xterm/xterm": "^6.0.0",
|
|
55
55
|
"ts-qr-codes": "^0.1.8",
|
|
56
|
-
"@stacksjs/support": "0.75.
|
|
57
|
-
"@stacksjs/browser": "0.75.
|
|
56
|
+
"@stacksjs/support": "0.75.693",
|
|
57
|
+
"@stacksjs/browser": "0.75.693"
|
|
58
58
|
}
|
|
59
59
|
}
|
package/routes/email.ts
CHANGED
|
@@ -46,6 +46,7 @@ interface EmailConfigShape {
|
|
|
46
46
|
ses?: { autoConfirmSubscriptions?: boolean }
|
|
47
47
|
sendgrid?: { publicKeyPem?: string }
|
|
48
48
|
}
|
|
49
|
+
newsletter?: { signup?: boolean }
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
function emailConfig(): EmailConfigShape {
|
|
@@ -155,9 +156,16 @@ route.post('/webhooks/email/sendgrid', async (req) => {
|
|
|
155
156
|
// without a CSRF token round-trip, and the abuse case (bots inflating
|
|
156
157
|
// the subscriber list) is better handled with the rate limiter — at
|
|
157
158
|
// the action layer — than with a token check the form can't satisfy.
|
|
158
|
-
|
|
159
|
-
//
|
|
160
|
-
|
|
159
|
+
//
|
|
160
|
+
// `email.newsletter.signup: false` leaves out the signup and its confirmation
|
|
161
|
+
// link, for a deployment that takes no signups (an app's self-hosted install,
|
|
162
|
+
// say, when only its public site runs the list). The unsubscribe routes stay
|
|
163
|
+
// whatever it says: anyone ever emailed must still be able to leave.
|
|
164
|
+
if (emailConfig().newsletter?.signup !== false) {
|
|
165
|
+
route.post('/api/email/subscribe', 'Actions/SubscriberEmailAction').name('email.subscribe').skipCsrf()
|
|
166
|
+
// The button in the double opt-in email (lists with `double_opt_in` on).
|
|
167
|
+
route.get('/api/email/confirm', 'Actions/ConfirmSubscriptionAction').name('email.confirm')
|
|
168
|
+
}
|
|
161
169
|
route.get('/api/email/unsubscribe', 'Actions/UnsubscribeAction').name('email.unsubscribe')
|
|
162
170
|
// RFC 8058 one-click endpoint. Mailbox providers (Gmail, Yahoo, Outlook)
|
|
163
171
|
// POST here with body `List-Unsubscribe=One-Click` when the user clicks
|