prunelle 0.8.0 → 0.10.0
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/llms.txt +68 -51
- package/package.json +7 -2
- package/src/a11y/declaration.ts +10 -17
- package/src/a11y/index.ts +69 -125
- package/src/animate.ts +127 -0
- package/src/build/asides.ts +51 -0
- package/src/build/bundle.ts +94 -136
- package/src/build/client-entries.ts +6 -6
- package/src/build/client-outputs.ts +75 -0
- package/src/build/client-plugin.ts +9 -4
- package/src/build/ecoindex.ts +4 -2
- package/src/build/files.ts +18 -0
- package/src/build/graph.ts +14 -6
- package/src/build/index.ts +23 -11
- package/src/build/island-promote.ts +42 -2
- package/src/build/islands.ts +63 -9
- package/src/build/key-types.ts +31 -0
- package/src/build/manifest.ts +117 -1
- package/src/build/plugin-host.ts +13 -1
- package/src/build/prerender.ts +8 -3
- package/src/build/reach.ts +18 -4
- package/src/build/report.ts +1 -1
- package/src/build/resolve.ts +5 -1
- package/src/build/route-types.ts +16 -0
- package/src/build/routes.ts +42 -15
- package/src/build/seed-ids.ts +65 -0
- package/src/build/seed-writes.ts +111 -0
- package/src/build/static-headers.ts +2 -2
- package/src/build/static.ts +1 -1
- package/src/cli/check-cache.ts +51 -0
- package/src/cli/check-consent.ts +95 -0
- package/src/cli/check-forms.ts +10 -2
- package/src/cli/check-links-patterns.ts +101 -0
- package/src/cli/check-links.ts +30 -105
- package/src/cli/check-regions.ts +185 -0
- package/src/cli/check-security.ts +50 -6
- package/src/cli/check.ts +49 -21
- package/src/cli/commands.ts +138 -16
- package/src/cli/docs.ts +21 -2
- package/src/cli/form-opaque-children.ts +40 -0
- package/src/cli/index.ts +1 -1
- package/src/cli/inspect.ts +2 -0
- package/src/cli/mcp-tools.ts +2 -2
- package/src/cli/new.ts +9 -5
- package/src/cli/upgrade-names.ts +14 -2
- package/src/cli/upgrade.ts +3 -0
- package/src/compiler/analyze.ts +22 -16
- package/src/compiler/cacheability-private.ts +13 -3
- package/src/compiler/cacheability.ts +24 -2
- package/src/compiler/compliance-contrast.ts +322 -0
- package/src/compiler/compliance-empty.ts +24 -0
- package/src/compiler/compliance-rgaa-content.ts +95 -0
- package/src/compiler/compliance-rgaa-criteria.ts +45 -0
- package/src/compiler/compliance-rgaa-pages.ts +140 -0
- package/src/compiler/compliance-rgaa.ts +19 -0
- package/src/compiler/compliance-rules.ts +72 -0
- package/src/compiler/compliance-third-party.ts +59 -0
- package/src/compiler/compliance-urls.ts +52 -0
- package/src/compiler/compliance.ts +61 -93
- package/src/compiler/cookie-inventory.ts +119 -0
- package/src/compiler/dom-attrs.ts +178 -22
- package/src/compiler/dom.ts +31 -44
- package/src/compiler/emit.ts +17 -6
- package/src/compiler/expr-context.ts +260 -207
- package/src/compiler/foreign-imports.ts +5 -3
- package/src/compiler/mistakes.ts +18 -9
- package/src/compiler/props-body.ts +263 -21
- package/src/compiler/props-pattern.ts +211 -0
- package/src/compiler/props.ts +324 -343
- package/src/compiler/signal-reads.ts +142 -29
- package/src/compiler/spread-handlers.ts +25 -13
- package/src/compiler/ssr-emit.ts +510 -0
- package/src/compiler/ssr-helpers.ts +165 -121
- package/src/compiler/ssr.ts +28 -441
- package/src/context.ts +14 -1
- package/src/dev/child.ts +1 -1
- package/src/dev/host-check.ts +2 -1
- package/src/dev/hot-islands.ts +71 -0
- package/src/dev/index.ts +31 -18
- package/src/dev/protocol.ts +1 -1
- package/src/dev/queue.ts +3 -2
- package/src/dev/reload.ts +5 -2
- package/src/dev/supervisor.ts +3 -1
- package/src/dev/watchers.ts +6 -2
- package/src/dom/action.ts +97 -14
- package/src/dom/attrs.ts +93 -25
- package/src/dom/extras.ts +91 -50
- package/src/dom/field-marks.ts +32 -0
- package/src/dom/hot.ts +9 -0
- package/src/dom/index.ts +44 -18
- package/src/dom/island-hot.ts +29 -0
- package/src/dom/island.ts +13 -2
- package/src/dom/loop.ts +259 -188
- package/src/dom/prefetch.ts +135 -0
- package/src/dom/regions.ts +515 -0
- package/src/dom/swap.ts +246 -0
- package/src/dom/trusted.ts +22 -0
- package/src/dom/upload.ts +44 -0
- package/src/eco/declaration.ts +44 -41
- package/src/eco/index.ts +8 -5
- package/src/href.ts +31 -0
- package/src/index.ts +12 -5
- package/src/plugins/config.ts +1 -1
- package/src/plugins/context.ts +7 -1
- package/src/plugins/daily.ts +27 -0
- package/src/plugins/index.ts +3 -3
- package/src/plugins/order.ts +1 -1
- package/src/plugins/public.ts +12 -5
- package/src/plugins/services.ts +88 -14
- package/src/plugins/types.ts +128 -10
- package/src/reactivity/graph.ts +244 -41
- package/src/reactivity/hmr.ts +101 -0
- package/src/reactivity/index.ts +243 -239
- package/src/reactivity/resource.ts +129 -0
- package/src/reactivity/seed.ts +141 -0
- package/src/reactivity/selector.ts +85 -47
- package/src/reactivity/server-seed.ts +202 -0
- package/src/reactivity/store.ts +331 -97
- package/src/rgpd/draft.ts +171 -0
- package/src/rgpd/forms.ts +85 -0
- package/src/rgpd/index.ts +57 -0
- package/src/server/action-flash.ts +1 -0
- package/src/server/action-protect.ts +3 -0
- package/src/server/action-registry.ts +11 -9
- package/src/server/action.ts +51 -19
- package/src/server/app-secret.ts +14 -8
- package/src/server/cache-invalidation.ts +97 -0
- package/src/server/compress.ts +55 -18
- package/src/server/consent.ts +21 -5
- package/src/server/cookie-inventory.ts +78 -0
- package/src/server/cookies.ts +77 -8
- package/src/server/cors.ts +98 -0
- package/src/server/csp-report.ts +90 -0
- package/src/server/discard.ts +13 -0
- package/src/server/document.ts +2 -2
- package/src/server/env.ts +1 -1
- package/src/server/errors.ts +9 -2
- package/src/server/field-errors.ts +91 -0
- package/src/server/form-schema.ts +16 -11
- package/src/server/health.ts +41 -11
- package/src/server/http.ts +28 -11
- package/src/server/index.ts +122 -307
- package/src/server/loader.ts +2 -0
- package/src/server/page.ts +3 -9
- package/src/server/plugin-host.ts +66 -16
- package/src/server/plugin-route-shadow.ts +24 -0
- package/src/server/public.ts +14 -3
- package/src/server/rate-limit.ts +49 -10
- package/src/server/region.ts +22 -2
- package/src/server/request-handler.ts +406 -0
- package/src/server/request-log.ts +94 -0
- package/src/server/route-cache.ts +55 -8
- package/src/server/route-input.ts +54 -0
- package/src/server/route-table.ts +53 -27
- package/src/server/router.ts +2 -1
- package/src/server/routing.ts +104 -45
- package/src/server/sanitize-html.ts +4 -2
- package/src/server/security.ts +38 -8
- package/src/server/serve-handlers.ts +16 -6
- package/src/server/served-file.ts +19 -14
- package/src/server/shared-store.ts +323 -0
- package/src/server/start.ts +12 -5
- package/src/server/static-dir.ts +34 -12
- package/src/server/stream.ts +2 -1
- package/src/server/surface.ts +39 -0
- package/src/server/webhook.ts +50 -0
- package/src/server/workers.ts +168 -0
- package/src/ssr/consent-banner.ts +20 -16
- package/src/ssr/consent-texts.ts +40 -0
- package/src/ssr/context.ts +174 -53
- package/src/ssr/cookie-table.ts +75 -0
- package/src/ssr/index.ts +63 -58
- package/src/ssr/navigation.ts +161 -14
- package/src/ssr/region.ts +9 -3
- package/src/style.ts +12 -5
- package/src/test/browser.ts +53 -23
- package/src/test/build-reuse.ts +85 -0
- package/src/test/index.ts +51 -8
- package/src/test/mount.ts +53 -0
- package/src/test/outside.ts +94 -0
- package/src/ts-plugin/diagnostics.ts +56 -18
- package/templates/_shared/AGENTS.md +1 -1
- package/templates/_shared/Dockerfile +22 -0
- package/templates/_shared/dockerignore +9 -0
- package/templates/_shared/gitignore +2 -0
- package/templates/app/.env.example +3 -1
- package/templates/app/compose.yaml +32 -0
- package/templates/app/db/migrations/001_notes.sql +7 -0
- package/templates/app/db/schema.ts +11 -0
- package/templates/app/package.json +1 -0
- package/templates/app/prunelle.config.ts +6 -0
- package/templates/app/src/actions/notes.ts +26 -0
- package/templates/app/src/auth.ts +4 -2
- package/templates/app/src/db.ts +5 -0
- package/templates/app/src/routes/dashboard/index.tsx +26 -1
- package/templates/app/src/routes/privacy.tsx +6 -2
- package/templates/app/tests/app.test.ts +14 -3
- package/templates/plugin/AGENTS.md +11 -0
- package/templates/plugin/CLAUDE.md +1 -0
- package/templates/plugin/README.md +27 -0
- package/templates/plugin/gitignore +2 -0
- package/templates/plugin/llms.txt +19 -0
- package/templates/plugin/package.json +33 -0
- package/templates/plugin/src/index.ts +40 -0
- package/templates/plugin/tests/fixture/prunelle.config.ts +4 -0
- package/templates/plugin/tests/fixture/src/routes/index.tsx +11 -0
- package/templates/plugin/tests/plugin.test.ts +42 -0
- package/templates/plugin/tsconfig.json +19 -0
- package/ts-plugin.cjs +4058 -2246
|
@@ -4,9 +4,11 @@ import { mail } from './mail'
|
|
|
4
4
|
|
|
5
5
|
// Set AUTH_SECRET (at least 32 bytes) in production — see .env.example.
|
|
6
6
|
export const auth = createAuth({
|
|
7
|
-
//
|
|
8
|
-
store: sqliteAuthStore(process.env.
|
|
7
|
+
// The `store` of prunelle.config.ts, opened here too so a test or a script reaches the accounts.
|
|
8
|
+
store: sqliteAuthStore(process.env.DATABASE || 'data/app.db'),
|
|
9
9
|
secret: process.env.AUTH_SECRET || undefined,
|
|
10
10
|
defaultRedirect: '/dashboard',
|
|
11
11
|
mailer: mail,
|
|
12
|
+
// An account nobody signs in to for 2 years is deleted, its owner mailed 30 days before.
|
|
13
|
+
inactivity: true,
|
|
12
14
|
})
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import type { PageProps } from 'prunelle'
|
|
2
|
-
import { Button, Card, CardBody, CardHeader, Checkbox, Cluster, Notice, Stack } from '@prunellejs/ui'
|
|
2
|
+
import { Button, Card, CardBody, CardHeader, Checkbox, Cluster, Field, Notice, Stack } from '@prunellejs/ui'
|
|
3
3
|
import { Head } from 'prunelle'
|
|
4
|
+
import { getActionError } from 'prunelle/server'
|
|
5
|
+
import { addNote } from '../../actions/notes'
|
|
4
6
|
import { auth } from '../../auth'
|
|
7
|
+
import { db } from '../../db'
|
|
8
|
+
|
|
9
|
+
interface Note { id: number, body: string }
|
|
5
10
|
|
|
6
11
|
export default async function DashboardPage({ locals, url }: PageProps) {
|
|
7
12
|
// A refused export or deletion comes back here with a code naming why.
|
|
8
13
|
const message = auth.formMessage(url)
|
|
9
14
|
const refusal = message?.form === 'account' ? message : undefined
|
|
15
|
+
const notes: Note[] = await db.sql`select id, body from notes where user_id = ${locals.user!.id} order by created_at desc, id desc`
|
|
16
|
+
const noteError = getActionError(locals)?.fieldErrors?.body
|
|
10
17
|
|
|
11
18
|
return (
|
|
12
19
|
<Stack gap="lg">
|
|
@@ -17,6 +24,24 @@ export default async function DashboardPage({ locals, url }: PageProps) {
|
|
|
17
24
|
<p class="m-0">Signed in as <strong>{locals.user?.email}</strong>.</p>
|
|
18
25
|
</CardBody>
|
|
19
26
|
</Card>
|
|
27
|
+
<Card>
|
|
28
|
+
<CardHeader><h2 class="card-title">Your notes</h2></CardHeader>
|
|
29
|
+
<CardBody>
|
|
30
|
+
<Stack gap="md">
|
|
31
|
+
<form action={addNote} method="post">
|
|
32
|
+
<Stack gap="sm">
|
|
33
|
+
<Field id="note-body" label="New note" error={noteError} required><textarea id="note-body" name="body" rows="3" /></Field>
|
|
34
|
+
<Cluster>
|
|
35
|
+
<Button type="submit">Add the note</Button>
|
|
36
|
+
</Cluster>
|
|
37
|
+
</Stack>
|
|
38
|
+
</form>
|
|
39
|
+
{notes.length === 0
|
|
40
|
+
? <p class="m-0">No notes yet.</p>
|
|
41
|
+
: <ul>{notes.map(note => <li>{note.body}</li>)}</ul>}
|
|
42
|
+
</Stack>
|
|
43
|
+
</CardBody>
|
|
44
|
+
</Card>
|
|
20
45
|
<Card>
|
|
21
46
|
<CardHeader><h2 class="card-title">Your data</h2></CardHeader>
|
|
22
47
|
<CardBody>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Head } from 'prunelle'
|
|
1
|
+
import { CookieTable, Head } from 'prunelle'
|
|
2
2
|
|
|
3
3
|
// What the RGPD (art. 13) asks to tell people when their data is collected, written for what @prunellejs/auth stores by default; `prunelle check` warns until every placeholder below is replaced.
|
|
4
4
|
// Change it when the app collects more, or when you change the auth plugin's storeIp, storeUserAgent or sessionTtlSeconds.
|
|
@@ -13,9 +13,13 @@ export default function Privacy() {
|
|
|
13
13
|
<p>__APP_NAME__ is run by [to fill in: your name or your company's, as on the legal notice]. For any question about your data, write to [to fill in: a contact email].</p>
|
|
14
14
|
<h2>What we collect and why</h2>
|
|
15
15
|
<p>To create your account and sign you in: your email address and a hash of your password, never the password itself. This is needed to provide the service you sign up for (RGPD art. 6.1.b).</p>
|
|
16
|
+
<p>To keep the notes you write: their text, for the same reason.</p>
|
|
16
17
|
<p>To keep you signed in and protect your account: a session cookie, which the site cannot work without and which therefore needs no consent, and for each session the name of your browser and a shortened IP address with its last part removed.</p>
|
|
17
18
|
<h2>How long we keep it</h2>
|
|
18
|
-
<p>A session ends 30 days after your last visit, or when you sign out, and is then deleted. An account whose email address is not confirmed within 7 days is deleted. Your account
|
|
19
|
+
<p>A session ends 30 days after your last visit, or when you sign out, and is then deleted. An account whose email address is not confirmed within 7 days is deleted. Your account and your notes are kept until you delete the account from your dashboard.</p>
|
|
20
|
+
<h2>Cookies</h2>
|
|
21
|
+
<p>Every cookie this site sets is essential to it, so none waits for your consent:</p>
|
|
22
|
+
<CookieTable />
|
|
19
23
|
<h2>Who receives it</h2>
|
|
20
24
|
<p>Nobody else: the data stays with our host, [to fill in: the host's name], and is not shared or sold.</p>
|
|
21
25
|
<h2>Your rights</h2>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { TestApp } from 'prunelle/test'
|
|
2
2
|
import { beforeAll, describe, expect, it } from 'bun:test'
|
|
3
|
+
import { Database } from 'bun:sqlite'
|
|
3
4
|
import { mkdtempSync } from 'node:fs'
|
|
4
5
|
import { tmpdir } from 'node:os'
|
|
5
6
|
import { join, resolve } from 'node:path'
|
|
@@ -7,7 +8,7 @@ import { testApp } from 'prunelle/test'
|
|
|
7
8
|
|
|
8
9
|
const root = resolve(import.meta.dir, '..')
|
|
9
10
|
// A file the app and this test both open, so a user the test creates can sign in to the app.
|
|
10
|
-
process.env.
|
|
11
|
+
process.env.DATABASE ??= join(mkdtempSync(join(tmpdir(), '__APP_NAME__-')), 'app.db')
|
|
11
12
|
const { auth } = await import('../src/auth')
|
|
12
13
|
|
|
13
14
|
describe('__APP_NAME__', () => {
|
|
@@ -30,6 +31,7 @@ describe('__APP_NAME__', () => {
|
|
|
30
31
|
|
|
31
32
|
const privacy = await app.get('/privacy')
|
|
32
33
|
expect(privacy.status).toBe(200)
|
|
34
|
+
expect(await privacy.text()).toContain('<td><code>pru_session</code></td><td>Keeps you signed in.</td><td>Essential</td><td>30 days</td>')
|
|
33
35
|
expect(app.errors).toEqual([])
|
|
34
36
|
})
|
|
35
37
|
|
|
@@ -41,7 +43,7 @@ describe('__APP_NAME__', () => {
|
|
|
41
43
|
expect(page).toContain('Invalid email or password')
|
|
42
44
|
})
|
|
43
45
|
|
|
44
|
-
it('lets a signed-in user download their data and delete their account
|
|
46
|
+
it('lets a signed-in user write notes, download them with their data and delete them with their account', async () => {
|
|
45
47
|
const credentials = { email: 'ada@example.com', password: 'correct-horse-battery' }
|
|
46
48
|
await auth.createUser({ ...credentials, emailVerified: true })
|
|
47
49
|
const fromLogin = { referer: 'http://localhost/login' }
|
|
@@ -55,12 +57,21 @@ describe('__APP_NAME__', () => {
|
|
|
55
57
|
expect(refused).toContain('Sign in again to confirm it is you')
|
|
56
58
|
expect(refused).toContain('<a href="/login">Sign in</a>')
|
|
57
59
|
|
|
60
|
+
const { addNote } = await app.import('src/actions/notes.ts') as typeof import('../src/actions/notes')
|
|
61
|
+
expect((await app.submit(addNote, { body: 'Buy milk' }, fromDashboard)).headers.get('location')).toBe('/dashboard')
|
|
62
|
+
expect(await (await app.get('/dashboard')).text()).toContain('<li>Buy milk</li>')
|
|
63
|
+
|
|
58
64
|
const dump = await app.get('/auth/me/export', fromDashboard)
|
|
59
65
|
expect(dump.status).toBe(200)
|
|
60
|
-
|
|
66
|
+
const exported = await dump.json() as { user: { email: string }, data: { notes: { body: string }[] } }
|
|
67
|
+
expect(exported.user.email).toBe('ada@example.com')
|
|
68
|
+
expect(exported.data.notes.map(note => note.body)).toEqual(['Buy milk'])
|
|
61
69
|
|
|
62
70
|
const deleted = await app.submit('/auth/me/delete', { confirm: 'on', redirect: '/' }, fromDashboard)
|
|
63
71
|
expect(deleted.headers.get('location')).toBe('/')
|
|
72
|
+
const database = new Database(process.env.DATABASE)
|
|
73
|
+
expect(database.query('select count(*) as n from notes').get()).toEqual({ n: 0 })
|
|
74
|
+
database.close()
|
|
64
75
|
expect((await app.get('/dashboard')).status).toBe(302)
|
|
65
76
|
expect((await app.submit('/auth/signin', credentials, fromLogin)).headers.get('location')).toBe('/login?error=signin.invalid-credentials')
|
|
66
77
|
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# __APP_NAME__
|
|
2
|
+
|
|
3
|
+
A prunelle plugin. Read `node_modules/prunelle/llms.txt` before writing code: it holds prunelle's whole API, the `PrunellePlugin` hooks included, for the version installed here.
|
|
4
|
+
|
|
5
|
+
## Workflow
|
|
6
|
+
|
|
7
|
+
- **Verify changes**: `bun test` (the plugin mounted on `tests/fixture` with `testApp` from `prunelle/test`) and `bun run check` (TypeScript).
|
|
8
|
+
- **Keep `llms.txt` current**: it is what an agent working on an app reads to use this plugin, and `prunelle docs` searches it. A change to an option or an export updates it in the same commit.
|
|
9
|
+
- **Report mistakes early**: a misused option throws from the factory, what may be intended is a `ctx.warn()` in `check()`, and what production cannot run without is a message from `requires()`. Each names the option and its fix.
|
|
10
|
+
|
|
11
|
+
@node_modules/prunelle/llms.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# __APP_NAME__
|
|
2
|
+
|
|
3
|
+
A [prunelle](https://prunelle.kaynooo.fr) plugin serving `/.well-known/security.txt`.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
bun add __APP_NAME__
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// prunelle.config.ts
|
|
11
|
+
import { defineConfig } from 'prunelle/config'
|
|
12
|
+
import { securityTxt } from '__APP_NAME__'
|
|
13
|
+
|
|
14
|
+
export default defineConfig({ plugins: [securityTxt({ contact: 'mailto:security@example.com', expires: '2027-06-30' })] })
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`llms.txt` documents the options for coding agents, and `prunelle docs` searches it in any app that installs the plugin.
|
|
18
|
+
|
|
19
|
+
## Developing
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
bun install
|
|
23
|
+
bun test
|
|
24
|
+
bun run check
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The tests mount the plugin on the app in `tests/fixture` with `testApp` from `prunelle/test`, in-process and with no port bound. [Writing a plugin](https://prunelle.kaynooo.fr/docs/production/writing-a-plugin) covers each hook and how to publish.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# __APP_NAME__ Reference
|
|
2
|
+
|
|
3
|
+
> A prunelle plugin serving `/.well-known/security.txt` (RFC 9116): where to report a vulnerability, and until when that address holds.
|
|
4
|
+
|
|
5
|
+
## Imports
|
|
6
|
+
|
|
7
|
+
- `__APP_NAME__`: `securityTxt`; type `SecurityTxtOptions`.
|
|
8
|
+
|
|
9
|
+
## Setup (`securityTxt(options)`)
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { defineConfig } from 'prunelle/config'
|
|
13
|
+
import { securityTxt } from '__APP_NAME__'
|
|
14
|
+
|
|
15
|
+
export default defineConfig({ plugins: [securityTxt({ contact: 'mailto:security@example.com', expires: '2027-06-30' })] })
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
- `contact`: a `mailto:` or `https://` URL; anything else throws as the config loads.
|
|
19
|
+
- `expires`: an ISO 8601 date, served in full (`2027-06-30T00:00:00.000Z`). One that is not a date throws; one more than a year ahead is a `prunelle check` warning; once it has passed, a production start refuses through `requires()`.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__APP_NAME__",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A prunelle plugin serving /.well-known/security.txt",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"files": [
|
|
8
|
+
"src",
|
|
9
|
+
"llms.txt"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./src/index.ts"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"prunelle",
|
|
16
|
+
"prunelle-plugin"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"bun": ">=1.4.0"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"check": "tsc",
|
|
23
|
+
"test": "bun test"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"prunelle": "__PRUNELLE_VERSION__"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/bun": "^1.4.4",
|
|
30
|
+
"prunelle": "__PRUNELLE_VERSION__",
|
|
31
|
+
"typescript": "^6.0.3"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// A prunelle plugin serving /.well-known/security.txt (RFC 9116): where to report a vulnerability, and until when that address holds.
|
|
2
|
+
|
|
3
|
+
import type { PrunellePlugin } from 'prunelle/config'
|
|
4
|
+
import { definePlugin } from 'prunelle/config'
|
|
5
|
+
|
|
6
|
+
export interface SecurityTxtOptions {
|
|
7
|
+
/** Where to report a vulnerability: a `mailto:` or `https://` URL. */
|
|
8
|
+
contact: string
|
|
9
|
+
/** When the file goes stale, as an ISO 8601 date such as `2027-06-30`: RFC 9116 asks for less than a year ahead. */
|
|
10
|
+
expires: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const CONTACT_RE = /^(?:mailto:|https:\/\/)\S+$/
|
|
14
|
+
const YEAR_MS = 365 * 24 * 60 * 60 * 1000
|
|
15
|
+
|
|
16
|
+
export function securityTxt(options: SecurityTxtOptions): PrunellePlugin {
|
|
17
|
+
// A misuse throws as the config loads, the earliest a plugin can report it, naming the option and its fix.
|
|
18
|
+
if (!CONTACT_RE.test(options.contact))
|
|
19
|
+
throw new Error(`__APP_NAME__: contact "${options.contact}" is neither a mailto: nor an https:// URL: give the address reports go to, such as mailto:security@example.com.`)
|
|
20
|
+
const expires = Date.parse(options.expires)
|
|
21
|
+
if (Number.isNaN(expires))
|
|
22
|
+
throw new Error(`__APP_NAME__: expires "${options.expires}" is not a date: give one such as 2027-06-30.`)
|
|
23
|
+
const body = `Contact: ${options.contact}\nExpires: ${new Date(expires).toISOString()}\n`
|
|
24
|
+
|
|
25
|
+
return definePlugin({
|
|
26
|
+
name: '__APP_NAME__',
|
|
27
|
+
server(api) {
|
|
28
|
+
api.route('GET', '/.well-known/security.txt', () => new Response(body, { headers: { 'content-type': 'text/plain; charset=utf-8' } }))
|
|
29
|
+
},
|
|
30
|
+
// What may be intended: `prunelle check` warns, and fails only under --strict.
|
|
31
|
+
check(ctx) {
|
|
32
|
+
if (expires - Date.now() > YEAR_MS)
|
|
33
|
+
ctx.warn(`__APP_NAME__: expires ${options.expires} is more than a year ahead, and RFC 9116 asks for less so a stale contact does not linger: set an earlier date.`)
|
|
34
|
+
},
|
|
35
|
+
// What production cannot run without: a production start refuses while any message is returned, and dev, tests and check warn, each after the plugin's name.
|
|
36
|
+
requires() {
|
|
37
|
+
return expires <= Date.now() ? [`security.txt expired on ${options.expires}, so reporters are told not to trust it: set \`expires\` to a date less than a year ahead.`] : []
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
import { testApp } from 'prunelle/test'
|
|
4
|
+
import { securityTxt } from '../src/index'
|
|
5
|
+
|
|
6
|
+
// The app the plugin is mounted on: `testApp` builds it in-process, with no port bound.
|
|
7
|
+
const root = join(import.meta.dir, 'fixture')
|
|
8
|
+
const DAY_MS = 24 * 60 * 60 * 1000
|
|
9
|
+
const daysFromNow = (days: number): string => new Date(Date.now() + days * DAY_MS).toISOString()
|
|
10
|
+
|
|
11
|
+
function checkWarnings(plugin: ReturnType<typeof securityTxt>): string[] {
|
|
12
|
+
const warnings: string[] = []
|
|
13
|
+
plugin.check?.({ root, routesDir: join(root, 'src/routes'), error: message => warnings.push(`error: ${message}`), warn: message => warnings.push(message) })
|
|
14
|
+
return warnings
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('__APP_NAME__', () => {
|
|
18
|
+
it('serves the contact and the expiry date, written in full as RFC 9116 asks, at /.well-known/security.txt', async () => {
|
|
19
|
+
const day = daysFromNow(30).slice(0, 10)
|
|
20
|
+
await using app = await testApp({ root, plugins: [securityTxt({ contact: 'mailto:security@example.com', expires: day })] })
|
|
21
|
+
const res = await app.get('/.well-known/security.txt')
|
|
22
|
+
expect(res.status).toBe(200)
|
|
23
|
+
expect(res.headers.get('content-type')).toBe('text/plain; charset=utf-8')
|
|
24
|
+
expect(await res.text()).toBe(`Contact: mailto:security@example.com\nExpires: ${day}T00:00:00.000Z\n`)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('refuses a contact that is not a mailto: or https:// URL, and an expiry that is not a date', () => {
|
|
28
|
+
expect(() => securityTxt({ contact: 'security@example.com', expires: '2027-06-30' })).toThrow('is neither a mailto: nor an https:// URL')
|
|
29
|
+
expect(() => securityTxt({ contact: 'https://example.com/report', expires: 'next year' })).toThrow('is not a date')
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('warns in prunelle check when the expiry is more than a year ahead', () => {
|
|
33
|
+
expect(checkWarnings(securityTxt({ contact: 'mailto:security@example.com', expires: daysFromNow(400) }))).toEqual([expect.stringContaining('is more than a year ahead')])
|
|
34
|
+
expect(checkWarnings(securityTxt({ contact: 'mailto:security@example.com', expires: daysFromNow(300) }))).toEqual([])
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('stops a production start once the file has expired', async () => {
|
|
38
|
+
const context = { root, site: undefined, consentCategories: [] }
|
|
39
|
+
expect(await securityTxt({ contact: 'mailto:security@example.com', expires: daysFromNow(-1) }).requires?.(context)).toEqual([expect.stringContaining('security.txt expired on')])
|
|
40
|
+
expect(await securityTxt({ contact: 'mailto:security@example.com', expires: daysFromNow(1) }).requires?.(context)).toEqual([])
|
|
41
|
+
})
|
|
42
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"jsxImportSource": "prunelle",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"types": [
|
|
12
|
+
"bun"
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
"include": [
|
|
16
|
+
"src",
|
|
17
|
+
"tests"
|
|
18
|
+
]
|
|
19
|
+
}
|