@openclaw/lobster 2026.9.6 → 2026.9.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.
Files changed (64) hide show
  1. package/assets/icon.png +0 -0
  2. package/dist/index.js +8 -294
  3. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/README.md +1 -0
  4. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/SECURITY.md +62 -13
  5. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/index.js +40 -9
  6. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/lib/schemes.js +76 -16
  7. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/lib/utils.js +54 -10
  8. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/package.json +1 -1
  9. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/test/fixtures/uri-js-parse.json +1 -0
  10. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/test/ipv6-validation.test.js +130 -0
  11. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/test/mailto-authority-security.test.js +125 -0
  12. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/test/mailto-field-name-security.test.js +151 -0
  13. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/test/security-normalization.test.js +38 -0
  14. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/types/index.d.ts +16 -0
  15. package/node_modules/@clawdbot/lobster/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +19 -18
  16. package/node_modules/@clawdbot/lobster/node_modules/yaml/browser/dist/nodes/Alias.js +25 -23
  17. package/node_modules/@clawdbot/lobster/node_modules/yaml/dist/compose/resolve-flow-scalar.js +19 -18
  18. package/node_modules/@clawdbot/lobster/node_modules/yaml/dist/nodes/Alias.js +25 -23
  19. package/node_modules/@clawdbot/lobster/node_modules/yaml/package.json +1 -1
  20. package/node_modules/typebox/build/compile/code.mjs +1 -2
  21. package/node_modules/typebox/build/compile/validator.mjs +5 -1
  22. package/node_modules/typebox/build/format/iri.mjs +16 -9
  23. package/node_modules/typebox/build/guard/emit.mjs +2 -2
  24. package/node_modules/typebox/build/guard/guard.d.mts +7 -5
  25. package/node_modules/typebox/build/guard/guard.mjs +14 -9
  26. package/node_modules/typebox/build/guard/index.mjs +6 -0
  27. package/node_modules/typebox/build/guard/unicode/unicode.d.mts +6 -0
  28. package/node_modules/typebox/build/guard/unicode/unicode.mjs +35 -0
  29. package/node_modules/typebox/build/guard/{string.mjs → unicode/unicode_segment.mjs} +16 -19
  30. package/node_modules/typebox/build/schema/build.mjs +2 -3
  31. package/node_modules/typebox/build/schema/engine/_pathing.d.mts +1 -0
  32. package/node_modules/typebox/build/schema/engine/_pathing.mjs +11 -0
  33. package/node_modules/typebox/build/schema/engine/_refine.mjs +13 -5
  34. package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +2 -1
  35. package/node_modules/typebox/build/schema/engine/dependencies.mjs +2 -1
  36. package/node_modules/typebox/build/schema/engine/dependentSchemas.mjs +2 -1
  37. package/node_modules/typebox/build/schema/engine/dynamicRef.d.mts +1 -1
  38. package/node_modules/typebox/build/schema/engine/dynamicRef.mjs +2 -2
  39. package/node_modules/typebox/build/schema/engine/format.mjs +9 -2
  40. package/node_modules/typebox/build/schema/engine/patternProperties.mjs +3 -2
  41. package/node_modules/typebox/build/schema/engine/properties.mjs +3 -2
  42. package/node_modules/typebox/build/schema/engine/propertyNames.mjs +2 -1
  43. package/node_modules/typebox/build/schema/engine/recursiveRef.d.mts +1 -1
  44. package/node_modules/typebox/build/schema/engine/recursiveRef.mjs +2 -2
  45. package/node_modules/typebox/build/schema/engine/ref.d.mts +1 -1
  46. package/node_modules/typebox/build/schema/engine/ref.mjs +2 -2
  47. package/node_modules/typebox/build/schema/engine/schema.mjs +24 -24
  48. package/node_modules/typebox/build/schema/parse.mjs +3 -0
  49. package/node_modules/typebox/build/schema/pointer/pointer.d.mts +1 -6
  50. package/node_modules/typebox/build/schema/pointer/pointer.mjs +47 -64
  51. package/node_modules/typebox/build/system/settings/internal.d.mts +2 -0
  52. package/node_modules/typebox/build/system/settings/internal.mjs +20 -0
  53. package/node_modules/typebox/build/system/settings/settings.d.mts +11 -0
  54. package/node_modules/typebox/build/system/settings/settings.mjs +14 -0
  55. package/node_modules/typebox/build/type/extends/inference.d.mts +1 -1
  56. package/node_modules/typebox/build/type/extends/inference.mjs +15 -2
  57. package/node_modules/typebox/build/type/extends/tuple.d.mts +2 -1
  58. package/node_modules/typebox/build/type/extends/tuple.mjs +21 -1
  59. package/node_modules/typebox/build/value/parse/parse.mjs +10 -4
  60. package/node_modules/typebox/package.json +1 -1
  61. package/node_modules/typebox/readme.md +3 -1
  62. package/package.json +5 -5
  63. package/dist/runtime-api.js +0 -3
  64. /package/node_modules/typebox/build/guard/{string.d.mts → unicode/unicode_segment.d.mts} +0 -0
