toiljs 0.0.128 → 0.0.129
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 +7 -0
- package/build/compiler/index.js +2 -0
- package/build/compiler/security-deployment.d.ts +3 -0
- package/build/compiler/security-deployment.js +88 -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,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [v0.0.129] - 2026-10-19
|
|
4
|
+
|
|
5
|
+
- 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.
|
|
6
|
+
- 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.
|
|
7
|
+
- Correct RegExp compile-error guidance, the framed and domain-separated user-id derivation, and startup Job permissions throughout the docs and API comments.
|
|
8
|
+
- Ship the native auth vectors as a package JSON export and beside the generated protocol guide so its fixture link resolves.
|
|
9
|
+
|
|
3
10
|
## [v0.0.128] - 2026-10-18
|
|
4
11
|
|
|
5
12
|
- 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,88 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
function headerRules(source) {
|
|
4
|
+
const rules = [];
|
|
5
|
+
let current;
|
|
6
|
+
for (const line of source.split(/\r?\n/)) {
|
|
7
|
+
const text = line.trim();
|
|
8
|
+
if (!text || text.startsWith('#'))
|
|
9
|
+
continue;
|
|
10
|
+
if (!/^\s/.test(line)) {
|
|
11
|
+
current = { pattern: text, headers: [] };
|
|
12
|
+
rules.push(current);
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (current === undefined)
|
|
16
|
+
continue;
|
|
17
|
+
const removal = /^!\s+([^\s:]+)$/.exec(text);
|
|
18
|
+
if (removal) {
|
|
19
|
+
current.headers.push({ name: removal[1], value: null });
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const header = /^([^\s:]+):\s*(.*)$/.exec(text);
|
|
23
|
+
if (header)
|
|
24
|
+
current.headers.push({ name: header[1], value: header[2] });
|
|
25
|
+
}
|
|
26
|
+
return rules.filter((rule) => rule.headers.length > 0);
|
|
27
|
+
}
|
|
28
|
+
function match(field, pattern) {
|
|
29
|
+
return `${field} ${pattern.includes('*') ? 'strict wildcard' : 'eq'} ${JSON.stringify(pattern)}`;
|
|
30
|
+
}
|
|
31
|
+
function expression(pattern, hostname) {
|
|
32
|
+
const absolute = /^https:\/\/([^/]+)(\/.*)?$/.exec(pattern);
|
|
33
|
+
const host = absolute?.[1] ?? hostname;
|
|
34
|
+
const pathname = absolute ? (absolute[2] ?? '/') : pattern;
|
|
35
|
+
if (!pathname.startsWith('/') || /:[A-Za-z_]\w*/.test(pathname))
|
|
36
|
+
return null;
|
|
37
|
+
const pathMatch = match('http.request.uri.path', pathname);
|
|
38
|
+
return host ? `(${match('http.host', host)}) and (${pathMatch})` : pathMatch;
|
|
39
|
+
}
|
|
40
|
+
export function securityDeploymentInstructions(headers, siteUrl) {
|
|
41
|
+
const rules = headerRules(headers);
|
|
42
|
+
if (!rules.some((rule) => rule.headers.some((header) => /^(content-security-policy|cross-origin-opener-policy)(-report-only)?$/i.test(header.name) &&
|
|
43
|
+
header.value !== null &&
|
|
44
|
+
header.value !== '')))
|
|
45
|
+
return null;
|
|
46
|
+
const site = siteUrl && URL.canParse(siteUrl) ? new URL(siteUrl) : undefined;
|
|
47
|
+
const hostname = site && ['https:', 'http:'].includes(site.protocol) ? site.hostname : undefined;
|
|
48
|
+
const lines = [
|
|
49
|
+
'\nBrowser security deployment setup',
|
|
50
|
+
'Cloudflare Pages static hosting: deploy the generated _headers with the client output.',
|
|
51
|
+
'Other hosts must send the generated response headers; uploading _headers alone does not apply them.',
|
|
52
|
+
'toiljs start applies the framework headers automatically. Pages Functions / Workers must set headers in their handlers.',
|
|
53
|
+
'',
|
|
54
|
+
'Cloudflare: Rules > Transform Rules > Modify Response Header > Create rule.',
|
|
55
|
+
'Create the following rules in order using Custom filter expression > Edit expression.',
|
|
56
|
+
'Choose Set static for each header value, or Remove where indicated, then Deploy.',
|
|
57
|
+
];
|
|
58
|
+
if (!hostname)
|
|
59
|
+
lines.push('No site hostname configured in client.seo.url: scope these expressions to your deployment hostname if needed.');
|
|
60
|
+
for (const [index, rule] of rules.entries()) {
|
|
61
|
+
lines.push('', `${index + 1}. ${rule.pattern}`);
|
|
62
|
+
const filter = expression(rule.pattern, hostname);
|
|
63
|
+
if (filter === null ||
|
|
64
|
+
rule.headers.some((header) => /:[A-Za-z_]\w*/.test(header.value ?? ''))) {
|
|
65
|
+
lines.push('This rule uses a pattern or placeholder requiring configuration at the origin or in a Worker.', rule.pattern, ...rule.headers.map((header) => header.value === null
|
|
66
|
+
? ` ! ${header.name}`
|
|
67
|
+
: ` ${header.name}: ${header.value}`));
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
lines.push('Expression:', filter);
|
|
71
|
+
for (const header of rule.headers) {
|
|
72
|
+
if (header.value === null)
|
|
73
|
+
lines.push(`Remove: ${header.name}`);
|
|
74
|
+
else
|
|
75
|
+
lines.push(`Set static: ${header.name}`, 'Value:', header.value);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
lines.push('', 'Keep the generated HTML CSP meta policy, import map, and integrity attributes when deploying.', '');
|
|
79
|
+
return lines.join('\n');
|
|
80
|
+
}
|
|
81
|
+
export function logSecurityDeployment(cfg) {
|
|
82
|
+
const file = path.resolve(cfg.root, cfg.outDir, '_headers');
|
|
83
|
+
if (!fs.existsSync(file))
|
|
84
|
+
return;
|
|
85
|
+
const instructions = securityDeploymentInstructions(fs.readFileSync(file, 'utf8'), cfg.seo?.url);
|
|
86
|
+
if (instructions !== null)
|
|
87
|
+
process.stdout.write(instructions + '\n');
|
|
88
|
+
}
|