dsh-agent-plugins-market 0.14.2 → 0.14.3

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.
@@ -1,43 +1,70 @@
1
- /** Hostnames that mean this machine. A rebound request cannot carry one of these. */
2
- const LOOPBACK_HOSTNAMES = new Set(['localhost', '127.0.0.1', '[::1]', '::1', '0.0.0.0']);
3
1
  /**
4
- * Parse an authority the way `URL` does, keeping the port separate.
2
+ * Whether a WHATWG hostname names the local loopback authority.
5
3
  *
6
- * `new URL()` needs a scheme, and a `Host` header has none, so the parse goes
7
- * through a fixed base and the result is only ever read for hostname and port.
8
- * @param authority - a `host` or `host:port` string.
9
- * @returns the parsed parts, or undefined when the text is not an authority.
4
+ * A byte-for-byte mirror of the harness classifier `isLoopbackHostname`
5
+ * (`packages/client/connection/src/loopback-hostname.ts:12`): localhost, the
6
+ * bracketed IPv6 loopback, or any IPv4 address in 127/8. Keeping the two fences
7
+ * on one classifier is the same alignment as the trusted entries below — the
8
+ * host accepts `127.0.0.2`, so a plugin inside that host may not refuse it —
9
+ * and `0.0.0.0` is not loopback here either: a listener bound to it admits that
10
+ * Host through the bind-address path, exactly like the host fence.
11
+ * @param hostname - the parsed request hostname (IPv6 literals retain brackets).
10
12
  */
