toiljs 0.0.128 → 0.0.130
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/CHANGELOG.md +11 -0
- package/build/compiler/index.js +2 -0
- package/build/compiler/security-deployment.d.ts +3 -0
- package/build/compiler/security-deployment.js +103 -0
- package/build/compiler/toil-docs.generated.js +12 -11
- package/build/shared/security.js +16 -0
- package/docs/auth/vectors-v1.json +41 -0
- package/package.json +2 -1
- package/scripts/gen-toil-docs.mjs +19 -7
- package/server/globals/userid.ts +4 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [v0.0.130] - 2026-10-19
|
|
4
|
+
|
|
5
|
+
- Format browser security deployment instructions with colored headings and actions, aligned hosting guidance, and spaced rule blocks. Preserve complete copyable expressions and header values, generic project rules, and plain output when terminal colors are disabled.
|
|
6
|
+
|
|
7
|
+
## [v0.0.129] - 2026-10-19
|
|
8
|
+
|
|
9
|
+
- Print generic Cloudflare deployment instructions after successful client builds, using the final generated header rules, configured hostname, complete policy values, and project-defined route exceptions.
|
|
10
|
+
- Support explicit `script-src` and `script-src-elem` overrides and an empty `require-trusted-types-for` array for script-injecting integrations such as Cloudflare analytics and challenges. Strict hash/nonce and Trusted Types defaults remain enabled unless explicitly overridden; document the reduced injection protection of compatibility settings.
|
|
11
|
+
- Correct RegExp compile-error guidance, the framed and domain-separated user-id derivation, and startup Job permissions throughout the docs and API comments.
|
|
12
|
+
- Ship the native auth vectors as a package JSON export and beside the generated protocol guide so its fixture link resolves.
|
|
13
|
+
|
|
3
14
|
## [v0.0.128] - 2026-10-18
|
|
4
15
|
|
|
5
16
|
- Add query-readable `SortedIndex` cursor pages and sortable `SortKey` encodings, so request handlers can read ordered lists without assembling their own paged Views.
|
package/build/compiler/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import { generate, TOIL_SERVER_ENV_DTS } from './generate.js';
|
|
|
14
14
|
import { prerenderStaticParams } from './ssg.js';
|
|
15
15
|
import { extractDevSsrTemplates, extractServerSlots, extractTemplates, } from './template-build.js';
|
|
16
16
|
import { createViteConfig } from './vite.js';
|
|
17
|
+
import { logSecurityDeployment } from './security-deployment.js';
|
|
17
18
|
export const SURFACE_DECORATOR = /^[ \t]*@(data|rest|service|remote|stream|daemon|scheduled)\b/m;
|
|
18
19
|
function toilconfigEntries(root) {
|
|
19
20
|
try {
|
|
@@ -748,6 +749,7 @@ export async function build(opts = {}) {
|
|
|
748
749
|
process.stdout.write(pc.dim(' SSR template changed; recompiling the server with the new hash…') + '\n');
|
|
749
750
|
await buildServer(cfg.root, cfg.auth);
|
|
750
751
|
}
|
|
752
|
+
logSecurityDeployment(cfg);
|
|
751
753
|
}
|
|
752
754
|
export async function start(opts = {}) {
|
|
753
755
|
const cfg = await loadConfig(opts);
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import pc from 'picocolors';
|
|
4
|
+
function headerRules(source) {
|
|
5
|
+
const rules = [];
|
|
6
|
+
let current;
|
|
7
|
+
for (const line of source.split(/\r?\n/)) {
|
|
8
|
+
const text = line.trim();
|
|
9
|
+
if (!text || text.startsWith('#'))
|
|
10
|
+
continue;
|
|
11
|
+
if (!/^\s/.test(line)) {
|
|
12
|
+
current = { pattern: text, headers: [] };
|
|
13
|
+
rules.push(current);
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (current === undefined)
|
|
17
|
+
continue;
|
|
18
|
+
const removal = /^!\s+([^\s:]+)$/.exec(text);
|
|
19
|
+
if (removal) {
|
|
20
|
+
current.headers.push({ name: removal[1], value: null });
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const header = /^([^\s:]+):\s*(.*)$/.exec(text);
|
|
24
|
+
if (header)
|
|
25
|
+
current.headers.push({ name: header[1], value: header[2] });
|
|
26
|
+
}
|
|
27
|
+
return rules.filter((rule) => rule.headers.length > 0);
|
|
28
|
+
}
|
|
29
|
+
function match(field, pattern) {
|
|
30
|
+
return `${field} ${pattern.includes('*') ? 'strict wildcard' : 'eq'} ${JSON.stringify(pattern)}`;
|
|
31
|
+
}
|
|
32
|
+
function expression(pattern, hostname) {
|
|
33
|
+
const absolute = /^https:\/\/([^/]+)(\/.*)?$/.exec(pattern);
|
|
34
|
+
const host = absolute?.[1] ?? hostname;
|
|
35
|
+
const pathname = absolute ? (absolute[2] ?? '/') : pattern;
|
|
36
|
+
if (!pathname.startsWith('/') || /:[A-Za-z_]\w*/.test(pathname))
|
|
37
|
+
return null;
|
|
38
|
+
const pathMatch = match('http.request.uri.path', pathname);
|
|
39
|
+
return host ? `(${match('http.host', host)}) and (${pathMatch})` : pathMatch;
|
|
40
|
+
}
|
|
41
|
+
export function securityDeploymentInstructions(headers, siteUrl, color = pc.isColorSupported) {
|
|
42
|
+
const rules = headerRules(headers);
|
|
43
|
+
if (!rules.some((rule) => rule.headers.some((header) => /^(content-security-policy|cross-origin-opener-policy)(-report-only)?$/i.test(header.name) &&
|
|
44
|
+
header.value !== null &&
|
|
45
|
+
header.value !== '')))
|
|
46
|
+
return null;
|
|
47
|
+
const site = siteUrl && URL.canParse(siteUrl) ? new URL(siteUrl) : undefined;
|
|
48
|
+
const hostname = site && ['https:', 'http:'].includes(site.protocol) ? site.hostname : undefined;
|
|
49
|
+
const colors = pc.createColors(color);
|
|
50
|
+
const separator = ` ${colors.dim('─'.repeat(64))}`;
|
|
51
|
+
const lines = [
|
|
52
|
+
'',
|
|
53
|
+
` ${colors.bold(colors.cyan('Browser security deployment setup'))}`,
|
|
54
|
+
separator,
|
|
55
|
+
'',
|
|
56
|
+
` ${colors.bold('Hosting')}`,
|
|
57
|
+
...[
|
|
58
|
+
['Cloudflare Pages', 'Deploy _headers with the client output.'],
|
|
59
|
+
['toiljs start', 'Framework headers apply automatically.'],
|
|
60
|
+
['Other hosts', 'Configure response headers on your host.'],
|
|
61
|
+
['', 'Uploading _headers alone does not apply them.'],
|
|
62
|
+
['Functions / Workers', 'Set response headers in your handlers.'],
|
|
63
|
+
].map(([label, description]) => ` ${colors.bold(label.padEnd(21))}${description}`),
|
|
64
|
+
'',
|
|
65
|
+
` ${colors.bold('Cloudflare response header rules')}`,
|
|
66
|
+
` Rules ${colors.dim('›')} Transform Rules ${colors.dim('›')} Modify Response Header ${colors.dim('›')} Create rule`,
|
|
67
|
+
'',
|
|
68
|
+
' Create the rules below in order.',
|
|
69
|
+
` Select ${colors.bold('Custom filter expression')} ${colors.dim('›')} ${colors.bold('Edit expression')}.`,
|
|
70
|
+
` Choose ${colors.green('Set static')} or ${colors.yellow('Remove')} as shown, then ${colors.bold('Deploy')}.`,
|
|
71
|
+
'',
|
|
72
|
+
];
|
|
73
|
+
if (!hostname)
|
|
74
|
+
lines.push(` ${colors.yellow('No site hostname configured')} in client.seo.url.`, ' Scope these expressions to your deployment hostname if needed.', '');
|
|
75
|
+
for (const [index, rule] of rules.entries()) {
|
|
76
|
+
lines.push(separator, '', ` ${colors.bold(colors.cyan(`${index + 1}. ${rule.pattern}`))}`, '');
|
|
77
|
+
const filter = expression(rule.pattern, hostname);
|
|
78
|
+
if (filter === null ||
|
|
79
|
+
rule.headers.some((header) => /:[A-Za-z_]\w*/.test(header.value ?? ''))) {
|
|
80
|
+
lines.push(` ${colors.yellow('Configure at the origin or in a Worker')}`, ' This rule uses a pattern or placeholder requiring configuration there.', '', ` ${rule.pattern}`, ...rule.headers.map((header) => header.value === null
|
|
81
|
+
? ` ! ${header.name}`
|
|
82
|
+
: ` ${header.name}: ${header.value}`), '');
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
lines.push(` ${colors.dim('Expression')}`, ` ${filter}`, '');
|
|
86
|
+
for (const header of rule.headers) {
|
|
87
|
+
if (header.value === null)
|
|
88
|
+
lines.push(` ${colors.yellow('Remove')} ${colors.bold(header.name)}`, '');
|
|
89
|
+
else
|
|
90
|
+
lines.push(` ${colors.green('Set static')} ${colors.bold(header.name)}`, ` ${colors.dim('Value')}`, ` ${header.value}`, '');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
lines.push(separator, '', ` ${colors.bold('When deploying')}`, ' Keep the generated HTML CSP meta policy, import map, and integrity attributes.', ' Expressions and header values above are complete; copy each as a single value.', '');
|
|
94
|
+
return lines.join('\n');
|
|
95
|
+
}
|
|
96
|
+
export function logSecurityDeployment(cfg) {
|
|
97
|
+
const file = path.resolve(cfg.root, cfg.outDir, '_headers');
|
|
98
|
+
if (!fs.existsSync(file))
|
|
99
|
+
return;
|
|
100
|
+
const instructions = securityDeploymentInstructions(fs.readFileSync(file, 'utf8'), cfg.seo?.url);
|
|
101
|
+
if (instructions !== null)
|
|
102
|
+
process.stdout.write(instructions + '\n');
|
|
103
|
+
}
|