package/assets/icon.png CHANGED
Binary file
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
2
- import { optionalNonNegativeIntegerSchema, optionalPositiveIntegerSchema } from "openclaw/plugin-sdk/channel-actions";
3
- import { readNonNegativeIntegerParam, readPositiveIntegerParam } from "openclaw/plugin-sdk/param-readers";
2
+ import { optionalPositiveIntegerSchema } from "openclaw/plugin-sdk/channel-actions";
3
+ import { readPositiveIntegerParam } from "openclaw/plugin-sdk/param-readers";
4
4
  import { jsonResult } from "openclaw/plugin-sdk/tool-results";
5
5
  import { Type } from "typebox";
6
6
  import { stat } from "node:fs/promises";
7
7
  import path from "node:path";
8
8
  import { Readable, Writable } from "node:stream";
9
- import { toErrorObject } from "openclaw/plugin-sdk/error-runtime";
9
+ import { extractErrorCode, toErrorObject } from "openclaw/plugin-sdk/error-runtime";
10
10
  import { isPathInside } from "openclaw/plugin-sdk/file-access-runtime";
11
11
  //#region extensions/lobster/src/lobster-runner.ts
12
12
  const workflowExts = /* @__PURE__ */ new Set([
@@ -53,9 +53,6 @@ function normalizeEnvelope(envelope, maxStdoutBytes) {
53
53
  if (Buffer.byteLength(JSON.stringify(normalized, null, 2), "utf8") > maxStdoutBytes) throw new Error("lobster runtime result exceeded maxStdoutBytes");
54
54
  return normalized;
55
55
  }
56
- function isMissingPathError(error) {
57
- return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
58
- }
59
56
  async function detectWorkflowFile(candidate, cwd) {
60
57
  const trimmed = candidate.trim();
61
58
  if (!trimmed || trimmed.includes("|") || !workflowExts.has(path.extname(trimmed).toLowerCase())) return null;
@@ -64,7 +61,7 @@ async function detectWorkflowFile(candidate, cwd) {
64
61
  if (!(await stat(resolved)).isFile()) throw new Error("Workflow path is not a file");
65
62
  return resolved;
66
63
  } catch (error) {
67
- if (/\s/.test(trimmed) && isMissingPathError(error)) return null;
64
+ if (/\s/.test(trimmed) && extractErrorCode(error) === "ENOENT") return null;
68
65
  throw error;
69
66
  }
70
67
  }
@@ -153,257 +150,7 @@ function createEmbeddedLobsterRunner(options) {
153
150
  } };
154
151
  }
155
152
  //#endregion
