@apralabs/apra-fleet 0.4.4 → 0.4.5
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/README.md +49 -4
- package/dist/agents/backlog-groomer.md +5 -0
- package/dist/agents/ci-watcher.md +5 -0
- package/dist/agents/deployer.md +20 -2
- package/dist/agents/doer.md +38 -2
- package/dist/agents/harvester.md +12 -9
- package/dist/agents/integ-test-runner.md +5 -0
- package/dist/agents/kb-reconciler.md +6 -0
- package/dist/agents/plan-reviewer.md +5 -0
- package/dist/agents/planner.md +5 -0
- package/dist/agents/regression-test-runner.md +5 -0
- package/dist/agents/reviewer.md +67 -15
- package/dist/agents/schemas/deployer-output.json +5 -0
- package/dist/agents/schemas/doer-output.json +78 -2
- package/dist/agents/schemas/reviewer-output.json +104 -2
- package/dist/cli/auth.js +5 -1
- package/dist/cli/beads-pin.js +6 -7
- package/dist/cli/claude-mod.d.ts +75 -0
- package/dist/cli/claude-mod.js +288 -0
- package/dist/cli/dolt-install.d.ts +1 -1
- package/dist/cli/dolt-install.js +5 -1
- package/dist/cli/fleet-se-guard.d.ts +8 -0
- package/dist/cli/fleet-se-guard.js +19 -3
- package/dist/cli/install-guard.d.ts +9 -0
- package/dist/cli/install-guard.js +24 -0
- package/dist/cli/install.d.ts +12 -0
- package/dist/cli/install.js +180 -20
- package/dist/cli/kb-profile.d.ts +16 -0
- package/dist/cli/kb-profile.js +81 -0
- package/dist/cli/start.js +3 -0
- package/dist/cli/uninstall.js +13 -3
- package/dist/cli/update.d.ts +4 -0
- package/dist/cli/update.js +19 -3
- package/dist/commands/kb-server.d.ts +10 -1
- package/dist/commands/kb-server.js +285 -11
- package/dist/index.js +22 -1
- package/dist/os/git-executable.d.ts +57 -0
- package/dist/os/git-executable.js +85 -0
- package/dist/os/go-concurrency.d.ts +44 -0
- package/dist/os/go-concurrency.js +53 -0
- package/dist/os/index.d.ts +1 -0
- package/dist/os/index.js +1 -0
- package/dist/os/linux.d.ts +2 -0
- package/dist/os/linux.js +10 -1
- package/dist/os/os-commands.d.ts +25 -0
- package/dist/os/os-commands.js +2 -0
- package/dist/os/windows-executable.d.ts +53 -0
- package/dist/os/windows-executable.js +185 -0
- package/dist/os/windows-gitbash.d.ts +23 -14
- package/dist/os/windows-gitbash.js +40 -16
- package/dist/os/windows.d.ts +2 -0
- package/dist/os/windows.js +37 -6
- package/dist/paths.d.ts +10 -1
- package/dist/paths.js +19 -2
- package/dist/services/agy-project.d.ts +7 -1
- package/dist/services/agy-project.js +7 -2
- package/dist/services/auth-socket.d.ts +18 -0
- package/dist/services/auth-socket.js +30 -4
- package/dist/services/credential-store.d.ts +33 -0
- package/dist/services/credential-store.js +79 -2
- package/dist/services/http-transport.d.ts +29 -0
- package/dist/services/http-transport.js +166 -37
- package/dist/services/kb-tool-profile.d.ts +36 -0
- package/dist/services/kb-tool-profile.js +88 -0
- package/dist/services/knowledge/bible-blob-id.js +10 -1
- package/dist/services/knowledge/bible-import.d.ts +108 -0
- package/dist/services/knowledge/bible-import.js +137 -4
- package/dist/services/knowledge/file-hash.js +6 -5
- package/dist/services/knowledge/http-provider.d.ts +303 -20
- package/dist/services/knowledge/http-provider.js +795 -125
- package/dist/services/knowledge/kb-config.d.ts +65 -1
- package/dist/services/knowledge/kb-config.js +143 -3
- package/dist/services/knowledge/kb-http-auth-state.d.ts +26 -0
- package/dist/services/knowledge/kb-http-auth-state.js +40 -0
- package/dist/services/knowledge/kb-providers.d.ts +9 -2
- package/dist/services/knowledge/kb-providers.js +67 -37
- package/dist/services/knowledge/kb-removed-scope-keys.js +1 -1
- package/dist/services/knowledge/kb-self.d.ts +122 -9
- package/dist/services/knowledge/kb-self.js +196 -36
- package/dist/services/knowledge/member-bible-view.js +16 -3
- package/dist/services/knowledge/path-validation.d.ts +7 -0
- package/dist/services/knowledge/path-validation.js +11 -0
- package/dist/services/knowledge/project-slug.js +3 -2
- package/dist/services/knowledge/repository-header.d.ts +77 -0
- package/dist/services/knowledge/repository-header.js +233 -0
- package/dist/services/knowledge/require-sqlite-project.d.ts +1 -1
- package/dist/services/knowledge/require-sqlite-project.js +1 -1
- package/dist/services/knowledge/sqlite-provider.d.ts +169 -0
- package/dist/services/knowledge/sqlite-provider.js +416 -4
- package/dist/services/knowledge/types.d.ts +15 -2
- package/dist/services/member-busy.d.ts +12 -0
- package/dist/services/member-busy.js +20 -0
- package/dist/services/member-config-io.d.ts +3 -2
- package/dist/services/member-config-io.js +7 -4
- package/dist/services/member-fleet-install.js +1 -0
- package/dist/services/member-tool-allowlist.d.ts +1 -1
- package/dist/services/member-tool-allowlist.js +8 -4
- package/dist/services/port-holder.js +2 -1
- package/dist/services/service-manager/types.d.ts +17 -1
- package/dist/services/service-manager/windows.d.ts +7 -2
- package/dist/services/service-manager/windows.js +28 -11
- package/dist/services/service-notice.d.ts +7 -0
- package/dist/services/service-notice.js +19 -0
- package/dist/services/session-registry.d.ts +13 -0
- package/dist/services/session-registry.js +13 -0
- package/dist/services/session-roots.d.ts +67 -0
- package/dist/services/session-roots.js +126 -0
- package/dist/services/statusline.d.ts +21 -0
- package/dist/services/statusline.js +97 -1
- package/dist/services/supervisor-service-cleanup.js +2 -1
- package/dist/services/tool-registry.js +108 -20
- package/dist/services/tool-scope.d.ts +34 -1
- package/dist/services/tool-scope.js +27 -2
- package/dist/services/vcs/azure-devops.js +10 -0
- package/dist/services/vcs/bitbucket.d.ts +22 -1
- package/dist/services/vcs/bitbucket.js +163 -17
- package/dist/services/vcs/types.d.ts +25 -2
- package/dist/services/watch/project-resolver.js +2 -1
- package/dist/skills/pm/cost.md +5 -1
- package/dist/skills/pm/index.md +9 -9
- package/dist/skills/pm/sprint.md +2 -1
- package/dist/tools/check-status.d.ts +51 -0
- package/dist/tools/check-status.js +124 -12
- package/dist/tools/code-intelligence-freshness.js +1 -1
- package/dist/tools/code-intelligence-gitnexus.d.ts +19 -0
- package/dist/tools/code-intelligence-gitnexus.js +166 -9
- package/dist/tools/code-intelligence-readiness.d.ts +58 -1
- package/dist/tools/code-intelligence-readiness.js +93 -8
- package/dist/tools/code-intelligence-reindex.d.ts +25 -1
- package/dist/tools/code-intelligence-reindex.js +76 -4
- package/dist/tools/code-intelligence.d.ts +1 -1
- package/dist/tools/code-intelligence.js +1 -1
- package/dist/tools/execute-command.js +14 -8
- package/dist/tools/execute-prompt.js +6 -2
- package/dist/tools/fleet-snapshot.d.ts +21 -0
- package/dist/tools/fleet-snapshot.js +78 -0
- package/dist/tools/kb-bible-commit.d.ts +25 -11
- package/dist/tools/kb-bible-commit.js +142 -33
- package/dist/tools/kb-capture.d.ts +2 -2
- package/dist/tools/kb-context.js +47 -27
- package/dist/tools/kb-demote.d.ts +27 -0
- package/dist/tools/kb-demote.js +37 -0
- package/dist/tools/kb-export.d.ts +35 -3
- package/dist/tools/kb-export.js +56 -13
- package/dist/tools/kb-feedback.d.ts +2 -0
- package/dist/tools/kb-feedback.js +17 -7
- package/dist/tools/kb-harvest.js +28 -9
- package/dist/tools/kb-import.d.ts +18 -2
- package/dist/tools/kb-import.js +24 -9
- package/dist/tools/kb-invalidate.d.ts +11 -3
- package/dist/tools/kb-invalidate.js +80 -7
- package/dist/tools/kb-list.js +38 -10
- package/dist/tools/kb-promote.js +6 -4
- package/dist/tools/kb-query.d.ts +3 -0
- package/dist/tools/kb-query.js +181 -37
- package/dist/tools/kb-session-prime.d.ts +4 -4
- package/dist/tools/kb-session-prime.js +89 -9
- package/dist/tools/kb-setup.d.ts +20 -0
- package/dist/tools/kb-setup.js +149 -11
- package/dist/tools/list-members.js +1 -1
- package/dist/tools/member-detail.js +7 -3
- package/dist/tools/provision-vcs-auth.d.ts +28 -3
- package/dist/tools/provision-vcs-auth.js +53 -7
- package/dist/tools/receive-files.js +7 -4
- package/dist/tools/send-files.js +5 -4
- package/dist/tools/send-message.d.ts +3 -0
- package/dist/tools/send-message.js +15 -2
- package/dist/tools/stop-prompt.js +3 -1
- package/dist/tools/vcs-credential-exec.d.ts +45 -3
- package/dist/tools/vcs-credential-exec.js +90 -11
- package/dist/utils/process-utils.js +5 -1
- package/dist/utils/redact-known-secrets.d.ts +17 -0
- package/dist/utils/redact-known-secrets.js +70 -0
- package/dist/utils/skill-matrix.js +1 -1
- package/dist/utils/vcs-provider-detect.js +2 -2
- package/dist/workflows/auto-sprint.js +245 -9
- package/package.json +10 -7
- package/packages/apra-fleet-client/package.json +1 -1
- package/packages/apra-fleet-client/src/client/api.mjs +172 -19
- package/packages/apra-fleet-client/src/client/reconnecting-transport.mjs +35 -2
- package/packages/apra-fleet-client/src/client/transport.mjs +6 -0
- package/packages/apra-fleet-se/apra-pm/agents/backlog-groomer.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/ci-watcher.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/deployer.md +20 -2
- package/packages/apra-fleet-se/apra-pm/agents/doer.md +38 -2
- package/packages/apra-fleet-se/apra-pm/agents/harvester.md +12 -9
- package/packages/apra-fleet-se/apra-pm/agents/integ-test-runner.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/kb-reconciler.md +6 -0
- package/packages/apra-fleet-se/apra-pm/agents/plan-reviewer.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/planner.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/regression-test-runner.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/reviewer.md +67 -15
- package/packages/apra-fleet-se/apra-pm/agents/schemas/deployer-output.json +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/doer-output.json +78 -2
- package/packages/apra-fleet-se/apra-pm/agents/schemas/reviewer-output.json +104 -2
- package/packages/apra-fleet-se/apra-pm/skills/pm/cost.md +5 -1
- package/packages/apra-fleet-se/apra-pm/skills/pm/index.md +9 -9
- package/packages/apra-fleet-se/apra-pm/skills/pm/sprint.md +2 -1
- package/packages/apra-fleet-se/bin/cli.mjs +104 -31
- package/packages/apra-fleet-se/bin/serve.mjs +46 -8
- package/packages/apra-fleet-se/fleet-sprint/abort.mjs +184 -32
- package/packages/apra-fleet-se/fleet-sprint/bd-sync-command.mjs +69 -0
- package/packages/apra-fleet-se/fleet-sprint/beads-children.mjs +21 -0
- package/packages/apra-fleet-se/fleet-sprint/beads-lock-probe.mjs +176 -0
- package/packages/apra-fleet-se/fleet-sprint/beads-reachability.mjs +126 -0
- package/packages/apra-fleet-se/fleet-sprint/beads-scope.mjs +158 -1
- package/packages/apra-fleet-se/fleet-sprint/contracts.mjs +82 -2
- package/packages/apra-fleet-se/fleet-sprint/coordination.mjs +23 -6
- package/packages/apra-fleet-se/fleet-sprint/decision-notify.mjs +338 -0
- package/packages/apra-fleet-se/fleet-sprint/decision-wait.mjs +731 -0
- package/packages/apra-fleet-se/fleet-sprint/decisions.mjs +372 -0
- package/packages/apra-fleet-se/fleet-sprint/dispatch-role.mjs +44 -11
- package/packages/apra-fleet-se/fleet-sprint/docs/README.md +4 -1
- package/packages/apra-fleet-se/fleet-sprint/dolt-settle.mjs +9 -3
- package/packages/apra-fleet-se/fleet-sprint/dolt-sync.mjs +314 -19
- package/packages/apra-fleet-se/fleet-sprint/errors.mjs +72 -4
- package/packages/apra-fleet-se/fleet-sprint/git-sync.mjs +7 -1
- package/packages/apra-fleet-se/fleet-sprint/git-topology.mjs +112 -1
- package/packages/apra-fleet-se/fleet-sprint/guarded-modules.mjs +36 -2
- package/packages/apra-fleet-se/fleet-sprint/kb.mjs +736 -101
- package/packages/apra-fleet-se/fleet-sprint/member-init-probe.mjs +1 -1
- package/packages/apra-fleet-se/fleet-sprint/member-provisioning.mjs +7 -1
- package/packages/apra-fleet-se/fleet-sprint/phases/deploy.mjs +49 -2
- package/packages/apra-fleet-se/fleet-sprint/phases/develop.mjs +206 -3
- package/packages/apra-fleet-se/fleet-sprint/phases/final-review.mjs +61 -3
- package/packages/apra-fleet-se/fleet-sprint/phases/harvest.mjs +81 -31
- package/packages/apra-fleet-se/fleet-sprint/phases/plan.mjs +7 -3
- package/packages/apra-fleet-se/fleet-sprint/phases/publish-pr.mjs +39 -14
- package/packages/apra-fleet-se/fleet-sprint/phases/re-review.mjs +17 -1
- package/packages/apra-fleet-se/fleet-sprint/phases/review.mjs +18 -3
- package/packages/apra-fleet-se/fleet-sprint/pr-body.mjs +14 -1
- package/packages/apra-fleet-se/fleet-sprint/prompts.mjs +32 -5
- package/packages/apra-fleet-se/fleet-sprint/runner.js +824 -98
- package/packages/apra-fleet-se/fleet-sprint/se-os-commands.mjs +4 -2
- package/packages/apra-fleet-se/fleet-sprint/se-posix.mjs +54 -1
- package/packages/apra-fleet-se/fleet-sprint/se-windows.mjs +29 -2
- package/packages/apra-fleet-se/fleet-sprint/set-aside.mjs +288 -0
- package/packages/apra-fleet-se/fleet-sprint/skills/fleet-supervisor/SKILL.md +3 -2
- package/packages/apra-fleet-se/fleet-sprint/sprint-args.mjs +20 -0
- package/packages/apra-fleet-se/fleet-sprint/sprint-report.mjs +21 -0
- package/packages/apra-fleet-se/fleet-sprint/sprint-state.mjs +9 -0
- package/packages/apra-fleet-se/fleet-sprint/vcs-auth.mjs +605 -32
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/bitbucket.mjs +811 -17
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/index.mjs +89 -1
- package/packages/apra-fleet-se/fleet-sprint/viewer-extensions.mjs +225 -2
- package/packages/apra-fleet-se/fleet-sprint/worklists.mjs +59 -3
- package/packages/apra-fleet-se/src/supervisor/api.mjs +148 -8
- package/packages/apra-fleet-se/src/supervisor/dashboard.mjs +6 -3
- package/packages/apra-fleet-se/src/supervisor/dolt-mutex.mjs +30 -10
- package/packages/apra-fleet-se/src/supervisor/fleet-members.mjs +17 -4
- package/packages/apra-fleet-se/src/supervisor/history.mjs +8 -1
- package/packages/apra-fleet-se/src/supervisor/id-allocator.mjs +92 -2
- package/packages/apra-fleet-se/src/supervisor/proxy.mjs +26 -1
- package/packages/apra-fleet-se/src/supervisor/server.mjs +151 -8
- package/packages/apra-fleet-se/src/supervisor/spawner.mjs +11 -9
- package/packages/apra-fleet-se/src/supervisor/watchdog.mjs +7 -1
- package/packages/apra-fleet-workflow/package.json +2 -1
- package/packages/apra-fleet-workflow/src/viewer/index.mjs +86 -5
- package/packages/apra-fleet-workflow/src/viewer/request-guard.mjs +222 -0
- package/packages/apra-fleet-workflow/src/workflow/index.mjs +34 -2
- package/plugins/claude-code/fleet-status/.claude-plugin/plugin.json +7 -0
- package/plugins/claude-code/fleet-status/hooks/hooks.json +1 -0
- package/plugins/claude-code/fleet-status/hooks/register.tsx +906 -0
- package/plugins/claude-code/fleet-status/types/index.d.ts +88 -0
- package/skills/fleet/auth-bitbucket.md +47 -20
- package/skills/fleet/onboarding.md +1 -1
- package/skills/fleet/skill-matrix.md +3 -3
- package/version.json +1 -1
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// Mutating-request guard (cross-site request forgery defence)
|
|
3
|
+
// =============================================================================
|
|
4
|
+
//
|
|
5
|
+
// Shared by the supervisor's route() dispatcher (apra-fleet-se
|
|
6
|
+
// src/supervisor/server.mjs) and the per-run dashboard viewer's own POST
|
|
7
|
+
// routes (./index.mjs). Both bind loopback HTTP servers whose POST routes
|
|
8
|
+
// change state (record an operator answer, launch/stop a run, shut down), so
|
|
9
|
+
// any web page the operator happens to visit could otherwise fire a plain HTML
|
|
10
|
+
// form POST at them.
|
|
11
|
+
//
|
|
12
|
+
// Every non-GET/HEAD/OPTIONS request must:
|
|
13
|
+
// (a) carry Content-Type application/json -- a browser can only send that
|
|
14
|
+
// cross-site after a CORS preflight, which these servers never approve,
|
|
15
|
+
// and an HTML form can never send it at all; and
|
|
16
|
+
// (b) be same-origin: no Origin header (a non-browser client: curl, the
|
|
17
|
+
// sprint child's HTTP clients, a server-side proxy) or an Origin whose
|
|
18
|
+
// host equals the request's own Host; a Sec-Fetch-Site of cross-site or
|
|
19
|
+
// same-site is refused too -- UNLESS it carries a valid token
|
|
20
|
+
// (`Authorization: Bearer <token>` or `X-Fleet-Token: <token>`) and a
|
|
21
|
+
// token is configured.
|
|
22
|
+
// A presented token that does not match is always refused, even when the
|
|
23
|
+
// request would otherwise pass the origin check.
|
|
24
|
+
//
|
|
25
|
+
// DNS rebinding: (b) compares the Origin with the request's Host header, and a
|
|
26
|
+
// rebound page (attacker.example re-resolved to 127.0.0.1) controls BOTH and
|
|
27
|
+
// makes them agree. So the Host header is validated first, on EVERY request
|
|
28
|
+
// (GET included -- a rebound page could otherwise read /api/sprints, /state):
|
|
29
|
+
// checkRequestHost() admits only a Host whose name is a loopback name
|
|
30
|
+
// (localhost, 127.0.0.1, [::1]), any IP literal (a page served from an IP
|
|
31
|
+
// literal is served by that IP, so it cannot rebind to us), the server's own
|
|
32
|
+
// configured bind host (unless a wildcard), or an explicitly allowed extra
|
|
33
|
+
// name. The port is not compared: a rebinding attacker cannot choose the NAME
|
|
34
|
+
// the browser puts in Host, and a same-machine port-forward/reverse proxy
|
|
35
|
+
// legitimately changes the port. A token does not waive the Host check (a
|
|
36
|
+
// non-browser token holder sends a real name anyway).
|
|
37
|
+
// =============================================================================
|
|
38
|
+
|
|
39
|
+
import crypto from 'node:crypto';
|
|
40
|
+
import net from 'node:net';
|
|
41
|
+
|
|
42
|
+
const SAFE_METHODS = new Set(['GET', 'HEAD', 'OPTIONS']);
|
|
43
|
+
|
|
44
|
+
/** Header a client may use instead of `Authorization: Bearer`. */
|
|
45
|
+
export const TOKEN_HEADER = 'x-fleet-token';
|
|
46
|
+
|
|
47
|
+
function headerValue(req, name) {
|
|
48
|
+
const v = req && req.headers ? req.headers[name] : undefined;
|
|
49
|
+
if (Array.isArray(v)) return v[0];
|
|
50
|
+
return typeof v === 'string' ? v : undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function presentedToken(req) {
|
|
54
|
+
const auth = headerValue(req, 'authorization');
|
|
55
|
+
if (auth) {
|
|
56
|
+
// No regex: a prefix check cannot backtrack on a hostile header.
|
|
57
|
+
const a = auth.trim();
|
|
58
|
+
if (a.length > 7 && a.slice(0, 6).toLowerCase() === 'bearer' && /^\s$/.test(a[6])) {
|
|
59
|
+
const tok = a.slice(7).trim();
|
|
60
|
+
if (tok) return tok;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const t = headerValue(req, TOKEN_HEADER);
|
|
64
|
+
return t ? t.trim() : undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function tokensEqual(a, b) {
|
|
68
|
+
const ba = Buffer.from(String(a), 'utf-8');
|
|
69
|
+
const bb = Buffer.from(String(b), 'utf-8');
|
|
70
|
+
if (ba.length !== bb.length) return false;
|
|
71
|
+
return crypto.timingSafeEqual(ba, bb);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** True when the request's Content-Type media type is application/json. */
|
|
75
|
+
export function isJsonContentType(req) {
|
|
76
|
+
const ct = headerValue(req, 'content-type');
|
|
77
|
+
if (!ct) return false;
|
|
78
|
+
return ct.split(';')[0].trim().toLowerCase() === 'application/json';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const LOOPBACK_NAMES = new Set(['localhost', '127.0.0.1', '[::1]']);
|
|
82
|
+
const WILDCARD_BIND_HOSTS = new Set(['', '0.0.0.0', '::', '[::]']);
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Normalises a host name or `host[:port]` value to the lowercase hostname a
|
|
86
|
+
* WHATWG URL would report (IPv6 bracketed, trailing dot dropped), or null when
|
|
87
|
+
* it does not parse.
|
|
88
|
+
* @param {string} value
|
|
89
|
+
* @returns {string|null}
|
|
90
|
+
*/
|
|
91
|
+
export function normalizeHostName(value) {
|
|
92
|
+
let v = String(value ?? '').trim();
|
|
93
|
+
if (!v) return null;
|
|
94
|
+
// A bare IPv6 literal (bind host '::1') needs brackets to parse as a host.
|
|
95
|
+
if (!v.startsWith('[') && net.isIPv6(v)) v = `[${v}]`;
|
|
96
|
+
try {
|
|
97
|
+
const u = new URL(`http://${v}`);
|
|
98
|
+
if (u.username || u.password || (u.pathname && u.pathname !== '/') || u.search || u.hash) return null;
|
|
99
|
+
const name = u.hostname.toLowerCase().replace(/\.$/, '');
|
|
100
|
+
return name || null;
|
|
101
|
+
} catch {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Parses a comma/whitespace separated allowed-hosts list (an env var or CLI
|
|
108
|
+
* value) into normalised host names; unparseable entries are dropped.
|
|
109
|
+
* @param {string|string[]|null|undefined} value
|
|
110
|
+
* @returns {string[]}
|
|
111
|
+
*/
|
|
112
|
+
export function parseAllowedHosts(value) {
|
|
113
|
+
const parts = Array.isArray(value) ? value.flatMap((v) => String(v).split(/[\s,]+/)) : String(value ?? '').split(/[\s,]+/);
|
|
114
|
+
return parts.map(normalizeHostName).filter(Boolean);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function isIpLiteralHost(name) {
|
|
118
|
+
const bare = name.startsWith('[') && name.endsWith(']') ? name.slice(1, -1) : name;
|
|
119
|
+
return net.isIP(bare) !== 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Validates the request's Host header (DNS-rebinding defence). Applies to every
|
|
124
|
+
* method. A request with no Host header (HTTP/1.0, some raw clients) is
|
|
125
|
+
* admitted: a browser always sends one.
|
|
126
|
+
*
|
|
127
|
+
* @param {import('node:http').IncomingMessage} req
|
|
128
|
+
* @param {{ bindHost?: string|null, allowedHosts?: string[]|string|null, allowedHostsHint?: string }} [opts]
|
|
129
|
+
* `allowedHostsHint`: embedder-specific remedy text appended to the 403
|
|
130
|
+
* (e.g. the CLI flag or env var that sets `allowedHosts`); `bindHost`: the interface the server bound (admitted as a name unless it
|
|
131
|
+
* is a wildcard such as 0.0.0.0); `allowedHosts`: extra names to admit (for
|
|
132
|
+
* an off-box bind reached by DNS name).
|
|
133
|
+
* @returns {null | { status: number, error: string }}
|
|
134
|
+
*/
|
|
135
|
+
export function checkRequestHost(req, opts = {}) {
|
|
136
|
+
const raw = headerValue(req, 'host');
|
|
137
|
+
if (raw === undefined || raw.trim() === '') return null;
|
|
138
|
+
const name = normalizeHostName(raw);
|
|
139
|
+
if (name) {
|
|
140
|
+
if (LOOPBACK_NAMES.has(name) || isIpLiteralHost(name)) return null;
|
|
141
|
+
const bind = opts.bindHost ? String(opts.bindHost).trim().toLowerCase() : '';
|
|
142
|
+
if (!WILDCARD_BIND_HOSTS.has(bind) && normalizeHostName(bind) === name) return null;
|
|
143
|
+
if (parseAllowedHosts(opts.allowedHosts).includes(name)) return null;
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
status: 403,
|
|
147
|
+
error: `request refused: Host '${raw}' is not a name this server answers to (possible DNS rebinding); add it to the server's allowed hosts if it is legitimate${opts.allowedHostsHint ? ` (${opts.allowedHostsHint})` : ''}`,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Decides whether a request may reach a mutating route. Also runs
|
|
153
|
+
* checkRequestHost() first, so a rebound page whose Origin and Host agree on a
|
|
154
|
+
* foreign name is refused.
|
|
155
|
+
*
|
|
156
|
+
* @param {import('node:http').IncomingMessage} req
|
|
157
|
+
* @param {{ token?: string|null, bindHost?: string|null, allowedHosts?: string[]|string|null }} [opts] -
|
|
158
|
+
* `token`: the accepted token, or empty/absent when no token mechanism is
|
|
159
|
+
* configured (then only same-origin requests pass); `bindHost` and
|
|
160
|
+
* `allowedHosts`: see checkRequestHost().
|
|
161
|
+
* @returns {null | { status: number, error: string }} null when allowed, else
|
|
162
|
+
* the status and message to answer with.
|
|
163
|
+
*/
|
|
164
|
+
export function checkMutatingRequest(req, opts = {}) {
|
|
165
|
+
const method = String((req && req.method) || 'GET').toUpperCase();
|
|
166
|
+
if (SAFE_METHODS.has(method)) return null;
|
|
167
|
+
|
|
168
|
+
const badHost = checkRequestHost(req, opts);
|
|
169
|
+
if (badHost) return badHost;
|
|
170
|
+
|
|
171
|
+
if (!isJsonContentType(req)) {
|
|
172
|
+
return {
|
|
173
|
+
status: 415,
|
|
174
|
+
error: `${method} requests must send Content-Type: application/json (form, multipart and text/plain bodies are refused); set that header and send a JSON body`,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const configured = typeof opts.token === 'string' && opts.token.length > 0 ? opts.token : null;
|
|
179
|
+
const presented = presentedToken(req);
|
|
180
|
+
if (presented !== undefined) {
|
|
181
|
+
if (configured && tokensEqual(presented, configured)) return null;
|
|
182
|
+
if (!configured) {
|
|
183
|
+
// Never blame the token: this server simply has no token mechanism.
|
|
184
|
+
return {
|
|
185
|
+
status: 403,
|
|
186
|
+
error: 'this server accepts no token (it takes same-origin requests only, or requests forwarded by its parent proxy); drop the Authorization / X-Fleet-Token header and resend the request without it',
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
return { status: 403, error: 'invalid token' };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const fetchSite = (headerValue(req, 'sec-fetch-site') || '').trim().toLowerCase();
|
|
193
|
+
if (fetchSite === 'cross-site' || fetchSite === 'same-site') {
|
|
194
|
+
return { status: 403, error: `cross-site request refused (Sec-Fetch-Site: ${fetchSite})` };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const origin = headerValue(req, 'origin');
|
|
198
|
+
if (origin !== undefined) {
|
|
199
|
+
const host = (headerValue(req, 'host') || '').trim().toLowerCase();
|
|
200
|
+
let originHost = null;
|
|
201
|
+
try {
|
|
202
|
+
const u = new URL(origin);
|
|
203
|
+
if (u.protocol === 'http:' || u.protocol === 'https:') originHost = u.host.toLowerCase();
|
|
204
|
+
} catch { /* 'null' or malformed -- refused below */ }
|
|
205
|
+
if (!originHost || !host || originHost !== host) {
|
|
206
|
+
return { status: 403, error: `cross-site request refused (Origin ${origin} is not this server's origin)` };
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Header names a same-host proxy must drop when forwarding a request it has
|
|
214
|
+
* already admitted with checkMutatingRequest(): the browser's Origin and fetch
|
|
215
|
+
* metadata describe the PROXY's origin, which the upstream (a different port)
|
|
216
|
+
* would otherwise read as cross-site, and the proxy's own token means nothing
|
|
217
|
+
* upstream (a presented-but-unknown token is refused there).
|
|
218
|
+
*/
|
|
219
|
+
export const ADMITTED_REQUEST_STRIP_HEADERS = Object.freeze([
|
|
220
|
+
'origin', 'referer', 'sec-fetch-site', 'sec-fetch-mode', 'sec-fetch-dest', 'sec-fetch-user',
|
|
221
|
+
'authorization', TOKEN_HEADER,
|
|
222
|
+
]);
|
|
@@ -414,6 +414,15 @@ function buildRepairPrompt(errorsText, initialPrompt) {
|
|
|
414
414
|
* return type. `CancelledError` (cooperative `requestStop()`) is never
|
|
415
415
|
* soft-caught -- it always throws, regardless of this option.
|
|
416
416
|
* (apra-fleet-unw.17)
|
|
417
|
+
* @property {boolean} [pauseExempt] - When true, the call skips the
|
|
418
|
+
* cooperative pause gate: it runs even while the run is paused, and it is
|
|
419
|
+
* not counted as an in-flight activity, so it neither blocks behind a pause
|
|
420
|
+
* nor holds one back from engaging. It is not journaled for replay either
|
|
421
|
+
* (no sequence number is consumed), so a resumed run's replay order does
|
|
422
|
+
* not depend on how many such calls ran. Meant for short, read-only probes
|
|
423
|
+
* a paused script issues while it waits on an external condition. A
|
|
424
|
+
* requestStop() still cancels it (the run's stop signal is passed through
|
|
425
|
+
* as for any command).
|
|
417
426
|
*/
|
|
418
427
|
|
|
419
428
|
export class FleetWorkflow extends EventEmitter {
|
|
@@ -1566,6 +1575,18 @@ export class FleetWorkflow extends EventEmitter {
|
|
|
1566
1575
|
if (!opts.member_name && !opts.member_id) {
|
|
1567
1576
|
throw new Error(`[Workflow Error] command() requires either member_name or member_id`);
|
|
1568
1577
|
}
|
|
1578
|
+
// opts.pauseExempt (see CommandOptions): no gate, no in-flight
|
|
1579
|
+
// bookkeeping -- a read-only probe a paused script issues while it
|
|
1580
|
+
// waits. A stop still cancels it through the run's stop signal.
|
|
1581
|
+
if (opts.pauseExempt) {
|
|
1582
|
+
const signal = opts.signal ?? this._currentSignal();
|
|
1583
|
+
if (signal && signal.aborted) {
|
|
1584
|
+
throw signal.reason instanceof CancelledError
|
|
1585
|
+
? signal.reason
|
|
1586
|
+
: new CancelledError('[Workflow Error] command() not started: the run was stopped');
|
|
1587
|
+
}
|
|
1588
|
+
return this._commandDispatch(cmd, opts);
|
|
1589
|
+
}
|
|
1569
1590
|
await this._pauseGate();
|
|
1570
1591
|
this._enterActivity();
|
|
1571
1592
|
try {
|
|
@@ -1623,7 +1644,9 @@ export class FleetWorkflow extends EventEmitter {
|
|
|
1623
1644
|
const store = this._store();
|
|
1624
1645
|
let sequence = null;
|
|
1625
1646
|
let replayKey = null;
|
|
1626
|
-
|
|
1647
|
+
// A pause-exempt call is never journaled for replay (see
|
|
1648
|
+
// CommandOptions.pauseExempt): it takes no sequence number.
|
|
1649
|
+
if (store && store.activitySeq && !opts.pauseExempt) {
|
|
1627
1650
|
// (apra-fleet-unw2.14, N6) See agent()/_nextSequence(): numeric at
|
|
1628
1651
|
// the top level, hierarchical/order-independent inside parallel().
|
|
1629
1652
|
sequence = this._nextSequence(store);
|
|
@@ -2099,7 +2122,16 @@ export class FleetWorkflow extends EventEmitter {
|
|
|
2099
2122
|
// one. requestStop() remains instance-only/operator-only -- a
|
|
2100
2123
|
// script has no business tearing down its own run.
|
|
2101
2124
|
requestPause: this.requestPause.bind(this),
|
|
2102
|
-
requestResume: this.requestResume.bind(this)
|
|
2125
|
+
requestResume: this.requestResume.bind(this),
|
|
2126
|
+
// Script-facing, read-only view of the active run's cooperative
|
|
2127
|
+
// cancellation: the AbortSignal requestStop() aborts (its reason
|
|
2128
|
+
// is the CancelledError), or undefined outside a runWithContext()
|
|
2129
|
+
// run. Lets a script that waits on a timer -- with no
|
|
2130
|
+
// agent()/command() blocked at the pause gate -- still see an
|
|
2131
|
+
// operator stop at once, and avoid re-pausing after one (a pause
|
|
2132
|
+
// requested after requestStop() would block the next dispatch at
|
|
2133
|
+
// the gate with nothing left to release it).
|
|
2134
|
+
stopSignal: () => this._currentSignal()
|
|
2103
2135
|
};
|
|
2104
2136
|
}
|
|
2105
2137
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "modules": ["./register.tsx"] }
|