@jini-ai/http-kit 0.6.15-rc.2 → 0.6.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +3 -2
- package/dist/api-security-middleware.js +4 -5
- package/dist/local-daemon-request.js +3 -1
- package/dist/rate-limit.js +3 -0
- package/dist/verified-origin/configured-origin.js +4 -17
- package/dist/verified-origin/loopback-host.d.ts +9 -0
- package/dist/verified-origin/loopback-host.js +17 -0
- package/dist/verified-origin/origin.js +1 -1
- package/dist/verified-origin/ports.d.ts +9 -11
- package/dist/verified-origin/repo.memory.d.ts +4 -6
- package/dist/verified-origin/site-path.js +3 -4
- package/dist/verified-origin/types.d.ts +6 -6
- package/dist/verified-origin/types.js +10 -3
- package/package.json +7 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @jini-ai/http-kit
|
|
2
2
|
|
|
3
|
+
## 0.6.16
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Remove the GitHub Copilot CLI agent: its def, `createCopilotStreamHandler`/`CopilotStreamEvent`,
|
|
8
|
+
account model discovery and the `@github/copilot-sdk` optional peer, the MCP installer's `copilot`
|
|
9
|
+
slug, and its icon. A saved `copilot` agent id no longer resolves (`getAgentDef` returns `null`).
|
|
10
|
+
CopilotKit/AG-UI is unrelated and unchanged.
|
|
11
|
+
|
|
12
|
+
Drop peers no runtime entry loads: `express` from core and http-kit (type-only imports; type
|
|
13
|
+
consumers keep `@types/express`), `vue` from ui-kit, `react-dom` from vibecoding.
|
|
14
|
+
|
|
3
15
|
## 0.6.13
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -12,8 +12,9 @@ lives in `@jini-ai/daemon/read-only-tools`. CMS settings live in `@jini-ai/cms/h
|
|
|
12
12
|
npm install @jini-ai/http-kit express
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
Regular dependencies are core, platform
|
|
16
|
-
|
|
15
|
+
Regular dependencies are core, platform and protocol. Express is supplied by the host and
|
|
16
|
+
referenced only through erased types, so this package declares no Express runtime peer.
|
|
17
|
+
There is no daemon, agent-runtime or CMS dependency.
|
|
17
18
|
|
|
18
19
|
## Surface
|
|
19
20
|
|
|
@@ -255,11 +255,10 @@ export function registerApiOriginGuardMiddleware({ app, deps }, _optional = {})
|
|
|
255
255
|
return;
|
|
256
256
|
}
|
|
257
257
|
const ports = allowedBrowserPorts({ config, port: resolvedPort, env });
|
|
258
|
-
if (!isAllowedBrowserOrigin({ config, origin, hostHeader: req.headers.host, ports, bindHost: host, extraAllowedOrigins: [...extraAllowedOrigins] })
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
258
|
+
if (!isAllowedBrowserOrigin({ config, origin, hostHeader: req.headers.host, ports, bindHost: host, extraAllowedOrigins: [...extraAllowedOrigins] })
|
|
259
|
+
&& (req.method !== 'GET' || !isPortlessLoopbackOrigin(String(origin)))) {
|
|
260
|
+
res.status(403).json({ error: 'Cross-origin requests are not allowed' });
|
|
261
|
+
return;
|
|
263
262
|
}
|
|
264
263
|
next();
|
|
265
264
|
});
|
|
@@ -56,7 +56,9 @@ export function isLoopbackPeerAddress({ address }, _optional = {}) {
|
|
|
56
56
|
function isBareHttpOrigin({ parsed }, _optional = {}) {
|
|
57
57
|
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:')
|
|
58
58
|
return false;
|
|
59
|
-
if (parsed.pathname !== '/' || parsed.search || parsed.hash
|
|
59
|
+
if (parsed.pathname !== '/' || parsed.search || parsed.hash)
|
|
60
|
+
return false;
|
|
61
|
+
if (parsed.username || parsed.password)
|
|
60
62
|
return false;
|
|
61
63
|
return true;
|
|
62
64
|
}
|
package/dist/rate-limit.js
CHANGED
|
@@ -48,6 +48,9 @@ export function createRateLimiter({ profile, clock, store }, _optional = {}) {
|
|
|
48
48
|
}
|
|
49
49
|
lastSweepMs = nowMs;
|
|
50
50
|
}
|
|
51
|
+
else {
|
|
52
|
+
// The active window needs no expiry sweep.
|
|
53
|
+
}
|
|
51
54
|
const existing = await store.get({ key });
|
|
52
55
|
if (!existing || nowMs - existing.windowStartMs >= windowMs) {
|
|
53
56
|
await store.set({ key, state: { windowStartMs: nowMs, count: 1 } });
|
|
@@ -1,20 +1,7 @@
|
|
|
1
|
+
import { trimCharsEnd } from '@jini-ai/core/primitives';
|
|
1
2
|
import { hasForbiddenRawUrlCharacter } from "./origin.js";
|
|
2
3
|
import { createVerifiedOrigin } from "./types.js";
|
|
3
|
-
|
|
4
|
-
* Loopback (including *.localhost and 127.0.0.0/8) cannot represent a public deployment. Rejecting
|
|
5
|
-
* it also prevents a shared public-URL setting from overriding development TLS-derived schemes
|
|
6
|
-
* with a workspace-setting HTTPS origin on a server that only answers HTTP.
|
|
7
|
-
* Private network ranges remain valid: intranet deployments can legitimately use private hosts.
|
|
8
|
-
*/
|
|
9
|
-
const LOOPBACK_HOSTS = new Set(["localhost", "0.0.0.0", "::1", "[::1]", "::", "[::]"]);
|
|
10
|
-
const LOOPBACK_IPV4 = /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
|
|
11
|
-
function isLoopbackHost(host) {
|
|
12
|
-
if (LOOPBACK_HOSTS.has(host))
|
|
13
|
-
return true;
|
|
14
|
-
if (host.endsWith(".localhost"))
|
|
15
|
-
return true;
|
|
16
|
-
return LOOPBACK_IPV4.test(host);
|
|
17
|
-
}
|
|
4
|
+
import { isLoopbackHost } from "./loopback-host.js";
|
|
18
5
|
// Match candidate-origin normalization so a trailing DNS dot has one meaning across decisions.
|
|
19
6
|
function normalizeHost(hostname) {
|
|
20
7
|
const lowered = hostname.toLowerCase();
|
|
@@ -44,7 +31,7 @@ function refusalReason(url) {
|
|
|
44
31
|
const host = normalizeHost(url.hostname);
|
|
45
32
|
if (host === "")
|
|
46
33
|
return "its host is empty";
|
|
47
|
-
if (isLoopbackHost(host))
|
|
34
|
+
if (isLoopbackHost({ host }))
|
|
48
35
|
return `'${host}' is a loopback host, not a public origin`;
|
|
49
36
|
return null;
|
|
50
37
|
}
|
|
@@ -59,7 +46,7 @@ function buildConfiguredOrigin(url, now) {
|
|
|
59
46
|
};
|
|
60
47
|
if (url.port !== "")
|
|
61
48
|
candidate.port = Number(url.port);
|
|
62
|
-
const basePath = url.pathname
|
|
49
|
+
const basePath = trimCharsEnd({ text: url.pathname, chars: "/" });
|
|
63
50
|
if (basePath !== "")
|
|
64
51
|
candidate.basePath = basePath;
|
|
65
52
|
return createVerifiedOrigin(candidate);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Public identity must not name a development listener. Normalize URL spellings first so
|
|
2
|
+
* shortened IPv4 and IPv4-mapped IPv6 cannot bypass the same rule used for localhost.
|
|
3
|
+
* Private intranet hosts remain valid. Invalid hosts are left to the caller's URL validation.
|
|
4
|
+
* @complexity O(host bytes), pure; parse failures return false.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isLoopbackHost({ host }: {
|
|
7
|
+
host: string;
|
|
8
|
+
}, _options?: {}): boolean;
|
|
9
|
+
//# sourceMappingURL=loopback-host.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Public identity must not name a development listener. Normalize URL spellings first so
|
|
2
|
+
* shortened IPv4 and IPv4-mapped IPv6 cannot bypass the same rule used for localhost.
|
|
3
|
+
* Private intranet hosts remain valid. Invalid hosts are left to the caller's URL validation.
|
|
4
|
+
* @complexity O(host bytes), pure; parse failures return false.
|
|
5
|
+
*/
|
|
6
|
+
export function isLoopbackHost({ host }, _options = {}) {
|
|
7
|
+
let hostname;
|
|
8
|
+
const authority = host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
9
|
+
try {
|
|
10
|
+
hostname = new URL(`http://${authority}`).hostname.toLowerCase().replace(/\.$/, "");
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return /^(?:localhost|.*\.localhost|127\.\d+\.\d+\.\d+|0\.0\.0\.0|\[(?:::1|::|::ffff:7f[\da-f]{2}:[\da-f]+)\])$/.test(hostname);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=loopback-host.js.map
|
|
@@ -6,7 +6,7 @@ import { OriginNotVerifiedError, createVerifiedOrigin } from "./types.js";
|
|
|
6
6
|
* redirect reads must use this same raw predicate; checking a reserialized url.href checks too late.
|
|
7
7
|
*/
|
|
8
8
|
// biome-ignore lint/suspicious/noControlCharactersInRegex: control chars are the POINT — F3 requires rejecting C0/DEL and backslash in a raw candidate URL before the WHATWG parser silently strips them. See this constant's own doc comment. See docs/decisions/DR-001-redirect-normalization.md.
|
|
9
|
-
const FORBIDDEN_RAW_CHARS = /[\\\s\x00-\x1F\x7F]/;
|
|
9
|
+
const FORBIDDEN_RAW_CHARS = /[\\\s\x00-\x08\x0E-\x1F\x7F]/;
|
|
10
10
|
/** Reject parser-ambiguous backslashes, whitespace and controls before URL normalization.
|
|
11
11
|
* @complexity O(raw.length) time, O(1) space; pure.
|
|
12
12
|
* @example hasForbiddenRawUrlCharacter({ raw: "/a b" }); // true
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
type UUID = string;
|
|
2
1
|
import type { VerifiedOrigin } from "./types.js";
|
|
3
2
|
export interface VerifiedOriginRequestContext {
|
|
4
|
-
workspaceId:
|
|
5
|
-
siteId?:
|
|
3
|
+
workspaceId: string;
|
|
4
|
+
siteId?: string;
|
|
6
5
|
locale?: string;
|
|
7
6
|
}
|
|
8
7
|
export interface RedirectTargetContext {
|
|
9
|
-
workspaceId:
|
|
10
|
-
siteId?:
|
|
8
|
+
workspaceId: string;
|
|
9
|
+
siteId?: string;
|
|
11
10
|
originKey?: string;
|
|
12
11
|
}
|
|
13
12
|
export interface EgressTargetContext {
|
|
14
|
-
workspaceId:
|
|
15
|
-
siteId?:
|
|
13
|
+
workspaceId: string;
|
|
14
|
+
siteId?: string;
|
|
16
15
|
}
|
|
17
16
|
export interface OriginRegistryPort {
|
|
18
17
|
canonicalOrigin(ctx: VerifiedOriginRequestContext): Promise<VerifiedOrigin>;
|
|
@@ -27,14 +26,13 @@ export interface OriginRegistryPort {
|
|
|
27
26
|
}
|
|
28
27
|
export interface OriginSettingRepoPort {
|
|
29
28
|
findByWorkspaceId(required: {
|
|
30
|
-
workspaceId:
|
|
29
|
+
workspaceId: string;
|
|
31
30
|
}): Promise<VerifiedOrigin | null>;
|
|
32
31
|
findRedirectAllowlist(required: {
|
|
33
|
-
workspaceId:
|
|
32
|
+
workspaceId: string;
|
|
34
33
|
}): Promise<string[]>;
|
|
35
34
|
findEgressAllowlist(required: {
|
|
36
|
-
workspaceId:
|
|
35
|
+
workspaceId: string;
|
|
37
36
|
}): Promise<string[]>;
|
|
38
37
|
}
|
|
39
|
-
export {};
|
|
40
38
|
//# sourceMappingURL=ports.d.ts.map
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
type UUID = string;
|
|
2
1
|
import type { OriginSettingRepoPort } from "./ports.js";
|
|
3
2
|
import { type VerifiedOrigin } from "./types.js";
|
|
4
3
|
export interface OriginSettingSeed {
|
|
5
|
-
workspaceId:
|
|
4
|
+
workspaceId: string;
|
|
6
5
|
origin: VerifiedOrigin;
|
|
7
6
|
/** Exact-match hosts trusted for cross-origin redirects; independent of third-party egress. */
|
|
8
7
|
redirectAllowlist?: string[];
|
|
@@ -21,14 +20,13 @@ export declare class InMemoryOriginSettingRepo implements OriginSettingRepoPort
|
|
|
21
20
|
seeds: readonly OriginSettingSeed[];
|
|
22
21
|
});
|
|
23
22
|
findByWorkspaceId({ workspaceId }: {
|
|
24
|
-
workspaceId:
|
|
23
|
+
workspaceId: string;
|
|
25
24
|
}): Promise<VerifiedOrigin | null>;
|
|
26
25
|
findRedirectAllowlist({ workspaceId }: {
|
|
27
|
-
workspaceId:
|
|
26
|
+
workspaceId: string;
|
|
28
27
|
}): Promise<string[]>;
|
|
29
28
|
findEgressAllowlist({ workspaceId }: {
|
|
30
|
-
workspaceId:
|
|
29
|
+
workspaceId: string;
|
|
31
30
|
}): Promise<string[]>;
|
|
32
31
|
}
|
|
33
|
-
export {};
|
|
34
32
|
//# sourceMappingURL=repo.memory.d.ts.map
|
|
@@ -73,11 +73,10 @@ function resolveDotSegments(path) {
|
|
|
73
73
|
for (const segment of path.split("/")) {
|
|
74
74
|
if (segment === "" || segment === ".")
|
|
75
75
|
continue;
|
|
76
|
-
if (segment === "..")
|
|
76
|
+
if (segment === "..")
|
|
77
77
|
out.pop();
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
out.push(segment);
|
|
78
|
+
else
|
|
79
|
+
out.push(segment);
|
|
81
80
|
}
|
|
82
81
|
return `/${out.join("/")}`;
|
|
83
82
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
type ISODateTime = string;
|
|
2
1
|
/** Canonical links, redirect checks and egress decisions must use stored trust evidence,
|
|
3
2
|
* never the raw request Host/:authority, which is attacker-controlled. */
|
|
4
3
|
export type OriginScheme = "https" | "http";
|
|
@@ -9,7 +8,7 @@ export interface VerifiedOrigin {
|
|
|
9
8
|
host: string;
|
|
10
9
|
port?: number;
|
|
11
10
|
basePath?: string;
|
|
12
|
-
verifiedAt:
|
|
11
|
+
verifiedAt: string;
|
|
13
12
|
source: OriginSource;
|
|
14
13
|
}
|
|
15
14
|
export declare class InsecureOriginSourceError extends Error {
|
|
@@ -24,10 +23,11 @@ export declare class OriginNotVerifiedError extends Error {
|
|
|
24
23
|
message: string;
|
|
25
24
|
});
|
|
26
25
|
}
|
|
27
|
-
/** Copy
|
|
28
|
-
*
|
|
26
|
+
/** Copy evidence, refusing HTTP public origins and treating public loopback origins as unset.
|
|
27
|
+
* Both writers and registry reads use this boundary, including reads of legacy persisted rows.
|
|
28
|
+
* @throws InsecureOriginSourceError for HTTP public evidence; OriginNotVerifiedError for loopback public evidence.
|
|
29
|
+
* @complexity O(host bytes) time and space; pure, with no ownership or reachability probe.
|
|
29
30
|
* @example createVerifiedOrigin({ scheme: "https", host: "example.com", verifiedAt, source: "workspace-setting" });
|
|
30
31
|
*/
|
|
31
|
-
export declare function createVerifiedOrigin(input: VerifiedOrigin): VerifiedOrigin;
|
|
32
|
-
export {};
|
|
32
|
+
export declare function createVerifiedOrigin(input: VerifiedOrigin, _options?: Record<string, never>): VerifiedOrigin;
|
|
33
33
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isLoopbackHost } from "./loopback-host.js";
|
|
1
2
|
export class InsecureOriginSourceError extends Error {
|
|
2
3
|
constructor({ message }) { super(message); }
|
|
3
4
|
}
|
|
@@ -6,11 +7,13 @@ export class InsecureOriginSourceError extends Error {
|
|
|
6
7
|
export class OriginNotVerifiedError extends Error {
|
|
7
8
|
constructor({ message }) { super(message); }
|
|
8
9
|
}
|
|
9
|
-
/** Copy
|
|
10
|
-
*
|
|
10
|
+
/** Copy evidence, refusing HTTP public origins and treating public loopback origins as unset.
|
|
11
|
+
* Both writers and registry reads use this boundary, including reads of legacy persisted rows.
|
|
12
|
+
* @throws InsecureOriginSourceError for HTTP public evidence; OriginNotVerifiedError for loopback public evidence.
|
|
13
|
+
* @complexity O(host bytes) time and space; pure, with no ownership or reachability probe.
|
|
11
14
|
* @example createVerifiedOrigin({ scheme: "https", host: "example.com", verifiedAt, source: "workspace-setting" });
|
|
12
15
|
*/
|
|
13
|
-
export function createVerifiedOrigin(input) {
|
|
16
|
+
export function createVerifiedOrigin(input, _options = {}) {
|
|
14
17
|
// Repositories and other adapters must construct evidence through this function; an object
|
|
15
18
|
// literal can bypass the scheme/source invariant even though it satisfies the structural type.
|
|
16
19
|
if (input.scheme === "http" && input.source !== "dev-capability") {
|
|
@@ -18,6 +21,10 @@ export function createVerifiedOrigin(input) {
|
|
|
18
21
|
message: `origin scheme 'http' is only legal for source 'dev-capability' (got source '${input.source}')`
|
|
19
22
|
});
|
|
20
23
|
}
|
|
24
|
+
// Explicit dev capabilities may address a listener; a public site URL never may.
|
|
25
|
+
if (input.source === "workspace-setting" && isLoopbackHost({ host: input.host })) {
|
|
26
|
+
throw new OriginNotVerifiedError({ message: "a loopback host is not a verified public origin" });
|
|
27
|
+
}
|
|
21
28
|
return { ...input };
|
|
22
29
|
}
|
|
23
30
|
//# sourceMappingURL=types.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/http-kit",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.16",
|
|
4
4
|
"description": "Generic Express transport primitives, request parsing, response serialization, origin guards and route-pack mounting.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -71,25 +71,14 @@
|
|
|
71
71
|
"@types/express": "^4.17.21",
|
|
72
72
|
"@vitest/coverage-v8": "^2.1.9",
|
|
73
73
|
"express": "^4.21.0",
|
|
74
|
-
"@jini-ai/core": "0.6.
|
|
75
|
-
"@jini-ai/platform": "0.6.
|
|
76
|
-
"@jini-ai/protocol": "0.6.
|
|
74
|
+
"@jini-ai/core": "0.6.16",
|
|
75
|
+
"@jini-ai/platform": "0.6.16",
|
|
76
|
+
"@jini-ai/protocol": "0.6.16"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@jini-ai/
|
|
80
|
-
"@jini-ai/core": "^0.6.
|
|
81
|
-
|
|
82
|
-
"peerDependencies": {
|
|
83
|
-
"@jini-ai/platform": "^0.6.15-rc.2",
|
|
84
|
-
"express": "^4.21.0 || ^5.0.0"
|
|
85
|
-
},
|
|
86
|
-
"peerDependenciesMeta": {
|
|
87
|
-
"@jini-ai/platform": {
|
|
88
|
-
"optional": true
|
|
89
|
-
},
|
|
90
|
-
"express": {
|
|
91
|
-
"optional": true
|
|
92
|
-
}
|
|
79
|
+
"@jini-ai/platform": "^0.6.16",
|
|
80
|
+
"@jini-ai/core": "^0.6.16",
|
|
81
|
+
"@jini-ai/protocol": "^0.6.16"
|
|
93
82
|
},
|
|
94
83
|
"scripts": {
|
|
95
84
|
"build": "tsc -p tsconfig.json",
|