156
- //#region extensions/lobster/src/lobster-taskflow.ts
157
- function toJsonLike(value, seen = /* @__PURE__ */ new WeakSet()) {
158
- if (value === null) return null;
159
- if (typeof value === "number") return Number.isFinite(value) ? value : String(value);
160
- if (typeof value === "bigint") return value.toString();
161
- if (typeof value === "boolean" || typeof value === "string") return value;
162
- if (typeof value !== "object") return null;
163
- if (value instanceof Date) return value.toISOString();
164
- if (seen.has(value)) return "[Circular]";
165
- seen.add(value);
166
- if (Array.isArray(value)) {
167
- const jsonArray = value.map((item) => toJsonLike(item, seen));
168
- seen.delete(value);
169
- return jsonArray;
170
- }
171
- const jsonObject = {};
172
- for (const [key, entry] of Object.entries(value)) {
173
- if (entry === void 0 || typeof entry === "function" || typeof entry === "symbol") continue;
174
- jsonObject[key] = toJsonLike(entry, seen);
175
- }
176
- seen.delete(value);
177
- return jsonObject;
178
- }
179
- function buildApprovalWaitState(envelope) {
180
- const approval = envelope.requiresApproval;
181
- return {
182
- kind: "lobster_approval",
183
- prompt: approval ? approval.prompt : "",
184
- items: approval ? approval.items.map((item) => toJsonLike(item)) : [],
185
- ...approval?.resumeToken ? { resumeToken: approval.resumeToken } : {},
186
- ...approval?.approvalId ? { approvalId: approval.approvalId } : {}
187
- };
188
- }
189
- async function executeManagedLobsterFlow(params, flow) {
190
- try {
191
- const envelope = await params.runner.run(params.runnerParams);
192
- if (envelope.ok && envelope.status === "cancelled") try {
193
- const mutation = await params.taskFlow.cancel({
194
- flowId: flow.flowId,
195
- cfg: params.config
196
- });
197
- return mutation.cancelled ? {
198
- ok: true,
199
- envelope,
200
- flow,
201
- mutation
202
- } : {
203
- ok: false,
204
- flow,
205
- mutation,
206
- error: /* @__PURE__ */ new Error(`TaskFlow cancellation failed: ${mutation.reason ?? "unknown"}`)
207
- };
208
- } catch (error) {
209
- return {
210
- ok: false,
211
- flow,
212
- error: error instanceof Error ? error : new Error(String(error))
213
- };
214
- }
215
- const flowMutation = {
216
- flowId: flow.flowId,
217
- expectedRevision: flow.revision
218
- };
219
- if (!envelope.ok) return {
220
- ok: false,
221
- flow,
222
- mutation: await params.taskFlow.fail(flowMutation),
223
- error: new Error(envelope.error.message)
224
- };
225
- return {
226
- ok: true,
227
- envelope,
228
- flow,
229
- mutation: envelope.status === "needs_approval" ? await params.taskFlow.setWaiting({
230
- ...flowMutation,
231
- currentStep: params.waitingStep ?? "await_lobster_approval",
232
- waitJson: buildApprovalWaitState(envelope)
233
- }) : await params.taskFlow.finish(flowMutation)
234
- };
235
- } catch (error) {
236
- const err = error instanceof Error ? error : new Error(String(error));
237
- try {
238
- return {
239
- ok: false,
240
- flow,
241
- mutation: await params.taskFlow.fail({
242
- flowId: flow.flowId,
243
- expectedRevision: flow.revision
244
- }),
245
- error: err
246
- };
247
- } catch {
248
- return {
249
- ok: false,
250
- flow,
251
- error: err
252
- };
253
- }
254
- }
255
- }
256
- async function runManagedLobsterFlow(params) {
257
- const createFlowParams = {
258
- controllerId: params.controllerId,
259
- goal: params.goal,
260
- currentStep: params.currentStep ?? "run_lobster",
261
- ...params.stateJson !== void 0 ? { stateJson: params.stateJson } : {}
262
- };
263
- const flow = await params.taskFlow.tryCreateManaged(createFlowParams);
264
- if (!flow) return {
265
- ok: false,
266
- error: /* @__PURE__ */ new Error("TaskFlow persistence failed.")
267
- };
268
- return await executeManagedLobsterFlow(params, flow);
269
- }
270
- async function resumeManagedLobsterFlow(params) {
271
- const saved = await params.taskFlow.get(params.flowId);
272
- if (!saved || saved.syncMode !== "managed" || saved.endedAt !== void 0 || saved.cancelRequestedAt !== void 0 || saved.status !== "waiting" && saved.status !== "blocked") return {
273
- ok: false,
274
- error: /* @__PURE__ */ new Error("TaskFlow has no resumable Lobster checkpoint.")
275
- };
276
- const wait = saved.waitJson;
277
- if (!wait || typeof wait !== "object" || Array.isArray(wait) || wait.kind !== "lobster_approval") return {
278
- ok: false,
279
- error: /* @__PURE__ */ new Error("TaskFlow is not waiting for Lobster approval.")
280
- };
281
- const token = typeof wait.resumeToken === "string" ? wait.resumeToken : void 0;
282
- const approvalId = typeof wait.approvalId === "string" ? wait.approvalId : void 0;
283
- if (!token && !approvalId || params.runnerParams.token !== void 0 && params.runnerParams.token.trim() !== token || params.runnerParams.approvalId !== void 0 && params.runnerParams.approvalId.trim() !== approvalId) return {
284
- ok: false,
285
- error: /* @__PURE__ */ new Error("Lobster checkpoint does not match the selected TaskFlow.")
286
- };
287
- const runnerParams = {
288
- ...params.runnerParams,
289
- ...params.runnerParams.token || params.runnerParams.approvalId ? {} : token ? { token } : { approvalId }
290
- };
291
- if (saved.revision !== params.expectedRevision) return {
292
- ok: false,
293
- error: /* @__PURE__ */ new Error("TaskFlow resume failed: revision_conflict")
294
- };
295
- const resumed = await params.taskFlow.resume({
296
- flowId: params.flowId,
297
- expectedRevision: params.expectedRevision,
298
- status: "running",
299
- currentStep: params.currentStep ?? "resume_lobster"
300
- });
301
- if (!resumed.applied) return {
302
- ok: false,
303
- mutation: resumed,
304
- error: /* @__PURE__ */ new Error(`TaskFlow resume failed: ${resumed.code}`)
305
- };
306
- return await executeManagedLobsterFlow({
307
- ...params,
308
- runnerParams
309
- }, resumed.flow);
310
- }
311
- //#endregion
312
153
  //#region extensions/lobster/src/lobster-tool.ts
