@rocket.chat/houston 0.27.0-next.3 → 2.1.8
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/LICENSE +1 -1
- package/README.md +108 -15
- package/bin/houston +62 -0
- package/data/docs/ARCHITECTURE.md +387 -0
- package/data/docs/automation.md +107 -0
- package/data/docs/e2ee.md +76 -0
- package/data/docs/eks.md +258 -0
- package/data/docs/gui.md +282 -0
- package/data/docs/guide.md +669 -0
- package/data/docs/kubernetes.md +138 -0
- package/data/docs/troubleshooting.md +193 -0
- package/data/docs/upgrading.md +84 -0
- package/data/docs/voice.md +253 -0
- package/data/iam/engineer-policy.json +11 -0
- package/data/iam/engineer-rbac.yaml +42 -0
- package/data/iam/operator-policy.json +211 -0
- package/data/loadtest/badbot.js +22 -0
- package/data/loadtest/common.js +168 -0
- package/data/loadtest/custom.js +20 -0
- package/data/loadtest/journey.js +58 -0
- package/data/loadtest/login.js +18 -0
- package/data/loadtest/messages.js +13 -0
- package/data/loadtest/mixed.js +39 -0
- package/data/loadtest/read.js +12 -0
- package/data/loadtest/webhook.js +20 -0
- package/data/monitoring/houston-logs.json +98 -0
- package/data/monitoring/k6-loadtest.json +610 -0
- package/data/monitoring/mongodb-exporter.json +3007 -0
- package/data/monitoring/node-exporter-full.json +16114 -0
- package/data/monitoring/rocketchat-metrics.json +6471 -0
- package/data/presets/airgapped.yaml +16 -0
- package/data/presets/default.yaml +9 -0
- package/data/seed/avatar-0.png +0 -0
- package/data/seed/avatar-1.png +0 -0
- package/data/seed/avatar-2.png +0 -0
- package/data/seed/avatar-3.png +0 -0
- package/data/seed/avatar-4.png +0 -0
- package/data/seed/avatar-5.png +0 -0
- package/data/seed/avatar-6.png +0 -0
- package/data/seed/avatar-7.png +0 -0
- package/data/seed/seed-metrics.csv +3 -0
- package/data/seed/seed-preview.png +0 -0
- package/data/seed/seed-report.pdf +32 -0
- package/data/seed/seed-runbook.txt +3 -0
- package/data/skill/SKILL.md +399 -0
- package/data/versions.yaml +55 -0
- package/data/voice/freeswitch/drachtio.xml +52 -0
- package/data/voice/freeswitch/public.xml +87 -0
- package/data/webui/app.css +2003 -0
- package/data/webui/index.html +678 -0
- package/data/webui/js/api.js +561 -0
- package/data/webui/js/boot.js +44 -0
- package/data/webui/js/clusters-tail.js +1377 -0
- package/data/webui/js/clusters.js +896 -0
- package/data/webui/js/create.js +276 -0
- package/data/webui/js/detail.js +507 -0
- package/data/webui/js/jobs.js +636 -0
- package/data/webui/js/logs.js +634 -0
- package/data/webui/js/main.js +14 -0
- package/data/webui/js/options.js +408 -0
- package/data/webui/js/people.js +438 -0
- package/data/webui/js/perf.js +303 -0
- package/data/webui/js/render.js +438 -0
- package/data/webui/js/shared.js +3 -0
- package/data/webui/js/state.js +583 -0
- package/data/webui/js/theme.js +123 -0
- package/data/webui/js/util.js +584 -0
- package/dist/cli/app.js +593 -0
- package/dist/cli/capabilities.js +76 -0
- package/dist/cli/cell-widths.js +495 -0
- package/dist/cli/entry.js +10 -0
- package/dist/cli/error-panel.js +492 -0
- package/dist/cli/handlers/actor.js +84 -0
- package/dist/cli/handlers/https.js +614 -0
- package/dist/cli/handlers/prompt.js +299 -0
- package/dist/cli/handlers/users.js +226 -0
- package/dist/cli/handlers.js +3678 -0
- package/dist/cli/help.js +183 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/perf.js +810 -0
- package/dist/cli/render.js +254 -0
- package/dist/cli/serve.js +858 -0
- package/dist/cli/spec-data.js +2593 -0
- package/dist/cli/spec-types.js +8 -0
- package/dist/cli/usage-error.js +520 -0
- package/dist/cli/wire.js +70 -0
- package/dist/core/audit.js +346 -0
- package/dist/core/backup-compat.js +85 -0
- package/dist/core/backup.js +1639 -0
- package/dist/core/cluster.js +1398 -0
- package/dist/core/configimport.js +344 -0
- package/dist/core/data.js +267 -0
- package/dist/core/database-of.js +82 -0
- package/dist/core/diagnose.js +159 -0
- package/dist/core/doctor.js +1518 -0
- package/dist/core/edge/acme.js +338 -0
- package/dist/core/edge/engine.js +500 -0
- package/dist/core/edge/networks.js +174 -0
- package/dist/core/edge/paths.js +107 -0
- package/dist/core/edge/routes.js +251 -0
- package/dist/core/edge/routeyml.js +195 -0
- package/dist/core/edge/runtime.js +493 -0
- package/dist/core/edge/spec.js +305 -0
- package/dist/core/edge/types.js +202 -0
- package/dist/core/eks-docs.js +135 -0
- package/dist/core/eks.js +2240 -0
- package/dist/core/envvars.js +562 -0
- package/dist/core/eventlog.js +541 -0
- package/dist/core/firstrun.js +153 -0
- package/dist/core/journal.js +691 -0
- package/dist/core/kube/ask.js +231 -0
- package/dist/core/kube/capabilities.js +269 -0
- package/dist/core/kube/certmanager.js +452 -0
- package/dist/core/kube/chart.js +413 -0
- package/dist/core/kube/cluster.js +196 -0
- package/dist/core/kube/context.js +545 -0
- package/dist/core/kube/endpoints.js +448 -0
- package/dist/core/kube/exec.js +195 -0
- package/dist/core/kube/forward.js +732 -0
- package/dist/core/kube/grafana-ingress.js +110 -0
- package/dist/core/kube/ingress.js +218 -0
- package/dist/core/kube/manifests.js +361 -0
- package/dist/core/kube/monitoring.js +768 -0
- package/dist/core/kube/names.js +237 -0
- package/dist/core/kube/namespace.js +678 -0
- package/dist/core/kube/operator.js +941 -0
- package/dist/core/kube/probe.js +202 -0
- package/dist/core/kube/reachability.js +163 -0
- package/dist/core/kube/release.js +439 -0
- package/dist/core/kube/replicaset.js +180 -0
- package/dist/core/kube/scale.js +398 -0
- package/dist/core/kube/status.js +633 -0
- package/dist/core/kube/tools.js +238 -0
- package/dist/core/kube/transfer.js +173 -0
- package/dist/core/kube/workspace.js +423 -0
- package/dist/core/lifecycle/admin.js +64 -0
- package/dist/core/lifecycle/create-docker.js +1533 -0
- package/dist/core/lifecycle/create-k8s.js +939 -0
- package/dist/core/lifecycle/destroy.js +339 -0
- package/dist/core/lifecycle/inspect.js +635 -0
- package/dist/core/lifecycle/naming.js +298 -0
- package/dist/core/lifecycle/notes.js +726 -0
- package/dist/core/lifecycle/ownership.js +313 -0
- package/dist/core/lifecycle/payload.js +401 -0
- package/dist/core/lifecycle/ports.js +388 -0
- package/dist/core/lifecycle/preconditions.js +367 -0
- package/dist/core/lifecycle/pruning.js +551 -0
- package/dist/core/lifecycle/ready.js +753 -0
- package/dist/core/lifecycle/request.js +525 -0
- package/dist/core/lifecycle/seeding.js +281 -0
- package/dist/core/lifecycle/sizing.js +392 -0
- package/dist/core/lifecycle/state.js +286 -0
- package/dist/core/lifecycle/tlsplan.js +704 -0
- package/dist/core/lifecycle/types.js +232 -0
- package/dist/core/loadtest.js +995 -0
- package/dist/core/migrate.js +612 -0
- package/dist/core/monitor.js +494 -0
- package/dist/core/postready.js +969 -0
- package/dist/core/promote.js +804 -0
- package/dist/core/rcapi.js +1285 -0
- package/dist/core/recovery.js +75 -0
- package/dist/core/runner/engine.js +394 -0
- package/dist/core/runner/host.js +298 -0
- package/dist/core/runner/locks.js +129 -0
- package/dist/core/runner/paths.js +173 -0
- package/dist/core/runner/ports.js +172 -0
- package/dist/core/runner/queries.js +612 -0
- package/dist/core/runner/record.js +563 -0
- package/dist/core/scaleseed.js +271 -0
- package/dist/core/seed-db.js +208 -0
- package/dist/core/sessions.js +472 -0
- package/dist/core/skill.js +326 -0
- package/dist/core/sso-identities.js +172 -0
- package/dist/core/sso.js +703 -0
- package/dist/core/tls-local.js +311 -0
- package/dist/core/tls.js +878 -0
- package/dist/core/topology.js +482 -0
- package/dist/core/upgrade.js +868 -0
- package/dist/core/users.js +739 -0
- package/dist/lib/audit.js +100 -0
- package/dist/lib/close-matches.js +238 -0
- package/dist/lib/compose.js +672 -0
- package/dist/lib/config.js +1398 -0
- package/dist/lib/context.js +18 -0
- package/dist/lib/errors.js +305 -0
- package/dist/lib/events.js +208 -0
- package/dist/lib/float-text.js +126 -0
- package/dist/lib/format.js +1320 -0
- package/dist/lib/home.js +325 -0
- package/dist/lib/journal.js +122 -0
- package/dist/lib/json-text.js +733 -0
- package/dist/lib/jsonout.js +382 -0
- package/dist/lib/lock.js +516 -0
- package/dist/lib/login-name.js +202 -0
- package/dist/lib/map-limit.js +29 -0
- package/dist/lib/mkdir-parents.js +90 -0
- package/dist/lib/mongo-kernel.js +67 -0
- package/dist/lib/monitoring.js +492 -0
- package/dist/lib/platform-name.js +59 -0
- package/dist/lib/presets/common.js +390 -0
- package/dist/lib/presets/composite.js +326 -0
- package/dist/lib/presets/e2ee.js +143 -0
- package/dist/lib/presets/email.js +172 -0
- package/dist/lib/presets/guides.js +27 -0
- package/dist/lib/presets/index.js +490 -0
- package/dist/lib/presets/keycloak.js +369 -0
- package/dist/lib/presets/ldap.js +1285 -0
- package/dist/lib/presets/livechat.js +220 -0
- package/dist/lib/presets/multi-instance.js +124 -0
- package/dist/lib/presets/oidc.js +161 -0
- package/dist/lib/presets/public.js +496 -0
- package/dist/lib/presets/registry.js +64 -0
- package/dist/lib/presets/s3-minio.js +300 -0
- package/dist/lib/presets/saml.js +149 -0
- package/dist/lib/presets/scenario.js +51 -0
- package/dist/lib/presets/types.js +86 -0
- package/dist/lib/presets/voice-pbx.js +320 -0
- package/dist/lib/presets/voice.js +345 -0
- package/dist/lib/presets/webhooks.js +182 -0
- package/dist/lib/redact.js +106 -0
- package/dist/lib/seed-options.js +68 -0
- package/dist/lib/seed-profiles.js +59 -0
- package/dist/lib/targz.js +1383 -0
- package/dist/lib/teammode.js +25 -0
- package/dist/lib/tempdir.js +162 -0
- package/dist/lib/unicode-tables.js +2335 -0
- package/dist/lib/version-spec.js +357 -0
- package/dist/lib/versions.js +463 -0
- package/dist/lib/yaml-dump.js +1361 -0
- package/dist/perf/baseline.js +168 -0
- package/dist/perf/constrain.js +296 -0
- package/dist/perf/k6.js +235 -0
- package/dist/perf/mongoprof.js +171 -0
- package/dist/perf/rcmetrics.js +178 -0
- package/dist/perf/report.js +386 -0
- package/dist/perf/resources.js +224 -0
- package/dist/perf/slo.js +111 -0
- package/dist/perf/timeline.js +187 -0
- package/dist/perf/timings.js +85 -0
- package/dist/perf/verdict.js +201 -0
- package/dist/seams/aws-cli.js +126 -0
- package/dist/seams/docker-cli.js +280 -0
- package/dist/seams/exec.js +861 -0
- package/dist/seams/fs/lock.js +528 -0
- package/dist/seams/kubectl.js +83 -0
- package/dist/seams/rc-http.js +921 -0
- package/dist/seed/apply.js +190 -0
- package/dist/seed/assets.js +76 -0
- package/dist/seed/check.js +391 -0
- package/dist/seed/client.js +172 -0
- package/dist/seed/executor.js +726 -0
- package/dist/seed/history.js +281 -0
- package/dist/seed/kinds.js +91 -0
- package/dist/seed/plan.js +432 -0
- package/dist/seed/receipt.js +339 -0
- package/dist/seed/repairs.js +75 -0
- package/dist/seed/verification.js +363 -0
- package/dist/seed/wording.js +248 -0
- package/dist/web/app.js +326 -0
- package/dist/web/jobs.js +510 -0
- package/dist/web/route-deps.js +211 -0
- package/dist/web/route-table.js +213 -0
- package/dist/web/routes/backup.js +244 -0
- package/dist/web/routes/clusters.js +303 -0
- package/dist/web/routes/data.js +187 -0
- package/dist/web/routes/edge.js +82 -0
- package/dist/web/routes/index.js +63 -0
- package/dist/web/routes/jobs.js +95 -0
- package/dist/web/routes/logs.js +297 -0
- package/dist/web/routes/meta.js +191 -0
- package/dist/web/routes/people.js +151 -0
- package/dist/web/routes/perf.js +95 -0
- package/dist/web/routes/repros.js +550 -0
- package/dist/web/routes/session.js +361 -0
- package/dist/web/routes/spa.js +198 -0
- package/dist/web/security.js +475 -0
- package/dist/web/signin.js +246 -0
- package/package.json +67 -32
- package/.eslintrc +0 -94
- package/.swcrc +0 -18
- package/dist/bin.js +0 -3
- package/dist/cli.js +0 -184
- package/dist/commands/createBranch.js +0 -194
- package/dist/outputCI.js +0 -59
- package/src/bin.js +0 -4
- package/src/cli.ts +0 -25
- package/src/commands/createBranch.ts +0 -28
- package/src/outputCI.ts +0 -12
- package/src-old/logs.js +0 -323
- package/src-old/md.js +0 -191
- package/src-old/release-table.js +0 -60
- package/src-old/set-version.js +0 -614
- package/src-old/utils.js +0 -15
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The guard chain: what a request must prove before a handler ever sees it.
|
|
4
|
+
*
|
|
5
|
+
* Fastify's named lifecycle is the security boundary. `onRequest` rejects an invalid
|
|
6
|
+
* Host or cross-site request before credentials are read; `preHandler` verifies the
|
|
7
|
+
* session, applies the injected default-deny role resolver and establishes request
|
|
8
|
+
* attribution; `onSend` puts the security headers on every answer, including early
|
|
9
|
+
* refusals. The order is explicit rather than dependent on middleware registration
|
|
10
|
+
* conventions.
|
|
11
|
+
*
|
|
12
|
+
* The role table deliberately remains in the web layer, but its rows are not in this
|
|
13
|
+
* module. The routes inject the resolver that translates Fastify's `:name` templates to
|
|
14
|
+
* the table's `{name}` keys.
|
|
15
|
+
*/
|
|
16
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
19
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
20
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
21
|
+
}
|
|
22
|
+
Object.defineProperty(o, k2, desc);
|
|
23
|
+
}) : (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
}));
|
|
27
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
+
}) : function(o, v) {
|
|
30
|
+
o["default"] = v;
|
|
31
|
+
});
|
|
32
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
33
|
+
var ownKeys = function(o) {
|
|
34
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
35
|
+
var ar = [];
|
|
36
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
37
|
+
return ar;
|
|
38
|
+
};
|
|
39
|
+
return ownKeys(o);
|
|
40
|
+
};
|
|
41
|
+
return function (mod) {
|
|
42
|
+
if (mod && mod.__esModule) return mod;
|
|
43
|
+
var result = {};
|
|
44
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
45
|
+
__setModuleDefault(result, mod);
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
})();
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.SSO_MAX_STARTS = exports.PREAUTH_AUDIT_WINDOW = exports.SIGNIN_MAX_KEYS = exports.SIGNIN_WINDOW = exports.SIGNIN_MAX_FAILURES = exports.COOKIE_PLAIN = exports.COOKIE_SECURE = void 0;
|
|
51
|
+
exports.workspaceRefusal = workspaceRefusal;
|
|
52
|
+
exports.hostname = hostname;
|
|
53
|
+
exports.hostOk = hostOk;
|
|
54
|
+
exports.originOk = originOk;
|
|
55
|
+
exports.crossSite = crossSite;
|
|
56
|
+
exports.rightmostUntrusted = rightmostUntrusted;
|
|
57
|
+
exports.resolvePeer = resolvePeer;
|
|
58
|
+
exports.cookieName = cookieName;
|
|
59
|
+
exports.setSessionCookie = setSessionCookie;
|
|
60
|
+
exports.clearSessionCookie = clearSessionCookie;
|
|
61
|
+
exports.sessionToken = sessionToken;
|
|
62
|
+
exports.preauthShouldAudit = preauthShouldAudit;
|
|
63
|
+
exports.signinRetryAfter = signinRetryAfter;
|
|
64
|
+
exports.signinFailed = signinFailed;
|
|
65
|
+
exports.signinOk = signinOk;
|
|
66
|
+
exports.ssoStartAllowed = ssoStartAllowed;
|
|
67
|
+
exports.doSignin = doSignin;
|
|
68
|
+
exports.signinNext = signinNext;
|
|
69
|
+
exports.installSecurity = installSecurity;
|
|
70
|
+
const node_perf_hooks_1 = require("node:perf_hooks");
|
|
71
|
+
const auditService = __importStar(require("../core/audit"));
|
|
72
|
+
const sessions = __importStar(require("../core/sessions"));
|
|
73
|
+
const context_1 = require("../lib/context");
|
|
74
|
+
const errors_1 = require("../lib/errors");
|
|
75
|
+
const format_1 = require("../lib/format");
|
|
76
|
+
exports.COOKIE_SECURE = '__Host-houston_session';
|
|
77
|
+
exports.COOKIE_PLAIN = 'houston_session';
|
|
78
|
+
exports.SIGNIN_MAX_FAILURES = 10;
|
|
79
|
+
exports.SIGNIN_WINDOW = 60;
|
|
80
|
+
exports.SIGNIN_MAX_KEYS = 4096;
|
|
81
|
+
exports.PREAUTH_AUDIT_WINDOW = 60;
|
|
82
|
+
const signinFailures = new Map();
|
|
83
|
+
const preauthSeen = new Map();
|
|
84
|
+
const DEFAULT_DEPENDENCIES = {
|
|
85
|
+
verifySession: sessions.verify,
|
|
86
|
+
roleOf: (name) => usersModule().roleOf(name),
|
|
87
|
+
atLeast: (role, needed) => usersModule().atLeast(role, needed),
|
|
88
|
+
audit: auditService.audit,
|
|
89
|
+
workspaceRefusal,
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* '' when `actor` may change the workspace `name` resolves to, else the refusal. A name that
|
|
93
|
+
* resolves to nothing is the route's to answer (404, or 400 for a bad one), not this gate's.
|
|
94
|
+
*/
|
|
95
|
+
async function workspaceRefusal(name, actor) {
|
|
96
|
+
const naming = require('../core/lifecycle/naming');
|
|
97
|
+
const ownership = require('../core/lifecycle/ownership');
|
|
98
|
+
let target;
|
|
99
|
+
try {
|
|
100
|
+
target = await naming.resolveName(name);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return '';
|
|
104
|
+
}
|
|
105
|
+
const [allowed, why] = await ownership.mayChange(target, actor);
|
|
106
|
+
return allowed ? '' : why;
|
|
107
|
+
}
|
|
108
|
+
function usersModule() {
|
|
109
|
+
// Resolved at call time, not at load, so that seam stays available.
|
|
110
|
+
return require('../core/users');
|
|
111
|
+
}
|
|
112
|
+
function headerText(value) {
|
|
113
|
+
return Array.isArray(value) ? (value[0] ?? '') : (value ?? '');
|
|
114
|
+
}
|
|
115
|
+
function hostname(header) {
|
|
116
|
+
const value = (0, format_1.stripText)(header ?? '');
|
|
117
|
+
if (value.startsWith('['))
|
|
118
|
+
return (value.slice(1).split(']', 1)[0] ?? '').toLowerCase();
|
|
119
|
+
return (value.split(':', 1)[0] ?? '').toLowerCase();
|
|
120
|
+
}
|
|
121
|
+
function hostOk(context, header) {
|
|
122
|
+
return context.anyHost || context.allowed.has(hostname(header));
|
|
123
|
+
}
|
|
124
|
+
/** The names every local port answers to, which an allow-list entry cannot vouch for. */
|
|
125
|
+
const LOOPBACK_NAMES = new Set(['localhost', '127.0.0.1', '::1']);
|
|
126
|
+
/**
|
|
127
|
+
* Whether an Origin authority (`host[:port]`, scheme removed) is this server's own.
|
|
128
|
+
*
|
|
129
|
+
* Its own host is compared WITH its port: `localhost:9999` is another server on this
|
|
130
|
+
* machine -- a workspace's Rocket.Chat, say -- and a hostname-only comparison let it through
|
|
131
|
+
* whenever a browser sent no `Sec-Fetch-Site`. A host the operator named with `--allow-host`
|
|
132
|
+
* still matches by name, because a proxy that rewrote Host left no port to compare; the
|
|
133
|
+
* loopback names are not trusted that way. The scheme is not compared: one port answers one
|
|
134
|
+
* scheme, and behind a proxy this server cannot know which the browser used.
|
|
135
|
+
*/
|
|
136
|
+
function originOk(context, header, hostHeader = '') {
|
|
137
|
+
const originHost = hostname(header);
|
|
138
|
+
if (!originHost)
|
|
139
|
+
return false;
|
|
140
|
+
if (originHost === hostname(hostHeader)) {
|
|
141
|
+
return (0, format_1.stripText)(header ?? '').toLowerCase() === (0, format_1.stripText)(hostHeader ?? '').toLowerCase();
|
|
142
|
+
}
|
|
143
|
+
return context.allowed.has(originHost) && !LOOPBACK_NAMES.has(originHost);
|
|
144
|
+
}
|
|
145
|
+
function crossSite(context, headers, { requireOrigin = false } = {}) {
|
|
146
|
+
const site = headerText(headers['sec-fetch-site']);
|
|
147
|
+
if (site)
|
|
148
|
+
return site !== 'same-origin' && site !== 'none';
|
|
149
|
+
const origin = headerText(headers.origin);
|
|
150
|
+
if (origin) {
|
|
151
|
+
if (origin === 'null')
|
|
152
|
+
return true;
|
|
153
|
+
const marker = origin.indexOf('://');
|
|
154
|
+
const originAuthority = marker === -1 ? origin : origin.slice(marker + 3);
|
|
155
|
+
return !originOk(context, originAuthority, headerText(headers.host));
|
|
156
|
+
}
|
|
157
|
+
return requireOrigin;
|
|
158
|
+
}
|
|
159
|
+
function isTrusted(context, address) {
|
|
160
|
+
return context.trustedProxies.some((network) => network.contains(address));
|
|
161
|
+
}
|
|
162
|
+
function rightmostUntrusted(forwarded, trusted) {
|
|
163
|
+
const hops = forwarded.split(',').map(format_1.stripText).filter(Boolean);
|
|
164
|
+
for (let index = hops.length - 1; index >= 0; index -= 1) {
|
|
165
|
+
const hop = hops[index] ?? '';
|
|
166
|
+
if (!trusted.some((network) => network.contains(hop)))
|
|
167
|
+
return hop;
|
|
168
|
+
}
|
|
169
|
+
return '';
|
|
170
|
+
}
|
|
171
|
+
function resolvePeer(context, request) {
|
|
172
|
+
let address = request.raw.socket.remoteAddress ?? request.ip;
|
|
173
|
+
let https = Boolean(context.publicHttps());
|
|
174
|
+
if (context.trustedProxies.length > 0 && address && isTrusted(context, address)) {
|
|
175
|
+
const forwarded = headerText(request.headers['x-forwarded-for']);
|
|
176
|
+
if (forwarded)
|
|
177
|
+
address = rightmostUntrusted(forwarded, context.trustedProxies) || address;
|
|
178
|
+
const protocol = headerText(request.headers['x-forwarded-proto']);
|
|
179
|
+
if (protocol)
|
|
180
|
+
https = (0, format_1.stripText)(protocol.split(',', 1)[0] ?? '').toLowerCase() === 'https';
|
|
181
|
+
}
|
|
182
|
+
return { address, https };
|
|
183
|
+
}
|
|
184
|
+
function cookieName(context, https) {
|
|
185
|
+
return https ? context.cookieSecure : context.cookiePlain;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The Set-Cookie line in its established spelling: attributes in sorted key order
|
|
189
|
+
* (expires, httponly, max-age, path, samesite, secure), the
|
|
190
|
+
* flags by their reserved names, and `SameSite=lax` as the value was given.
|
|
191
|
+
*/
|
|
192
|
+
function sessionCookie(name, token, maxAge, secure) {
|
|
193
|
+
return (`${name}=${token}; HttpOnly; Max-Age=${maxAge}; Path=/; SameSite=lax` +
|
|
194
|
+
(secure ? '; Secure' : ''));
|
|
195
|
+
}
|
|
196
|
+
/** Mint the one browser credential with the prefix and Secure flag for its real hop. */
|
|
197
|
+
function setSessionCookie(context, reply, token, https = context.publicHttps()) {
|
|
198
|
+
reply.header('Set-Cookie', sessionCookie(cookieName(context, https), token, sessions.ABSOLUTE_SECONDS, https));
|
|
199
|
+
}
|
|
200
|
+
/** Expire both names so switching between HTTP and HTTPS cannot strand a credential. */
|
|
201
|
+
function clearSessionCookie(context, reply) {
|
|
202
|
+
// Deleted as the established server deletes a cookie: an empty value, quoted as `""`, and
|
|
203
|
+
// an expiry of NOW, not the epoch.
|
|
204
|
+
const now = new Date().toUTCString();
|
|
205
|
+
const expired = (name) => `${name}=""; expires=${now}; Max-Age=0; Path=/; SameSite=lax`;
|
|
206
|
+
reply.header('Set-Cookie', [expired(context.cookieSecure), expired(context.cookiePlain)]);
|
|
207
|
+
}
|
|
208
|
+
function cookieValue(header, name) {
|
|
209
|
+
for (const item of header.split(';')) {
|
|
210
|
+
const part = (0, format_1.stripText)(item);
|
|
211
|
+
const separator = part.indexOf('=');
|
|
212
|
+
if (separator !== -1 && part.slice(0, separator) === name)
|
|
213
|
+
return part.slice(separator + 1);
|
|
214
|
+
}
|
|
215
|
+
return '';
|
|
216
|
+
}
|
|
217
|
+
function sessionToken(context, request) {
|
|
218
|
+
const peer = resolvePeer(context, request);
|
|
219
|
+
return cookieValue(headerText(request.headers.cookie), cookieName(context, peer.https));
|
|
220
|
+
}
|
|
221
|
+
function monotonicSeconds() {
|
|
222
|
+
return node_perf_hooks_1.performance.now() / 1000;
|
|
223
|
+
}
|
|
224
|
+
function preauthShouldAudit(source, why) {
|
|
225
|
+
const now = monotonicSeconds();
|
|
226
|
+
const key = `${source}\0${why}`;
|
|
227
|
+
const last = preauthSeen.get(key) ?? 0;
|
|
228
|
+
if (last && now - last < exports.PREAUTH_AUDIT_WINDOW)
|
|
229
|
+
return false;
|
|
230
|
+
if (preauthSeen.size > exports.SIGNIN_MAX_KEYS) {
|
|
231
|
+
for (const [candidate, seen] of preauthSeen) {
|
|
232
|
+
if (now - seen > exports.PREAUTH_AUDIT_WINDOW)
|
|
233
|
+
preauthSeen.delete(candidate);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
preauthSeen.set(key, now);
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
function signinRetryAfter(source) {
|
|
240
|
+
const now = monotonicSeconds();
|
|
241
|
+
const hits = (signinFailures.get(source) ?? []).filter((stamp) => now - stamp < exports.SIGNIN_WINDOW);
|
|
242
|
+
signinFailures.set(source, hits);
|
|
243
|
+
if (hits.length < exports.SIGNIN_MAX_FAILURES)
|
|
244
|
+
return 0;
|
|
245
|
+
return Math.max(1, Math.trunc(exports.SIGNIN_WINDOW - (now - (hits[0] ?? now))) + 1);
|
|
246
|
+
}
|
|
247
|
+
function signinFailed(source) {
|
|
248
|
+
const now = monotonicSeconds();
|
|
249
|
+
if (signinFailures.size > exports.SIGNIN_MAX_KEYS) {
|
|
250
|
+
for (const [address, hits] of signinFailures) {
|
|
251
|
+
const newest = hits.at(-1);
|
|
252
|
+
if (newest === undefined || now - newest > exports.SIGNIN_WINDOW)
|
|
253
|
+
signinFailures.delete(address);
|
|
254
|
+
}
|
|
255
|
+
if (signinFailures.size > exports.SIGNIN_MAX_KEYS) {
|
|
256
|
+
const oldest = [...signinFailures.entries()].sort(([, left], [, right]) => (left.at(-1) ?? 0) - (right.at(-1) ?? 0));
|
|
257
|
+
const remove = signinFailures.size - Math.floor(exports.SIGNIN_MAX_KEYS / 2);
|
|
258
|
+
for (const [address] of oldest.slice(0, remove))
|
|
259
|
+
signinFailures.delete(address);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const hits = signinFailures.get(source) ?? [];
|
|
263
|
+
hits.push(now);
|
|
264
|
+
signinFailures.set(source, hits);
|
|
265
|
+
}
|
|
266
|
+
function signinOk(source) {
|
|
267
|
+
const seen = signinFailures.get(source);
|
|
268
|
+
if (seen === undefined || seen.length === 0)
|
|
269
|
+
return;
|
|
270
|
+
if (seen.length <= 1)
|
|
271
|
+
signinFailures.delete(source);
|
|
272
|
+
else
|
|
273
|
+
signinFailures.set(source, seen.slice(Math.floor(seen.length / 2)));
|
|
274
|
+
}
|
|
275
|
+
/** Okta sign-ins one address may start per `SIGNIN_WINDOW`, counted apart from passwords. */
|
|
276
|
+
exports.SSO_MAX_STARTS = 20;
|
|
277
|
+
const ssoStarts = new Map();
|
|
278
|
+
/** Count an Okta sign-in start from `source`, or refuse it: false once over the limit. */
|
|
279
|
+
function ssoStartAllowed(source) {
|
|
280
|
+
const now = monotonicSeconds();
|
|
281
|
+
if (ssoStarts.size > exports.SIGNIN_MAX_KEYS) {
|
|
282
|
+
for (const [address, hits] of ssoStarts) {
|
|
283
|
+
if (now - (hits.at(-1) ?? 0) > exports.SIGNIN_WINDOW)
|
|
284
|
+
ssoStarts.delete(address);
|
|
285
|
+
}
|
|
286
|
+
// Still full: every key is live. Forgetting them costs at most more starts, which the
|
|
287
|
+
// pending cap in `core/sso` bounds anyway; growing without limit costs the server.
|
|
288
|
+
if (ssoStarts.size > exports.SIGNIN_MAX_KEYS)
|
|
289
|
+
ssoStarts.clear();
|
|
290
|
+
}
|
|
291
|
+
const hits = (ssoStarts.get(source) ?? []).filter((stamp) => now - stamp < exports.SIGNIN_WINDOW);
|
|
292
|
+
if (hits.length >= exports.SSO_MAX_STARTS)
|
|
293
|
+
return false;
|
|
294
|
+
hits.push(now);
|
|
295
|
+
ssoStarts.set(source, hits);
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
async function doSignin(user, password, source, agent) {
|
|
299
|
+
const users = usersModule();
|
|
300
|
+
if (!users.anyUsers())
|
|
301
|
+
return ['', 'nouser'];
|
|
302
|
+
if (signinRetryAfter(source))
|
|
303
|
+
return ['', 'rate'];
|
|
304
|
+
if (!(await users.verify(user, password, source))) {
|
|
305
|
+
signinFailed(source);
|
|
306
|
+
return ['', 'bad'];
|
|
307
|
+
}
|
|
308
|
+
signinOk(source);
|
|
309
|
+
return [
|
|
310
|
+
await sessions.create(users.normalizeName(user), { label: sessions.describeAgent(agent) }),
|
|
311
|
+
'',
|
|
312
|
+
];
|
|
313
|
+
}
|
|
314
|
+
function requestPath(request) {
|
|
315
|
+
return request.url.split('?', 1)[0] ?? '/';
|
|
316
|
+
}
|
|
317
|
+
function forbidden(reply, error) {
|
|
318
|
+
return reply.code(403).send({ error, kind: 'Forbidden' });
|
|
319
|
+
}
|
|
320
|
+
function onRequestHook(context) {
|
|
321
|
+
return function onRequest(request, reply, done) {
|
|
322
|
+
// WebSocket refusals are protocol close frames (1008), not HTTP JSON replies.
|
|
323
|
+
// Its handler re-runs this same Host/cross-site/session/role chain after upgrade.
|
|
324
|
+
if (request.routeOptions.config.houstonTransport === 'WS') {
|
|
325
|
+
done();
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const host = headerText(request.headers.host);
|
|
329
|
+
if (!hostOk(context, host)) {
|
|
330
|
+
const refused = host.slice(0, 120);
|
|
331
|
+
forbidden(reply, `host not allowed: ${(0, format_1.quotedText)(refused)} is not in the allow-list. ` +
|
|
332
|
+
`Restart with \`--allow-host ${refused.split(':', 1)[0] ?? ''}\` ` +
|
|
333
|
+
"(or '*' for any host).");
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
const path = requestPath(request);
|
|
337
|
+
if ((request.method !== 'GET' && request.method !== 'HEAD' && request.method !== 'OPTIONS') ||
|
|
338
|
+
path.startsWith('/api/')) {
|
|
339
|
+
if (crossSite(context, request.headers)) {
|
|
340
|
+
forbidden(reply, 'cross-site request refused');
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
done();
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
function roleRefusal(dependencies, actor, need, request, template, reply) {
|
|
348
|
+
const role = dependencies.roleOf(actor);
|
|
349
|
+
if (need === null) {
|
|
350
|
+
const where = template || requestPath(request) || '?';
|
|
351
|
+
dependencies.audit(actor, 'denied', `${request.method} ${where} (no role declared)`, {
|
|
352
|
+
origin: 'session',
|
|
353
|
+
outcome: 'denied',
|
|
354
|
+
});
|
|
355
|
+
forbidden(reply, `${request.method} ${template} declares no minimum role, so it is refused (see ROUTE_ROLES)`);
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
if (!dependencies.atLeast(role, need)) {
|
|
359
|
+
dependencies.audit(actor, 'denied', `${request.method} ${template} needs ${need}`, {
|
|
360
|
+
origin: 'session',
|
|
361
|
+
outcome: 'denied',
|
|
362
|
+
});
|
|
363
|
+
forbidden(reply, `this needs the '${need}' role; you are '${role}'`);
|
|
364
|
+
return true;
|
|
365
|
+
}
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
function preHandlerHook(context, dependencies) {
|
|
369
|
+
return function preHandler(request, reply, done) {
|
|
370
|
+
if (request.routeOptions.config.houstonTransport === 'WS') {
|
|
371
|
+
done();
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
const path = requestPath(request);
|
|
375
|
+
const template = request.routeOptions.url ?? '';
|
|
376
|
+
const need = context.routeRequirement(request.method, template);
|
|
377
|
+
const openPath = need === '' || path === '/app.css';
|
|
378
|
+
if (!context.accounts) {
|
|
379
|
+
request.houstonActor = '';
|
|
380
|
+
(0, context_1.runWithContext)({ actor: '', origin: '' }, done);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
const peer = resolvePeer(context, request);
|
|
384
|
+
const token = cookieValue(headerText(request.headers.cookie), cookieName(context, peer.https));
|
|
385
|
+
void dependencies.verifySession(token).then((session) => {
|
|
386
|
+
const actor = session?.user ?? '';
|
|
387
|
+
if (actor && path.startsWith('/api/') && !openPath) {
|
|
388
|
+
if (roleRefusal(dependencies, actor, need, request, template, reply))
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
if (!openPath && !actor) {
|
|
392
|
+
if (path.startsWith('/api/')) {
|
|
393
|
+
reply.code(401).send({ error: 'sign in to use houston', kind: 'Unauthorized' });
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
reply.redirect(`/signin?e=required&next=${signinNext(request.url)}`, 303);
|
|
397
|
+
}
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
request.houstonActor = actor;
|
|
401
|
+
if (!actor || context.ownerScoped?.(request.method, template) !== true) {
|
|
402
|
+
(0, context_1.runWithContext)({ actor, origin: actor ? 'session' : '' }, done);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
const name = String(request.params.name ?? '');
|
|
406
|
+
void dependencies.workspaceRefusal(name, actor).then((why) => {
|
|
407
|
+
if (why === '') {
|
|
408
|
+
(0, context_1.runWithContext)({ actor, origin: 'session' }, done);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
dependencies.audit(actor, 'denied', `${request.method} ${template} not theirs`, {
|
|
412
|
+
origin: 'session',
|
|
413
|
+
outcome: 'denied',
|
|
414
|
+
});
|
|
415
|
+
done(new errors_1.ConflictError(why));
|
|
416
|
+
}, (error) => done(error instanceof Error ? error : new Error((0, errors_1.errorText)(error))));
|
|
417
|
+
}, (error) => done(error instanceof Error ? error : new Error((0, errors_1.errorText)(error))));
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Where the sign-in page sends a browser back to: the request's decoded path, plus `?` and
|
|
422
|
+
* its query when there is one, percent-encoded with `/?=&` kept.
|
|
423
|
+
*
|
|
424
|
+
* Not the raw target. The path is decoded and the raw query set beside it, the two are
|
|
425
|
+
* glued into a URL, and that URL is split again. So the path is DECODED and quoted again
|
|
426
|
+
* (`/%2F` is `//`), tab, CR and LF are dropped, a decoded `#` ends it and a decoded `?`
|
|
427
|
+
* starts the query, and the query keeps its escapes, which are quoted once more (`?q=%2F`
|
|
428
|
+
* is `?q=%252F`). encodeURIComponent over the raw target sent `/` as `%2F` where the
|
|
429
|
+
* established redirect has `/`.
|
|
430
|
+
*/
|
|
431
|
+
function signinNext(target) {
|
|
432
|
+
const mark = target.indexOf('?');
|
|
433
|
+
const query = mark === -1 ? '' : target.slice(mark + 1);
|
|
434
|
+
let url = (0, format_1.urlUnquote)(mark === -1 ? target : target.slice(0, mark));
|
|
435
|
+
if (query !== '')
|
|
436
|
+
url += `?${query}`;
|
|
437
|
+
url = url.replace(/[\t\r\n]/gu, '');
|
|
438
|
+
const hash = url.indexOf('#');
|
|
439
|
+
if (hash !== -1)
|
|
440
|
+
url = url.slice(0, hash);
|
|
441
|
+
const split = url.indexOf('?');
|
|
442
|
+
// An empty query is no query: `path + ('?' + query if query else '')`.
|
|
443
|
+
const nxt = split !== -1 && split === url.length - 1 ? url.slice(0, split) : url;
|
|
444
|
+
return (0, format_1.urlQuote)(nxt, '/?=&');
|
|
445
|
+
}
|
|
446
|
+
function onSendHook(context) {
|
|
447
|
+
return function onSend(request, reply, payload, done) {
|
|
448
|
+
if (!reply.hasHeader('content-security-policy'))
|
|
449
|
+
reply.header('Content-Security-Policy', context.csp);
|
|
450
|
+
if (!reply.hasHeader('x-content-type-options'))
|
|
451
|
+
reply.header('X-Content-Type-Options', 'nosniff');
|
|
452
|
+
if (!requestPath(request).startsWith('/api/') && !reply.hasHeader('cache-control')) {
|
|
453
|
+
reply.header('Cache-Control', 'no-cache');
|
|
454
|
+
}
|
|
455
|
+
if (!reply.hasHeader('referrer-policy'))
|
|
456
|
+
reply.header('Referrer-Policy', 'same-origin');
|
|
457
|
+
done(null, payload);
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
/** Install the named guard chain before registering any routes. */
|
|
461
|
+
function installSecurity(app, context, dependencies = {}) {
|
|
462
|
+
const resolved = { ...DEFAULT_DEPENDENCIES, ...dependencies };
|
|
463
|
+
app.decorate('houstonSecurity', context);
|
|
464
|
+
app.decorateRequest('houstonActor', '');
|
|
465
|
+
app.addHook('onRequest', onRequestHook(context));
|
|
466
|
+
// Authentication belongs before content parsing: an unauthenticated protected request
|
|
467
|
+
// is refused before its body is validated. Fastify's
|
|
468
|
+
// preParsing stage keeps the established onRequest -> role guard ordering and is still
|
|
469
|
+
// early enough that an unauthorised body is never parsed.
|
|
470
|
+
const roleGuard = preHandlerHook(context, resolved);
|
|
471
|
+
app.addHook('preParsing', (request, reply, _payload, done) => {
|
|
472
|
+
roleGuard(request, reply, done);
|
|
473
|
+
});
|
|
474
|
+
app.addHook('onSend', onSendHook(context));
|
|
475
|
+
}
|