11
- function parseAuthority(authority) {
12
- try {
13
- const url = new URL('http://' + authority);
14
- return { hostname: url.hostname, port: url.port };
15
- }
16
- catch (error) {
17
- // Unparsable authority text is a request we cannot reason about, which is not
18
- // the same as a trusted one.
19
- if (error instanceof TypeError)
20
- return undefined;
21
- throw error;
22
- }
13
+ function isLoopbackHostname(hostname) {
14
+ if (hostname === 'localhost' || hostname === '[::1]')
15
+ return true;
16
+ const parts = hostname.split('.');
17
+ return parts.length === 4 && parts[0] === '127' && parts.every(part => /^\d{1,3}$/.test(part) && Number(part) <= 255);
18
+ }
19
+ /**
20
+ * Read the host's declared authorities out of the context a route mount already holds.
21
+ *
22
+ * The connection service keeps `trustedHosts` TypeScript-private and the web server
23
+ * service carries the bind address, so both ride structural reads: there is no host
24
+ * package dependency to import types from, mirroring the local `WebHost` precedent.
25
+ * The services resolve at call time because they can provision after this plugin's
26
+ * apply, and a context without them yields undefined, which the fence reads as
27
+ * loopback-only.
28
+ * @param host - the host context a route mount received, verbatim.
29
+ * @returns the declared authorities, or undefined when the host declares none.
30
+ */
31
+ export function requestTrustAuthoritiesOf(host) {
32
+ const get = host?.get;
33
+ if (get === undefined)
34
+ return undefined;
35
+ const connection = get.call(host, 'connection');
36
+ const webServer = get.call(host, 'webServer');
37
+ const trustedHosts = Array.isArray(connection?.trustedHosts) ? connection.trustedHosts : [];
38
+ const bindHost = typeof webServer?.host === 'string' && webServer.host !== '' ? webServer.host : undefined;
39
+ if (trustedHosts.length === 0 && bindHost === undefined)
40
+ return undefined;
41
+ return {
42
+ trustedHosts,
43
+ ...(bindHost === undefined ? {} : { bindHost }),
44
+ ...(webServer?.protocol === undefined ? {} : { protocol: webServer.protocol })
45
+ };
23
46
  }
24
47
  /**
25
48
  * Decide whether one request may run a mutating route.
26
49
  *
27
- * @param request - the incoming request; its headers are the only evidence.
28
- * @returns true only when the request provably came from this machine.
50
+ * @param request - the incoming request; its headers are the only evidence of who sent it.
51
+ * @param authorities - the host's declared authorities beyond loopback; undefined means loopback-only.
52
+ * @returns true only when the request provably came from a source the deployment serves.
29
53
  */
30
- export function isTrustedMutation(request) {
54
+ export function isTrustedMutation(request, authorities) {
31
55
  const host = request.headers['host'];
32
56
  if (host === undefined)
33
57
  return false;
34
- const authority = parseAuthority(host);
35
- if (authority === undefined)
58
+ // Host parses under the listener's scheme, like the host fence: that is what makes an
59
+ // explicit default-port entry exact instead of a wildcard.
60
+ const protocol = authorities?.protocol === 'https:' ? 'https:' : 'http:';
61
+ const hostUrl = parseAuthority(host, protocol);
62
+ if (hostUrl === undefined)
36
63
  return false;
37
- // Loopback only. A deployment that exposes this port under another name needs a
38
- // configured allow-list, and the plugin has none, so a non-loopback Host means
39
- // the request did not come from a page we serve.
40
- if (!LOOPBACK_HOSTNAMES.has(authority.hostname))
64
+ // Loopback per the harness classifier. A non-loopback Host passes only when the host
65
+ // deployment declared it: a `trustedHosts` entry or the listener's own bind address.
66
+ // Everything else is still refused, so a rebound page's attacker domain gains nothing here.
67
+ if (!isLoopbackHostname(hostUrl.hostname) && !isTrustedAuthority(hostUrl, authorities?.trustedHosts ?? [], protocol) && !isBindAddressAuthority(hostUrl, authorities?.bindHost))
41
68
  return false;
42
69
  if (request.headers['sec-fetch-site'] === 'cross-site')
43
70
  return false;
@@ -46,15 +73,88 @@ export function isTrustedMutation(request) {
46
73
  return true;
47
74
  if (origin === 'null')
48
75
  return false;
76
+ // The Origin comparison keeps its own parse under plain HTTP: it weighs the browser's two
77
+ // headers against each other, not the configured authorities, and is unchanged by the
78
+ // accepted set above.
49
79
  const from = parseAuthority(stripScheme(origin));
50
- return from !== undefined && from.hostname === authority.hostname && from.port === authority.port;
80
+ const authority = parseAuthority(host);
81
+ return from !== undefined && authority !== undefined && from.hostname === authority.hostname && from.port === authority.port;
82
+ }
83
+ /**
84
+ * Parse an authority the way `URL` does.
85
+ *
86
+ * `new URL()` needs a scheme, and a `Host` header has none, so the parse goes through a
87
+ * fixed special scheme and only the hostname and port are ever read.
88
+ * @param authority - a `host` or `host:port` string.
89
+ * @param scheme - the special scheme to parse under; its default port is the one stripped.
90
+ * @returns the parsed URL, or undefined when the text is not an authority.
91
+ */
92
+ function parseAuthority(authority, scheme = 'http:') {
93
+ try {
94
+ return new URL(`${scheme}//${authority}`);
95
+ }
96
+ catch (error) {
97
+ // Unparsable authority text is a request we cannot reason about, which is not
98
+ // the same as a trusted one.
99
+ if (error instanceof TypeError)
100
+ return undefined;
101
+ throw error;
102
+ }
103
+ }
104
+ /**
105
+ * Whether the request authority matches one of the host's `trustedHosts` entries.
106
+ *
107
+ * A mirror of the host fence's own matcher: an entry with an explicit port matches that
108
+ * exact authority, a port-less entry matches the hostname on any port, and both sides
109
+ * compare through WHATWG normalization, so case and a redundant scheme-default port never
110
+ * decide trust. Explicitness is judged from parses under both special schemes, because
111
+ * `:80` and `:443` are explicit ports that their own scheme's parser silently strips.
112
+ * Whether an entry is well-formed is the host's load-time concern: the connection service
113
+ * refuses malformed entries when it provisions, so only validated ones arrive here.
114
+ * @param hostUrl - the parsed request authority.
115
+ * @param trustedHosts - the entries as the host holds them.
116
+ * @param protocol - the listener scheme, for default-port normalization.
117
+ */
118
+ function isTrustedAuthority(hostUrl, trustedHosts, protocol) {
119
+ return trustedHosts.some(entry => {
120
+ const entryUrl = parseAuthority(entry, protocol);
121
+ if (entryUrl === undefined)
122
+ return false;
123
+ return canonicalAuthority(entry, entryUrl) === entryUrl.hostname ? entryUrl.hostname === hostUrl.hostname : entryUrl.host === hostUrl.host;
124
+ });
125
+ }
126
+ /**
127
+ * Canonical form of a parsed configured entry: `hostname` when no port was written, else
128
+ * `hostname:port`. The port is judged from parses under both special schemes, never from
129
+ * the raw string, where WHATWG trimming would misread shapes like `host:port `.
130
+ */
131
+ function canonicalAuthority(entry, entryUrl) {
132
+ const port = entryUrl.port !== '' ? entryUrl.port : (parseAuthority(entry, entryUrl.protocol === 'http:' ? 'https:' : 'http:')?.port ?? '');
133
+ return port === '' ? entryUrl.hostname : `${entryUrl.hostname}:${port}`;
134
+ }
135
+ /**
136
+ * Whether the request authority names the listener's own bind address, matched by hostname
137
+ * on any port, like a port-less entry. A browser dialing that literal sends it as `Host`,
138
+ * and accepting it grants nothing further: the literal is no rebinding target, and the
139
+ * Origin and cross-site checks still apply. Any `%zone` id is an interface selector, not
140
+ * address text, and is dropped first.
141
+ */
142
+ function isBindAddressAuthority(hostUrl, bindHost) {
143
+ if (bindHost === undefined)
144
+ return false;
145
+ const zoneAt = bindHost.indexOf('%');
146
+ const address = zoneAt === -1 ? bindHost : bindHost.slice(0, zoneAt);
147
+ const bindUrl = parseAuthority(address.includes(':') ? `[${address}]` : address);
148
+ return bindUrl !== undefined && bindUrl.hostname === hostUrl.hostname;
51
149
  }
52
150
  /**
53
151
  * Drop a scheme from an Origin value so it parses like a Host value.
54
152
  *
55
153
  * An Origin carries a scheme and never a path, so removing the scheme is enough
56
- * to compare it with Host. A value with a path is not an Origin this server
57
- * issued, and it fails to parse as an authority, which then refuses it.
154
+ * to compare it with Host. A value carrying a path is not an Origin this server
155
+ * issued, but the URL constructor drops the path silently instead of failing, so
156
+ * such a value is compared on its hostname like any other; a genuine browser
157
+ * Origin never carries one, so the comparison never sees this shape in practice.
58
158
  * @param origin - the Origin header value.
59
159
  * @returns the authority text, unchanged when it carries no scheme.
60
160
  */
@@ -1,5 +1,5 @@
1
1
  import { AI_DIAGNOSE_FACES, AI_DIAGNOSE_LIMITS, AI_DRAFT_ROUTES, AI_PRESET_LIMITS } from '../../market-contracts/src/contracts/ai-draft.js';
2
- import { isTrustedMutation } from './request-trust.js';
2
+ import { isTrustedMutation, requestTrustAuthoritiesOf } from './request-trust.js';
3
3
  import { routeFailurePayload } from './route-errors.js';
4
4
  import { readJsonBody, sendJson } from './route-http.js';
5
5
  /**
@@ -34,7 +34,7 @@ export function mountAiDraftRoutes(ctx, deps) {
34
34
  sendJson(response, 405, { error: 'method not allowed' });
35
35
  return;
36
36
  }
37
- if (!isTrustedMutation(request)) {
37
+ if (!isTrustedMutation(request, requestTrustAuthoritiesOf(ctx))) {
38
38
  sendJson(response, 403, { error: 'untrusted request' });
39
39
  return;
40
40
  }
@@ -83,7 +83,7 @@ export function mountAiDraftRoutes(ctx, deps) {
83
83
  sendJson(response, 405, { error: 'method not allowed' });
84
84
  return;
85
85
  }
86
- if (!isTrustedMutation(request)) {
86
+ if (!isTrustedMutation(request, requestTrustAuthoritiesOf(ctx))) {
87
87
  sendJson(response, 403, { error: 'untrusted request' });
88
88
  return;
89
89
  }
@@ -1,5 +1,5 @@
1
1
  /** Session-addressed extension APIs. Workspace authority comes from the live Agent, never request paths. */
2
- import { isTrustedMutation } from './request-trust.js';
2
+ import { isTrustedMutation, requestTrustAuthoritiesOf } from './request-trust.js';
3
3
  import { EXTENSION_ROUTES, parseExtensionIds, parseExtensionName } from '../../market-contracts/src/contracts/extension-presets.js';
4
4
  function id(value) {
5
5
  if (typeof value !== 'string' || value.length === 0 || value.length > 1024)
@@ -43,7 +43,7 @@ export function mountExtensionPresetRoutes(host, service) {
43
43
  json(response, 405, { ok: false, code: 'method-not-allowed', error: 'method not allowed' });
44
44
  return;
45
45
  }
46
- if (!isTrustedMutation(request)) {
46
+ if (!isTrustedMutation(request, requestTrustAuthoritiesOf(host))) {
47
47
  json(response, 403, { ok: false, code: 'cross-origin', error: 'cross-origin request rejected' });
48
48
  return;
49
49
  }
@@ -73,7 +73,7 @@ export function mountExtensionPresetRoutes(host, service) {
73
73
  json(response, 405, { ok: false, code: 'method-not-allowed', error: 'method not allowed' });
74
74
  return;
75
75
  }
76
- if (!isTrustedMutation(request)) {
76
+ if (!isTrustedMutation(request, requestTrustAuthoritiesOf(host))) {
77
77
  json(response, 403, { ok: false, code: 'cross-origin', error: 'cross-origin request rejected' });
78
78
  return;
79
79
  }
@@ -99,7 +99,7 @@ export function mountExtensionPresetRoutes(host, service) {
99
99
  json(response, 405, { ok: false, code: 'method-not-allowed', error: 'method not allowed' });
100
100
  return;
101
101
  }
102
- if (!isTrustedMutation(request)) {
102
+ if (!isTrustedMutation(request, requestTrustAuthoritiesOf(host))) {
103
103
  json(response, 403, { ok: false, code: 'cross-origin', error: 'cross-origin request rejected' });
104
104
  return;
105
105
  }
@@ -11,7 +11,7 @@
11
11
  * The handlers live here rather than in `routes.ts` so the main table stays
12
12
  * readable; the composition root mounts both under one disposer.
13
13
  */
14
- import { isTrustedMutation } from './request-trust.js';
14
+ import { isTrustedMutation, requestTrustAuthoritiesOf } from './request-trust.js';
15
15
  import { routeFailurePayload } from './route-errors.js';
16
16
  import { queryOf, readJsonBody, sendJson } from './route-http.js';
17
17
  import { isAbsolute } from 'node:path';
@@ -29,7 +29,7 @@ export function mountInstructionRoutes(hostCtx, deps) {
29
29
  kind: 'exact',
30
30
  path,
31
31
  handler: (request, response) => {
32
- if (!isTrustedMutation(request)) {
32
+ if (!isTrustedMutation(request, requestTrustAuthoritiesOf(hostCtx))) {
33
33
  sendJson(response, 403, { ok: false, error: 'cross-origin request rejected' });
34
34
  return;
35
35
  }
@@ -14,7 +14,7 @@
14
14
  * readable; the composition root mounts both under one disposer.
15
15
  * @module routes-output-styles
16
16
  */
17
- import { isTrustedMutation } from './request-trust.js';
17
+ import { isTrustedMutation, requestTrustAuthoritiesOf } from './request-trust.js';
18
18
  import { routeFailurePayload } from './route-errors.js';
19
19
  import { queryOf, readJsonBody, sendJson } from './route-http.js';
20
20
  import { isAbsolute } from 'node:path';
@@ -36,7 +36,7 @@ export function mountOutputStyleRoutes(hostCtx, deps) {
36
36
  kind: 'exact',
37
37
  path,
38
38
  handler: (request, response) => {
39
- if (!isTrustedMutation(request)) {
39
+ if (!isTrustedMutation(request, requestTrustAuthoritiesOf(hostCtx))) {
40
40
  sendJson(response, 403, { ok: false, error: 'cross-origin request rejected' });
41
41
  return;
42
42
  }
@@ -6,7 +6,7 @@
6
6
  * handlers live in their own module so the main route table stays untouched
7
7
  * by the window; the composition root mounts both under one disposer.
8
8
  */
9
- import { isTrustedMutation } from './request-trust.js';
9
+ import { isTrustedMutation, requestTrustAuthoritiesOf } from './request-trust.js';
10
10
  import { routeFailurePayload } from './route-errors.js';
11
11
  import { readJsonBody, sendJson } from './route-http.js';
12
12
  import { RESOURCE_ROUTES, resolveFavoriteInput } from '../../market-contracts/src/contracts/resource-window.js';
@@ -24,7 +24,7 @@ export function mountResourceRoutes(hostCtx, deps) {
24
24
  kind: 'exact',
25
25
  path,
26
26
  handler: (request, response) => {
27
- if (!isTrustedMutation(request)) {
27
+ if (!isTrustedMutation(request, requestTrustAuthoritiesOf(hostCtx))) {
28
28
  sendJson(response, 403, { ok: false, error: 'cross-origin request rejected' });
29
29
  return;
30
30
  }
@@ -9,7 +9,7 @@
9
9
  * by the store.
10
10
  * @module routes-tab-layout
11
11
  */
12
- import { isTrustedMutation } from './request-trust.js';
12
+ import { isTrustedMutation, requestTrustAuthoritiesOf } from './request-trust.js';
13
13
  import { routeFailurePayload } from './route-errors.js';
14
14
  import { readJsonBody, sendJson } from './route-http.js';
15
15
  import { MARKET_ROUTES } from '../../market-contracts/src/contracts/market.js';
@@ -34,7 +34,7 @@ export function mountTabLayoutRoutes(hostCtx, service) {
34
34
  kind: 'exact',
35
35
  path: MARKET_ROUTES.setTabLayout,
36
36
  handler: (request, response) => {
37
- if (!isTrustedMutation(request)) {
37
+ if (!isTrustedMutation(request, requestTrustAuthoritiesOf(hostCtx))) {
38
38
  sendJson(response, 403, { ok: false, error: 'cross-origin request rejected' });
39
39
  return;
40
40
  }
@@ -58,7 +58,7 @@ export function mountTabLayoutRoutes(hostCtx, service) {
58
58
  kind: 'exact',
59
59
  path: MARKET_ROUTES.setTabOrder,
60
60
  handler: (request, response) => {
61
- if (!isTrustedMutation(request)) {
61
+ if (!isTrustedMutation(request, requestTrustAuthoritiesOf(hostCtx))) {
62
62
  sendJson(response, 403, { ok: false, error: 'cross-origin request rejected' });
63
63
  return;
64
64
  }
@@ -1,7 +1,7 @@
1
1
  import { USER_HOOK_EVENTS, USER_HOOK_LIMITS, USER_HOOKS_ROUTES } from '../../market-contracts/src/contracts/user-hooks.js';
2
2
  import { appendUserHook } from './application/user-hooks-writer.js';
3
3
  import { createAiHookService } from './application/ai-hook.js';
4
- import { isTrustedMutation } from './request-trust.js';
4
+ import { isTrustedMutation, requestTrustAuthoritiesOf } from './request-trust.js';
5
5
  import { routeFailurePayload } from './route-errors.js';
6
6
  import { readJsonBody, sendJson } from './route-http.js';
7
7
  /** The one failure a document can earn that is the reader's to fix. */
@@ -34,7 +34,7 @@ export function mountUserHooksRoutes(ctx, deps) {
34
34
  sendJson(response, 405, { error: 'method not allowed' });
35
35
  return;
36
36
  }
37
- if (!isTrustedMutation(request)) {
37
+ if (!isTrustedMutation(request, requestTrustAuthoritiesOf(ctx))) {
38
38
  sendJson(response, 403, { error: 'untrusted request' });
39
39
  return;
40
40
  }
@@ -64,7 +64,7 @@ export function mountUserHooksRoutes(ctx, deps) {
64
64
  sendJson(response, 405, { error: 'method not allowed' });
65
65
  return;
66
66
  }
67
- if (!isTrustedMutation(request)) {
67
+ if (!isTrustedMutation(request, requestTrustAuthoritiesOf(ctx))) {
68
68
  sendJson(response, 403, { error: 'untrusted request' });
69
69
  return;
70
70
  }
@@ -6,7 +6,7 @@
6
6
  * cross-site form or fetch cannot trigger a clone, an uninstall, or an
7
7
  * enable/disable against a local profile.
8
8
  */
9
- import { isTrustedMutation } from './request-trust.js';
9
+ import { isTrustedMutation, requestTrustAuthoritiesOf } from './request-trust.js';
10
10
  import { queryOf, readJsonBody, sendJson } from './route-http.js';
11
11
  import { isAbsolute } from 'node:path';
12
12
  import { MARKET_ROUTES, userPanelRoute } from '../../market-contracts/src/contracts/market.js';
@@ -51,7 +51,7 @@ export function mountSuiteRoutes(hostCtx, manager, panels, surfaceToggles, sessi
51
51
  kind: 'exact',
52
52
  path,
53
53
  handler: (request, response) => {
54
- if (!isTrustedMutation(request)) {
54
+ if (!isTrustedMutation(request, requestTrustAuthoritiesOf(hostCtx))) {
55
55
  sendJson(response, 403, { ok: false, error: 'cross-origin request rejected' });
56
56
  return;
57
57
  }
@@ -1,5 +1,6 @@
1
1
  import { PLUGIN_DATA_VARIABLES, PLUGIN_ROOT_VARIABLES } from '../../../market-contracts/src/model/layouts.js';
2
2
  const FIELDS = new Set([
3
+ 'type',
3
4
  'command',
4
5
  'args',
5
6
  'env',
@@ -51,6 +52,19 @@ function timeout(value, field, factor) {
51
52
  throw new Error(`${field} must be a positive finite timeout within the timer range`);
52
53
  return Math.max(1, Math.ceil(value * factor));
53
54
  }
55
+ const SERVER_TYPES = new Set(['stdio', 'http', 'sse', 'streamable-http', 'streamable_http']);
56
+ /** A declared `type` must agree with the transport the table's fields imply; Codex itself never writes the key and ignores unknown fields. */
57
+ function declaredType(value, stdio) {
58
+ if (value.type === undefined)
59
+ return;
60
+ const declared = text(value.type, 'type');
61
+ if (!SERVER_TYPES.has(declared))
62
+ throw new Error('type must be one of stdio, http, sse, streamable-http, streamable_http');
63
+ if (stdio && declared !== 'stdio')
64
+ throw new Error(`type "${declared}" cannot be combined with a stdio command`);
65
+ if (!stdio && declared === 'stdio')
66
+ throw new Error(`type "${declared}" cannot be combined with an HTTP endpoint`);
67
+ }
54
68
  /** Unknown or malformed server options reject that server; other servers stay independently usable. */
55
69
  export function normalizeCodexMcp(raw, errors) {
56
70
  const servers = Object.create(null);
@@ -78,6 +92,7 @@ export function normalizeCodexMcp(raw, errors) {
78
92
  if (value.command !== undefined) {
79
93
  if (['url', 'http_headers', 'env_http_headers', 'bearer_token_env_var'].some(key => value[key] !== undefined))
80
94
  throw new Error('HTTP options cannot be combined with a stdio command');
95
+ declaredType(value, true);
81
96
  const inherited = Object.fromEntries((strings(value.env_vars, 'env_vars') ?? []).map(key => [key, reference(key, 'env_vars')]));
82
97
  servers[name] = {
83
98
  ...policy,
@@ -94,6 +109,7 @@ export function normalizeCodexMcp(raw, errors) {
94
109
  const url = text(value.url, 'url');
95
110
  if (!['https:', 'http:'].includes(new URL(url).protocol))
96
111
  throw new Error('url must use HTTP or HTTPS');
112
+ declaredType(value, false);
97
113
  const headers = {
98
114
  ...table(value.http_headers, 'http_headers'),
99
115
  ...Object.fromEntries(Object.entries(table(value.env_http_headers, 'env_http_headers')).map(([key, variable]) => [key, reference(variable, 'env_http_headers')]))
@@ -8,26 +8,60 @@
8
8
  * `Origin` alike. Comparing the two is therefore not a fence: both are
9
9
  * attacker-chosen.
10
10
  *
11
- * The host applies this same rule to its own bridge, at
11
+ * The host applies this same rule to its own `/api` bridge, at
12
12
  * `packages/client/connection/src/api-request-trust.ts:121`. Three checks, in order:
13
13
  *
14
- * 1. `Host` must name this machine. A rebound page carries the attacker's
15
- * domain there even though the socket lands here.
14
+ * 1. `Host` must name this machine: a loopback hostname (`localhost`, `[::1]`, or
15
+ * any 127/8 address — the harness's own classifier, mirrored below), an entry
16
+ * of the host connection service's `trustedHosts` (an exact `host:port`, or a
17
+ * port-less `host` on any port), or the listener's bind address. A reverse proxy keeps
18
+ * the public `Host`, so a deployment that declared its name to the host must
19
+ * not be refused by a plugin mounted inside that same host, while a name it
20
+ * never declared is still refused (the #156 rebinding defense).
16
21
  * 2. `sec-fetch-site: cross-site` is refused outright. Modern browsers label
17
22
  * the initiator on every fetch, and a cross-site marker is decisive.
18
23
  * 3. When `Origin` is present it must equal `Host`. An absent `Origin` is
19
24
  * allowed because the `Host` fence already bound the request, and a
20
25
  * non-browser client sends no `Origin`.
21
26
  *
27
+ * The trusted entries and the bind address arrive through
28
+ * {@link requestTrustAuthoritiesOf}, read from the host services per request.
29
+ * Without a connection service — an older harness, a hand-built test context —
30
+ * the accepted set degrades to loopback only, which is everything this fence
31
+ * used to accept.
32
+ *
22
33
  * A sandboxed iframe or a `file:` page sends the literal `null`, which is an
23
34
  * opaque origin from somewhere else, so it is refused rather than parsed.
24
35
  * @module request-trust
25
36
  */
26
37
  import type { IncomingMessage } from 'node:http';
38
+ /** The authorities a host deployment declares beyond loopback. */
39
+ export interface RequestTrustAuthorities {
40
+ /** Entries of the host connection service's `trustedHosts`: exact `host:port`, or port-less `host` on any port. */
41
+ trustedHosts: readonly string[];
42
+ /** The listener's own bind address; matched by hostname on any port. */
43
+ bindHost?: string;
44
+ /** The listener scheme, used to normalize default ports; HTTP when unknown. */
45
+ protocol?: string;
46
+ }
47
+ /**
48
+ * Read the host's declared authorities out of the context a route mount already holds.
49
+ *
50
+ * The connection service keeps `trustedHosts` TypeScript-private and the web server
51
+ * service carries the bind address, so both ride structural reads: there is no host
52
+ * package dependency to import types from, mirroring the local `WebHost` precedent.
53
+ * The services resolve at call time because they can provision after this plugin's
54
+ * apply, and a context without them yields undefined, which the fence reads as
55
+ * loopback-only.
56
+ * @param host - the host context a route mount received, verbatim.
57
+ * @returns the declared authorities, or undefined when the host declares none.
58
+ */
59
+ export declare function requestTrustAuthoritiesOf(host: unknown): RequestTrustAuthorities | undefined;
27
60
  /**
28
61
  * Decide whether one request may run a mutating route.
29
62
  *
30
- * @param request - the incoming request; its headers are the only evidence.
31
- * @returns true only when the request provably came from this machine.
63
+ * @param request - the incoming request; its headers are the only evidence of who sent it.
64
+ * @param authorities - the host's declared authorities beyond loopback; undefined means loopback-only.
65
+ * @returns true only when the request provably came from a source the deployment serves.
32
66
  */
33
- export declare function isTrustedMutation(request: IncomingMessage): boolean;
67
+ export declare function isTrustedMutation(request: IncomingMessage, authorities?: RequestTrustAuthorities): boolean;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "dsh-agent-plugins-market",
3
3
  "icon": "./assets/dsh-agent-plugins.png",
4
4
  "description": "One-stop skills, subagent, MCP and LSP manager inside DeepSeek Harness (DSH), compatible with Claude Code, Codex, Cursor, Kimi and other agent plugin layouts.",
5
- "version": "0.14.2",
5
+ "version": "0.14.3",
6
6
  "type": "module",
7
7
  "main": "lib/index.js",
8
8
  "types": "lib/types/index.d.ts",