313
- function readOptionalTrimmedString(value, fieldName) {
314
- if (value === void 0) return;
315
- if (typeof value !== "string") throw new Error(`${fieldName} must be a string`);
316
- const trimmed = value.trim();
317
- return trimmed ? trimmed : void 0;
318
- }
319
- function readOptionalNumber(value, fieldName) {
320
- return readNonNegativeIntegerParam({ [fieldName]: value }, fieldName, { message: `${fieldName} must be a non-negative integer` });
321
- }
322
- function readOptionalBoolean(value, fieldName) {
323
- if (value === void 0) return;
324
- if (typeof value !== "boolean") throw new Error(`${fieldName} must be a boolean`);
325
- return value;
326
- }
327
- function parseOptionalFlowStateJson(value) {
328
- if (value === void 0) return;
329
- if (typeof value !== "string") throw new Error("flowStateJson must be a JSON string");
330
- const trimmed = value.trim();
331
- if (!trimmed) return;
332
- try {
333
- return JSON.parse(trimmed);
334
- } catch {
335
- throw new Error("flowStateJson must be valid JSON");
336
- }
337
- }
338
- function isEmptyJsonObject(value) {
339
- return value !== void 0 && value !== null && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0;
340
- }
341
- function parseManagedFlowParams(action, params, runnerParams) {
342
- if (action === "run") {
343
- const controllerId = readOptionalTrimmedString(params.flowControllerId, "flowControllerId");
344
- const goal = readOptionalTrimmedString(params.flowGoal, "flowGoal");
345
- const currentStep = readOptionalTrimmedString(params.flowCurrentStep, "flowCurrentStep");
346
- const waitingStep = readOptionalTrimmedString(params.flowWaitingStep, "flowWaitingStep");
347
- const stateJson = parseOptionalFlowStateJson(params.flowStateJson);
348
- const resumeFlowId = readOptionalTrimmedString(params.flowId, "flowId");
349
- const resumeRevision = readOptionalNumber(params.flowExpectedRevision, "flowExpectedRevision");
350
- const stateJsonSignalsRunMode = stateJson !== void 0 && !isEmptyJsonObject(stateJson);
351
- if (resumeFlowId !== void 0 || resumeRevision !== void 0 && resumeRevision !== 0) throw new Error("run action does not accept flowId or flowExpectedRevision");
352
- if (controllerId === void 0 && goal === void 0 && currentStep === void 0 && waitingStep === void 0 && !stateJsonSignalsRunMode) return null;
353
- if (!controllerId) throw new Error("flowControllerId required when using managed TaskFlow run mode");
354
- if (!goal) throw new Error("flowGoal required when using managed TaskFlow run mode");
355
- return {
356
- action,
357
- controllerId,
358
- goal,
359
- ...currentStep ? { currentStep } : {},
360
- ...waitingStep ? { waitingStep } : {},
361
- ...stateJson !== void 0 ? { stateJson } : {}
362
- };
363
- }
364
- const flowId = readOptionalTrimmedString(params.flowId, "flowId");
365
- const expectedRevision = readOptionalNumber(params.flowExpectedRevision, "flowExpectedRevision");
366
- const currentStep = readOptionalTrimmedString(params.flowCurrentStep, "flowCurrentStep");
367
- const waitingStep = readOptionalTrimmedString(params.flowWaitingStep, "flowWaitingStep");
368
- const token = readOptionalTrimmedString(params.token, "token");
369
- const approvalId = readOptionalTrimmedString(params.approvalId, "approvalId");
370
- const approve = readOptionalBoolean(params.approve, "approve");
371
- const runControllerId = readOptionalTrimmedString(params.flowControllerId, "flowControllerId");
372
- const runGoal = readOptionalTrimmedString(params.flowGoal, "flowGoal");
373
- const stateJson = parseOptionalFlowStateJson(params.flowStateJson);
374
- const stateJsonDisallowed = stateJson !== void 0 && !isEmptyJsonObject(stateJson);
375
- if (runControllerId !== void 0 || runGoal !== void 0 || stateJsonDisallowed) throw new Error("resume action does not accept flowControllerId, flowGoal, or flowStateJson");
376
- if (!(flowId !== void 0 || expectedRevision !== void 0 && expectedRevision !== 0 || currentStep !== void 0 || waitingStep !== void 0)) return null;
377
- if (!flowId) throw new Error("flowId required when using managed TaskFlow resume mode");
378
- if (expectedRevision === void 0) throw new Error("flowExpectedRevision required when using managed TaskFlow resume mode");
379
- const credentialParams = token ? { token: runnerParams.token ?? token } : approvalId ? { approvalId: runnerParams.approvalId ?? approvalId } : null;
380
- if (approve === void 0) throw new Error("approve required when using managed TaskFlow resume mode");
381
- return {
382
- action,
383
- flowId,
384
- expectedRevision,
385
- ...currentStep ? { currentStep } : {},
386
- ...waitingStep ? { waitingStep } : {},
387
- runnerParams: {
388
- ...runnerParams,
389
- ...credentialParams,
390
- action,
391
- approve
392
- }
393
- };
394
- }
395
- function resolveManagedFlowToolResult(result) {
396
- if (!result.ok) throw result.error;
397
- return jsonResult({
398
- ...result.envelope,
399
- flow: result.flow,
400
- mutation: result.mutation
401
- });
402
- }
403
- function requireTaskFlowRuntime(taskFlow, action) {
404
- if (!taskFlow) throw new Error(`Managed TaskFlow ${action} mode requires a bound taskFlow runtime`);
405
- return taskFlow;
406
- }
407
154
  function createLobsterTool(api, options) {
408
155
  const runner = options?.runner ?? createEmbeddedLobsterRunner();
409
156
  return {
@@ -419,14 +166,7 @@ function createLobsterTool(api, options) {
419
166
  approve: Type.Optional(Type.Boolean()),
420
167
  cwd: Type.Optional(Type.String({ description: "Relative working directory (optional). Must stay within the gateway working directory." })),
421
168
  timeoutMs: optionalPositiveIntegerSchema(),
422
- maxStdoutBytes: optionalPositiveIntegerSchema(),
423
- flowControllerId: Type.Optional(Type.String()),
424
- flowGoal: Type.Optional(Type.String()),
425
- flowStateJson: Type.Optional(Type.String()),
426
- flowId: Type.Optional(Type.String({ description: "Managed flow to resume. Its saved approval checkpoint is used when token and approvalId are omitted." })),
427
- flowExpectedRevision: optionalNonNegativeIntegerSchema(),
428
- flowCurrentStep: Type.Optional(Type.String()),
429
- flowWaitingStep: Type.Optional(Type.String())
169
+ maxStdoutBytes: optionalPositiveIntegerSchema()
430
170
  }),
431
171
  async execute(_id, params) {
432
172
  const action = typeof params.action === "string" ? params.action.trim() : "";
@@ -447,29 +187,6 @@ function createLobsterTool(api, options) {
447
187
  timeoutMs,
448
188
  maxStdoutBytes
449
189
  };
450
- const taskFlow = options?.taskFlow;
451
- const flowParams = parseManagedFlowParams(action, params, runnerParams);
452
- if (flowParams?.action === "run") return resolveManagedFlowToolResult(await runManagedLobsterFlow({
453
- taskFlow: requireTaskFlowRuntime(taskFlow, "run"),
454
- config: api.config,
455
- runner,
456
- runnerParams,
457
- controllerId: flowParams.controllerId,
458
- goal: flowParams.goal,
459
- ...flowParams.stateJson !== void 0 ? { stateJson: flowParams.stateJson } : {},
460
- ...flowParams.currentStep ? { currentStep: flowParams.currentStep } : {},
461
- ...flowParams.waitingStep ? { waitingStep: flowParams.waitingStep } : {}
462
- }));
463
- if (flowParams?.action === "resume") return resolveManagedFlowToolResult(await resumeManagedLobsterFlow({
464
- taskFlow: requireTaskFlowRuntime(taskFlow, "resume"),
465
- config: api.config,
466
- runner,
467
- runnerParams: flowParams.runnerParams,
468
- flowId: flowParams.flowId,
469
- expectedRevision: flowParams.expectedRevision,
470
- ...flowParams.currentStep ? { currentStep: flowParams.currentStep } : {},
471
- ...flowParams.waitingStep ? { waitingStep: flowParams.waitingStep } : {}
472
- }));
473
190
  const envelope = await runner.run(runnerParams);
474
191
  if (!envelope.ok) throw new Error(envelope.error.message);
475
192
  return jsonResult(envelope);
@@ -483,13 +200,10 @@ var lobster_default = definePluginEntry({
483
200
  name: "Lobster",
484
201
  description: "Optional local shell helper tools",
485
202
  register(api) {
486
- api.registerTool(((ctx) => {
203
+ api.registerTool((ctx) => {
487
204
  if (ctx.sandboxed) return null;
488
- return createLobsterTool(api, { taskFlow: api.runtime && ctx.sessionKey ? {
489
- ...api.runtime.tasks.async.managedFlows.fromToolContext(ctx),
490
- cancel: api.runtime.tasks.managedFlows.fromToolContext(ctx).cancel
491
- } : void 0 });
492
- }), { optional: true });
205
+ return createLobsterTool(api);
206
+ }, { optional: true });
493
207
  }
494
208
  });
495
209
  //#endregion
@@ -99,6 +99,7 @@ fast-uri supports inserting custom [scheme](https://en.wikipedia.org/wiki/URI_sc
99
99
  * wss \[[RFC 6455](https://www.ietf.org/rfc/rfc6455.txt)\]
100
100
  * urn \[[RFC 2141](https://www.ietf.org/rfc/rfc2141.txt)\]
101
101
  * urn:uuid \[[RFC 4122](https://www.ietf.org/rfc/rfc4122.txt)\]
102
+ * mailto \[[RFC 6068](https://www.rfc-editor.org/rfc/rfc6068)\]
102
103
 
103
104
 
104
105
  ## Benchmarks
@@ -15,38 +15,87 @@ Reports based solely on comparing or mixing parsers that follow these different
15
15
  standards are out of scope. Applications must use the same parsing and
16
16
  normalization rules for both security decisions and subsequent URI use.
17
17
 
18
+ A WHATWG comparison may be useful supporting evidence, but a parser difference
19
+ is not by itself a vulnerability. A report remains in scope when it independently
20
+ demonstrates a defect in `fast-uri`'s RFC or documented behavior for a supported
21
+ scheme and a concrete security impact when the application uses `fast-uri`
22
+ consistently. An exploit that requires validating with `fast-uri` and then
23
+ passing the original, unmodified input to a parser with different rules is an
24
+ application parser-confusion issue.
25
+
18
26
  Reports are assessed based on reproducibility, documented supported usage, and
19
27
  concrete security impact—not merely on whether they mention WHATWG URL
20
- behavior. Reports demonstrating a parsing or normalization flaw in a supported
21
- scheme remain eligible for evaluation.
28
+ behavior.
22
29
 
23
30
  ## Threat model
24
31
 
25
32
  `fast-uri`'s threat model extends the
26
33
  [Node.js threat model](https://github.com/nodejs/node/blob/main/SECURITY.md#the-nodejs-threat-model).
27
34
 
28
- **Trusted:** Application code, parser options, configuration, and the runtime
29
- environment.
35
+ **Trusted:** Application code, structured component objects constructed or
36
+ modified by application code and passed directly to `serialize()`, parser
37
+ options, configuration, and the runtime environment.
30
38
 
31
39
  **Untrusted:** URI and IRI strings passed to the package's public APIs.
32
40
 
41
+ ## Vulnerability classification
42
+
43
+ A report is treated as a vulnerability when it demonstrates all of the
44
+ following:
45
+
46
+ 1. Attacker-controlled input reaches a public API through documented,
47
+ supported usage.
48
+ 2. `fast-uri` violates an applicable RFC or its documented API contract.
49
+ 3. The defect creates a concrete confidentiality, integrity, or availability
50
+ impact in a realistic supported use case.
51
+ 4. The impact does not depend solely on application misuse, an unsupported
52
+ scheme, a different parser interpreting the original input, or another
53
+ package's behavior.
54
+
55
+ A reproducible bug can still merit a normal issue and fix without meeting the
56
+ security-vulnerability threshold.
57
+
33
58
  ### Examples of vulnerabilities
34
59
 
35
- - RFC 3986 parsing or normalization flaws that bypass security controls
36
- - Denial of service through malformed input
37
- - Inconsistent parsing or normalization between `fast-uri` APIs
60
+ - `parse()`, `normalize()`, or `resolve()` changes an attacker-controlled
61
+ authority within `fast-uri`, and the report demonstrates a host security
62
+ control being bypassed using that output
63
+ - `equal()` aliases distinct URIs under the rules of a supported scheme, and
64
+ the report demonstrates an authorization, signature, or cache boundary being
65
+ bypassed
66
+ - One public API call on a reasonably sized malformed URI causes
67
+ disproportionate CPU or memory consumption, with reproducible availability
68
+ impact
69
+ - Parsing or normalization turns component data into a structural delimiter
70
+ and the report demonstrates a security-control bypass in documented usage
71
+
72
+ ### Denial-of-service reports
73
+
74
+ A synchronous exception, parse error, or non-idempotent result is not by itself
75
+ a denial-of-service vulnerability. A report must demonstrate disproportionate
76
+ resource consumption in a public API call, or loss of availability in a
77
+ supported deployment despite normal exception handling. An application that
78
+ terminates on an uncaught exception, or repeatedly normalizes until reaching a
79
+ fixpoint, does not establish a package vulnerability by itself.
38
80
 
39
81
  ### Examples of non-vulnerabilities
40
82
 
41
83
  The following are **not** considered vulnerabilities in `fast-uri`:
42
84
 
43
- - **Different URL standards:** Differences between RFC 3986 behavior and
44
- WHATWG URL behavior, including differences exposed by mixing parsers that
45
- implement those standards
46
- - **Unsupported scheme semantics:** Scheme-specific behavior for schemes that
47
- `fast-uri` does not document as supported
85
+ - **Different URL standards:** `fast-uri` returns one host, but an application
86
+ passes the original input to WHATWG `URL`, `fetch`, or another parser that
87
+ applies different recovery, whitespace, or legacy-IP rules
88
+ - **Unsupported scheme semantics:** Behavior specific to schemes such as
89
+ `ftp` or `file`, which `fast-uri` does not document as supported
90
+ - **Correctness without security impact:** Non-idempotent normalization,
91
+ surprising equality, truncation, re-encoding, or malformed-input handling
92
+ without a demonstrated security boundary or availability impact
93
+ - **Caller-created resource use:** An application repeatedly parses or
94
+ normalizes a value, or fails to catch a synchronous exception
95
+ - **Trusted structured input:** Boundary characters supplied in a component
96
+ object that application code constructs and passes to `serialize()`
48
97
  - **Application code vulnerabilities:** Security flaws in code that consumes
49
- `fast-uri` output
98
+ `fast-uri` output contrary to its documented contract
50
99
  - **Configuration mistakes:** Security issues caused by incorrect parser
51
100
  options or application configuration
52
101
  - **Missing security features:** Application-level protections that are not
@@ -89,6 +89,22 @@ function resolve (baseURI, relativeURI, options) {
89
89
  return serialize(resolved, schemelessOptions)
90
90
  }
91
91
 
92
+ /**
93
+ * Copies a host component together with its parse-time zone identifier (if
94
+ * any), so downstream recomposition does not re-derive an IPv6 zone from the
95
+ * ambiguous single-"%" component form. The zone is validated on use by
96
+ * `recomposeAuthority` rather than blindly trusted.
97
+ *
98
+ * @param {import('./types/index').URIComponent} target
99
+ * @param {import('./types/index').URIComponent} source
100
+ */
101
+ function copyHost (target, source) {
102
+ target.host = source.host
103
+ if (source.ipv6Zone !== undefined) {
104
+ target.ipv6Zone = source.ipv6Zone
105
+ }
106
+ }
107
+
92
108
  /**
93
109
  * @param {import ('./types/index').URIComponent} base
94
110
  * @param {import ('./types/index').URIComponent} relative
@@ -109,7 +125,7 @@ function resolveComponent (base, relative, options, skipNormalization) {
109
125
  target.scheme = relative.scheme
110
126
  // target.authority = relative.authority;
111
127
  target.userinfo = relative.userinfo
112
- target.host = relative.host
128
+ copyHost(target, relative)
113
129
  target.port = relative.port
114
130
  target.path = removeDotSegments(relative.path || '')
115
131
  target.query = relative.query
@@ -117,7 +133,7 @@ function resolveComponent (base, relative, options, skipNormalization) {
117
133
  if (relative.userinfo !== undefined || relative.host !== undefined || relative.port !== undefined) {
118
134
  // target.authority = relative.authority;
119
135
  target.userinfo = relative.userinfo
120
- target.host = relative.host
136
+ copyHost(target, relative)
121
137
  target.port = relative.port
122
138
  target.path = removeDotSegments(relative.path || '')
123
139
  target.query = relative.query
@@ -146,7 +162,7 @@ function resolveComponent (base, relative, options, skipNormalization) {
146
162
  }
147
163
  // target.authority = base.authority;
148
164
  target.userinfo = base.userinfo
149
- target.host = base.host
165
+ copyHost(target, base)
150
166
  target.port = base.port
151
167
  }
152
168
  target.scheme = base.scheme
@@ -178,6 +194,7 @@ function equal (uriA, uriB, options) {
178
194
  function serialize (cmpts, opts) {
179
195
  const component = {
180
196
  host: cmpts.host,
197
+ ipv6Zone: cmpts.ipv6Zone,
181
198
  scheme: cmpts.scheme,
182
199
  userinfo: cmpts.userinfo,
183
200
  port: cmpts.port,
@@ -506,6 +523,16 @@ function parseWithStatus (uri, opts) {
506
523
  malformedIPLiteral = hasIPLiteralBracket && (!bracketedIPLiteral || ipv6result.error === true)
507
524
  parsed.host = isIP ? ipv6result.host : ipv6result.host.toLowerCase()
508
525
 
526
+ if (isIP && ipv6result.isIPV6 === true && parsed.host.indexOf('%') !== -1) {
527
+ // Persist the zone identifier so recomposition never has to re-derive
528
+ // it from the ambiguous single-"%" component form, which misreads a
529
+ // zone that begins with "25" as a %25 separator. It is validated on
530
+ // use during recomposition, so a host reassigned after parse or an
531
+ // input zone that does not describe the host is ignored. Only zoned
532
+ // literals are ambiguous; plain IPv6 addresses round-trip without it.
533
+ parsed.ipv6Zone = parsed.host.slice(parsed.host.indexOf('%') + 1)
534
+ }
535
+
509
536
  if (malformedIPLiteral) {
510
537
  parsed.error = parsed.error || 'URI host is malformed.'
511
538
  malformedAuthorityOrPort = true
@@ -537,13 +564,17 @@ function parseWithStatus (uri, opts) {
537
564
  malformedHost = canonicalizeHost(parsed, options, schemeHandler, isIP)
538
565
  }
539
566
 
540
- if (!schemeHandler || (schemeHandler && !schemeHandler.skipNormalize)) {
541
- if (uri.indexOf('%') !== -1) {
542
- if (parsed.host !== undefined && !malformedIPLiteral) {
543
- const host = isIP ? parsed.host : normalizePercentEncoding(parsed.host, true)
544
- parsed.host = reescapeHostDelimiters(host, isIP)
545
- }
567
+ if (uri.indexOf('%') !== -1 && parsed.host !== undefined && !malformedIPLiteral) {
568
+ let host = isIP ? parsed.host : normalizePercentEncoding(parsed.host, true)
569
+ if (!isIP) {
570
+ // Fold reg-name case after decoding unreserved octets. The second
571
+ // pass only restores uppercase hex in escapes that remain encoded.
572
+ host = normalizePercentEncoding(host.toLowerCase())
546
573
  }
574
+ parsed.host = reescapeHostDelimiters(host, isIP)
575
+ }
576
+
577
+ if (!schemeHandler || (schemeHandler && !schemeHandler.skipNormalize)) {
547
578
  if (parsed.path) {
548
579
  parsed.path = normalizePathEncoding(parsed.path)
549
580
  }