@jini-ai/http-kit 0.6.15-rc.1 → 0.6.15

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.
@@ -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
- if (req.method !== 'GET' || !isPortlessLoopbackOrigin(String(origin))) {
260
- res.status(403).json({ error: 'Cross-origin requests are not allowed' });
261
- return;
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 || parsed.username || parsed.password)
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
  }
@@ -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 } });
package/dist/sse.js CHANGED
@@ -92,7 +92,7 @@ export function createSseChannel({ res }, options = {}) {
92
92
  }
93
93
  if (wroteOk === false)
94
94
  writable = false;
95
- if (options.isEndEvent?.({ event })) {
95
+ if (isTerminalEvent(event)) {
96
96
  finish();
97
97
  return;
98
98
  }
@@ -100,6 +100,7 @@ export function createSseChannel({ res }, options = {}) {
100
100
  if (ending)
101
101
  end();
102
102
  };
103
+ const isTerminalEvent = (event) => options.isEndEvent?.({ event });
103
104
  const enqueue = ({ event }) => {
104
105
  if (closed || ending)
105
106
  return;
@@ -1,3 +1,4 @@
1
+ import { trimCharsEnd } from '@jini-ai/core/primitives';
1
2
  import { hasForbiddenRawUrlCharacter } from "./origin.js";
2
3
  import { createVerifiedOrigin } from "./types.js";
3
4
  /**
@@ -59,7 +60,7 @@ function buildConfiguredOrigin(url, now) {
59
60
  };
60
61
  if (url.port !== "")
61
62
  candidate.port = Number(url.port);
62
- const basePath = url.pathname.replace(/\/+$/, "");
63
+ const basePath = trimCharsEnd({ text: url.pathname, chars: "/" });
63
64
  if (basePath !== "")
64
65
  candidate.basePath = basePath;
65
66
  return createVerifiedOrigin(candidate);
@@ -1,6 +1,5 @@
1
1
  import type { VerifiedOriginRequestContext, OriginRegistryPort, OriginSettingRepoPort, RedirectTargetContext, EgressTargetContext } from "./ports.js";
2
- import { OriginNotVerifiedError, type VerifiedOrigin } from "./types.js";
3
- export { OriginNotVerifiedError };
2
+ import { type VerifiedOrigin } from "./types.js";
4
3
  export interface NormalizedTarget {
5
4
  scheme: "https" | "http";
6
5
  host: string;
@@ -1,5 +1,4 @@
1
1
  import { OriginNotVerifiedError, createVerifiedOrigin } from "./types.js";
2
- export { OriginNotVerifiedError };
3
2
  /**
4
3
  * Check the original string before the WHATWG parser strips whitespace/controls or converts a
5
4
  * backslash to a slash. A stored backslash plus a request tail can become a browser-followed
@@ -7,7 +6,7 @@ export { OriginNotVerifiedError };
7
6
  * redirect reads must use this same raw predicate; checking a reserialized url.href checks too late.
8
7
  */
9
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.
10
- const FORBIDDEN_RAW_CHARS = /[\\\s\x00-\x1F\x7F]/;
9
+ const FORBIDDEN_RAW_CHARS = /[\\\s\x00-\x08\x0E-\x1F\x7F]/;
11
10
  /** Reject parser-ambiguous backslashes, whitespace and controls before URL normalization.
12
11
  * @complexity O(raw.length) time, O(1) space; pure.
13
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: UUID;
5
- siteId?: UUID;
3
+ workspaceId: string;
4
+ siteId?: string;
6
5
  locale?: string;
7
6
  }
8
7
  export interface RedirectTargetContext {
9
- workspaceId: UUID;
10
- siteId?: UUID;
8
+ workspaceId: string;
9
+ siteId?: string;
11
10
  originKey?: string;
12
11
  }
13
12
  export interface EgressTargetContext {
14
- workspaceId: UUID;
15
- siteId?: UUID;
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: UUID;
29
+ workspaceId: string;
31
30
  }): Promise<VerifiedOrigin | null>;
32
31
  findRedirectAllowlist(required: {
33
- workspaceId: UUID;
32
+ workspaceId: string;
34
33
  }): Promise<string[]>;
35
34
  findEgressAllowlist(required: {
36
- workspaceId: UUID;
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: UUID;
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: UUID;
23
+ workspaceId: string;
25
24
  }): Promise<VerifiedOrigin | null>;
26
25
  findRedirectAllowlist({ workspaceId }: {
27
- workspaceId: UUID;
26
+ workspaceId: string;
28
27
  }): Promise<string[]>;
29
28
  findEgressAllowlist({ workspaceId }: {
30
- workspaceId: UUID;
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
- continue;
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: ISODateTime;
11
+ verifiedAt: string;
13
12
  source: OriginSource;
14
13
  }
15
14
  export declare class InsecureOriginSourceError extends Error {
@@ -29,5 +28,4 @@ export declare class OriginNotVerifiedError extends Error {
29
28
  * @example createVerifiedOrigin({ scheme: "https", host: "example.com", verifiedAt, source: "workspace-setting" });
30
29
  */
31
30
  export declare function createVerifiedOrigin(input: VerifiedOrigin): VerifiedOrigin;
32
- export {};
33
31
  //# sourceMappingURL=types.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/http-kit",
3
- "version": "0.6.15-rc.1",
3
+ "version": "0.6.15",
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,16 +71,16 @@
71
71
  "@types/express": "^4.17.21",
72
72
  "@vitest/coverage-v8": "^2.1.9",
73
73
  "express": "^4.21.0",
74
- "@jini-ai/protocol": "0.6.15-rc.1",
75
- "@jini-ai/core": "0.6.15-rc.1",
76
- "@jini-ai/platform": "0.6.15-rc.1"
74
+ "@jini-ai/core": "0.6.15",
75
+ "@jini-ai/protocol": "0.6.15",
76
+ "@jini-ai/platform": "0.6.15"
77
77
  },
78
78
  "dependencies": {
79
- "@jini-ai/core": "^0.6.15-rc.1",
80
- "@jini-ai/protocol": "^0.6.15-rc.1"
79
+ "@jini-ai/protocol": "^0.6.15",
80
+ "@jini-ai/core": "^0.6.15"
81
81
  },
82
82
  "peerDependencies": {
83
- "@jini-ai/platform": "^0.6.15-rc.1",
83
+ "@jini-ai/platform": "^0.6.10",
84
84
  "express": "^4.21.0 || ^5.0.0"
85
85
  },
86
86
  "peerDependenciesMeta": {