@openclaw/lobster 2026.10.10 → 2026.11.5-beta.1

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 (98) hide show
  1. package/README.md +8 -0
  2. package/dist/.setup/lobster-schema-compiler-T2XZzavY.mjs +32 -0
  3. package/dist/.source-module-urls/00dc8c474cfa3e6e755374b6a78ce42a8dcd5a5a37a90df29d7baaef767292a6.json +1 -1
  4. package/dist/index.js +17 -11
  5. package/node_modules/@clawdbot/lobster/dist/src/commands/stdlib/llm_invoke.js +1 -82
  6. package/node_modules/@clawdbot/lobster/dist/src/commands/stdlib/llm_invoke_schemas.js +79 -0
  7. package/node_modules/@clawdbot/lobster/dist/src/commands/stdlib/llm_invoke_validators.generated.js +1008 -0
  8. package/node_modules/@clawdbot/lobster/dist/src/core/index.js +1 -1
  9. package/node_modules/@clawdbot/lobster/dist/src/validation.js +25 -4
  10. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/.github/workflows/release.yml +1 -11
  11. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/README.md +0 -8
  12. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/index.js +17 -93
  13. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/lib/utils.js +0 -52
  14. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/package.json +1 -1
  15. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/test/reserved-path-normalization.test.js +4 -32
  16. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/test/scheme-validation.test.js +12 -51
  17. package/node_modules/typebox/build/format/duration.d.mts +2 -2
  18. package/node_modules/typebox/build/format/duration.mjs +2 -2
  19. package/node_modules/typebox/build/format/idn_email.d.mts +1 -0
  20. package/node_modules/typebox/build/format/idn_email.mjs +1 -0
  21. package/node_modules/typebox/build/format/idn_hostname.d.mts +1 -1
  22. package/node_modules/typebox/build/format/idn_hostname.mjs +1 -1
  23. package/node_modules/typebox/build/format/ipv4.d.mts +2 -2
  24. package/node_modules/typebox/build/format/ipv4.mjs +2 -2
  25. package/node_modules/typebox/build/format/ipv6.d.mts +1 -1
  26. package/node_modules/typebox/build/format/ipv6.mjs +1 -1
  27. package/node_modules/typebox/build/format/relative_json_pointer.d.mts +2 -2
  28. package/node_modules/typebox/build/format/relative_json_pointer.mjs +2 -2
  29. package/node_modules/typebox/build/schema/build.mjs +1 -0
  30. package/node_modules/typebox/build/schema/engine/_unique.d.mts +4 -2
  31. package/node_modules/typebox/build/schema/engine/_unique.mjs +7 -3
  32. package/node_modules/typebox/build/schema/engine/additionalItems.mjs +3 -3
  33. package/node_modules/typebox/build/schema/engine/additionalProperties.d.mts +0 -3
  34. package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +15 -17
  35. package/node_modules/typebox/build/schema/engine/contains.mjs +3 -3
  36. package/node_modules/typebox/build/schema/engine/index.d.mts +1 -0
  37. package/node_modules/typebox/build/schema/engine/index.mjs +1 -0
  38. package/node_modules/typebox/build/schema/engine/items.mjs +7 -4
  39. package/node_modules/typebox/build/schema/engine/maxContains.mjs +2 -2
  40. package/node_modules/typebox/build/schema/engine/minContains.mjs +3 -3
  41. package/node_modules/typebox/build/schema/engine/oneOf.mjs +2 -2
  42. package/node_modules/typebox/build/schema/engine/patternProperties.mjs +2 -2
  43. package/node_modules/typebox/build/schema/engine/propertyNames.mjs +2 -2
  44. package/node_modules/typebox/build/schema/engine/unevaluatedItems.mjs +2 -2
  45. package/node_modules/typebox/build/schema/engine/unevaluatedProperties.mjs +2 -2
  46. package/node_modules/typebox/build/system/hashing/hash.mjs +63 -34
  47. package/node_modules/typebox/build/system/locale/en_US.mjs +2 -1
  48. package/node_modules/typebox/build/system/memory/assign.d.mts +2 -8
  49. package/node_modules/typebox/build/system/memory/assign.mjs +13 -6
  50. package/node_modules/typebox/build/system/memory/clone.d.mts +4 -5
  51. package/node_modules/typebox/build/system/memory/clone.mjs +8 -96
  52. package/node_modules/typebox/build/system/memory/create.d.mts +1 -5
  53. package/node_modules/typebox/build/system/memory/create.mjs +18 -13
  54. package/node_modules/typebox/build/system/memory/deep.d.mts +2 -0
  55. package/node_modules/typebox/build/system/memory/deep.mjs +108 -0
  56. package/node_modules/typebox/build/system/memory/discard.d.mts +1 -1
  57. package/node_modules/typebox/build/system/memory/discard.mjs +9 -8
  58. package/node_modules/typebox/build/system/memory/finalize.d.mts +4 -0
  59. package/node_modules/typebox/build/system/memory/finalize.mjs +30 -0
  60. package/node_modules/typebox/build/system/memory/keys.d.mts +2 -0
  61. package/node_modules/typebox/build/system/memory/keys.mjs +8 -0
  62. package/node_modules/typebox/build/system/memory/update.d.mts +1 -4
  63. package/node_modules/typebox/build/system/memory/update.mjs +43 -16
  64. package/node_modules/typebox/build/type/engine/call/index.d.mts +1 -0
  65. package/node_modules/typebox/build/type/engine/call/index.mjs +1 -0
  66. package/node_modules/typebox/build/type/engine/evaluate/composite.d.mts +2 -24
  67. package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +2 -29
  68. package/node_modules/typebox/build/type/engine/evaluate/index.d.mts +1 -0
  69. package/node_modules/typebox/build/type/engine/evaluate/index.mjs +1 -0
  70. package/node_modules/typebox/build/type/engine/evaluate/narrow.d.mts +5 -1
  71. package/node_modules/typebox/build/type/engine/evaluate/narrow.mjs +6 -1
  72. package/node_modules/typebox/build/type/engine/evaluate/property.d.mts +30 -0
  73. package/node_modules/typebox/build/type/engine/evaluate/property.mjs +29 -0
  74. package/node_modules/typebox/build/type/engine/immutable/instantiate_add.d.mts +1 -3
  75. package/node_modules/typebox/build/type/engine/immutable/instantiate_add.mjs +1 -4
  76. package/node_modules/typebox/build/type/engine/object/from_intersect.d.mts +2 -2
  77. package/node_modules/typebox/build/type/engine/object/from_intersect.mjs +2 -2
  78. package/node_modules/typebox/build/type/engine/object/from_union.d.mts +2 -2
  79. package/node_modules/typebox/build/type/engine/object/from_union.mjs +2 -2
  80. package/node_modules/typebox/build/type/engine/optional/instantiate_add.d.mts +1 -3
  81. package/node_modules/typebox/build/type/engine/optional/instantiate_add.mjs +1 -4
  82. package/node_modules/typebox/build/type/engine/readonly/instantiate_add.d.mts +1 -3
  83. package/node_modules/typebox/build/type/engine/readonly/instantiate_add.mjs +1 -4
  84. package/node_modules/typebox/build/type/engine/this/index.d.mts +1 -0
  85. package/node_modules/typebox/build/type/engine/this/index.mjs +1 -0
  86. package/node_modules/typebox/build/value/clone/clone.d.mts +4 -3
  87. package/node_modules/typebox/build/value/clone/clone.mjs +5 -7
  88. package/node_modules/typebox/build/value/repair/from_cyclic.d.mts +2 -0
  89. package/node_modules/typebox/build/value/repair/from_cyclic.mjs +6 -0
  90. package/node_modules/typebox/build/value/shared/union_priority_sort.mjs +25 -14
  91. package/node_modules/typebox/package.json +1 -1
  92. package/node_modules/typebox/readme.md +1 -1
  93. package/package.json +5 -5
  94. package/node_modules/@clawdbot/lobster/dist/src/workflows/types.js +0 -2
  95. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/test/host-delimiter-security.test.js +0 -94
  96. package/node_modules/@clawdbot/lobster/node_modules/fast-uri/test/relative-normalization-security.test.js +0 -152
  97. package/node_modules/typebox/build/system/memory/freeze.d.mts +0 -4
  98. package/node_modules/typebox/build/system/memory/freeze.mjs +0 -6
@@ -4,4 +4,4 @@ export { runPipeline } from "../runtime.js";
4
4
  export { runWorkflowFile } from "../workflows/file.js";
5
5
  export { decodeResumeToken } from "../resume.js";
6
6
  export { runToolRequest, resumeToolRequest, createToolContext } from "./tool_runtime.js";
7
- //# sourceMappingURL=index.js.map
7
+ export { withSchemaCompiler } from "../validation.js";
@@ -1,3 +1,4 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
1
2
  import { Ajv } from "ajv";
2
3
  import { stableStringify } from "./state/store.js";
3
4
  export const sharedAjv = new Ajv({
@@ -6,6 +7,11 @@ export const sharedAjv = new Ajv({
6
7
  // User-provided schemas may repeat `$id` across runs/resumes.
7
8
  addUsedSchema: false,
8
9
  });
10
+ const schemaCompilerScope = new AsyncLocalStorage();
11
+ /** Run one host request with its schema compiler, without changing other requests. */
12
+ export function withSchemaCompiler(compiler, callback) {
13
+ return schemaCompilerScope.run(compiler, callback);
14
+ }
9
15
  /**
10
16
  * Build a memoized `compile()` for a given Ajv instance.
11
17
  *
@@ -22,17 +28,32 @@ export const sharedAjv = new Ajv({
22
28
  * interchangeable across different Ajv configurations.
23
29
  */
24
30
  export function createCompileCached(ajv) {
25
- const cache = new Map();
31
+ const defaultCache = new Map();
32
+ const scopedCaches = new WeakMap();
26
33
  return function compileCached(schema) {
34
+ const compiler = schemaCompilerScope.getStore();
35
+ let cache = defaultCache;
36
+ if (compiler) {
37
+ cache = scopedCaches.get(compiler);
38
+ if (!cache) {
39
+ cache = new Map();
40
+ scopedCaches.set(compiler, cache);
41
+ }
42
+ }
27
43
  const key = stableStringify(schema);
28
44
  let validator = cache.get(key);
29
45
  if (!validator) {
30
- validator = ajv.compile(schema);
46
+ validator = compiler
47
+ ? compiler(schema, {
48
+ scope: ajv,
49
+ allErrors: ajv.opts.allErrors === true,
50
+ addUsedSchema: ajv.opts.addUsedSchema !== false,
51
+ })
52
+ : ajv.compile(schema);
31
53
  cache.set(key, validator);
32
54
  }
33
55
  return validator;
34
56
  };
35
57
  }
36
58
  /** Memoized compile bound to the module-level `sharedAjv` instance. */
37
- export const compileCached = createCompileCached(sharedAjv);
38
- //# sourceMappingURL=validation.js.map
59
+ export const compileCached = createCompileCached(sharedAjv);
@@ -11,14 +11,6 @@ on:
11
11
  - patch
12
12
  - minor
13
13
  - major
14
- - prepatch
15
- - preminor
16
- - premajor
17
- - prerelease
18
- preid:
19
- description: 'Prerelease identifier (e.g. rc), used by the pre* bump types'
20
- required: false
21
- type: string
22
14
 
23
15
  permissions: {}
24
16
 
@@ -27,8 +19,6 @@ jobs:
27
19
  permissions:
28
20
  id-token: write # required for npm provenance via OIDC
29
21
  contents: write # required to push the release commit and the tag
30
- uses: fastify/workflows/.github/workflows/reusable-release.yml@b0a2ab2d8259b6bd574b804cd6874bbd75c3577c
22
+ uses: fastify/workflows/.github/workflows/reusable-release.yml@b1a11bce713bc857e52b2231fec3c89071ad3135
31
23
  with:
32
24
  semver: ${{ inputs.semver }}
33
- preid: ${{ inputs.preid }}
34
- dist-tag: ${{ startsWith(inputs.semver, 'pre') && 'next' || 'latest' }}
@@ -15,18 +15,12 @@ All of the above functions can accept an additional options argument that is an
15
15
 
16
16
  Malformed authorities, out-of-range ports, and raw leading or trailing C0 controls or spaces (U+0000–U+0020) are reported through the parsed component's `error` field. `normalize()` leaves these malformed string inputs unchanged, and `equal()` returns `false`. `resolve()` rejects them in either input and rejects HTTP(S) results with an empty host. Percent-encoded and interior component data remain valid.
17
17
 
18
- Schemes are never percent-decoded. RFC 3986 does not allow percent-encoding in a scheme, so an input such as `%6Aavascript:alert(1)` is reported as malformed (`error: 'URI scheme is malformed.'`) instead of being parsed as `javascript:`. `normalize()` leaves it unchanged, `equal()` returns `false`, and `resolve()` and `serialize()` throw.
19
-
20
- For schemes with domain hosts (`http`, `https`, `ws`, `wss`, or any scheme with the `domainHost` option), a host containing an ASCII character that RFC 3986 does not allow in a reg-name (for example `@`, TAB, LF, CR, space, `"`, `<`, `>`, `^`, `` ` ``, `{`, `|`, `}`) is reported as malformed (`error: 'URI host is malformed.'`). It is never passed through a WHATWG URL parser that could treat `@` as a delimiter or strip whitespace. `normalize()` leaves such input unchanged, `equal()` returns `false`, and `resolve()` throws.
21
-
22
18
  * `scheme` (string)
23
19
  Indicates the scheme that the URI should be treated as, overriding the URI's normal scheme parsing behavior.
24
20
 
25
21
  * `reference` (string)
26
22
  If set to `"suffix"`, it indicates that the URI is in the suffix format and the parser will use the option's `scheme` property to determine the URI's scheme.
27
23
 
28
- A suffix reference is written without its scheme and without the `//` authority marker (RFC 3986 section 4.5). Such a reference is inherently ambiguous: an authority component cannot always be distinguished from a path. When the input carries an authority of the form `host:port` (for example `//javascript:80/x`) or a userinfo containing a colon, the serialized suffix output can begin with text that reparses as a URI scheme (for example `javascript:80/x`). Do not treat suffix output as a trusted absolute URL, and do not render it or use it in a scheme allowlist without first validating it with `parse()`. If you need an unambiguous result, use the default (non-suffix) serialization.
29
-
30
24
  * `tolerant` (boolean, false)
31
25
  If set to `true`, the parser will relax URI resolving rules.
32
26
 
@@ -86,8 +80,6 @@ uri.normalize('http://example.com/a%2Fb')
86
80
 
87
81
  Reserved path escapes such as `%2F` and `%2E` are preserved as path data during normalization and comparison.
88
82
 
89
- Dot segments in relative references are removed without changing what the reference resolves to: leading `..` segments that cannot be collapsed are kept, a relative path is never turned into a root-relative one, and a first-segment colon exposed by the removal is kept behind a leading `./` so the reference is not reparsed as a scheme (`a/../b` → `b`, `../x` → `../x`, `x/..` → `./`, `a/../a:b` → `./a:b`).
90
-
91
83
  ### Equal
92
84
 
93
85
  ```js
@@ -1,29 +1,21 @@
1
1
  'use strict'
2
2
 
3
- const { normalizeIPv6, removeDotSegments, removeDotSegmentsRelative, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding, serializePathEncoding, normalizeQueryFragmentEncoding, encodeQuery, encodeFragment, encodeHost, isIPv4, nonSimpleDomain } = require('./lib/utils')
3
+ const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding, serializePathEncoding, normalizeQueryFragmentEncoding, encodeQuery, encodeFragment, encodeHost, isIPv4, nonSimpleDomain } = require('./lib/utils')
4
4
  const { SCHEMES, getSchemeHandler } = require('./lib/schemes')
5
5
 
6
6
  const VALID_SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*$/u
7
7
  const MALFORMED_SCHEME_ERROR = 'URI scheme is malformed.'
8
- const MALFORMED_HOST_ERROR = 'URI host is malformed.'
9
- // ASCII characters outside the RFC 3986 reg-name set (unreserved, sub-delims
10
- // and "%" for pct-encoded): C0 controls, space, DEL, and "#/:<>?@[\]^`{|}.
11
- const FORBIDDEN_DOMAIN_HOST_CHARACTER = /[\0-\x20"#/:<>?@[\\\]^`{|}\x7F]/u
12
8
 
13
9
  /**
14
- * RFC 3986 section 3.1 does not allow percent-encoding in a scheme, so the
15
- * scheme is validated as-is and never decoded. Decoding would let inert input
16
- * such as `%6Aavascript:` become a live `javascript:` scheme.
17
- *
18
10
  * @param {string} scheme
19
11
  * @returns {string}
20
12
  */
21
- function validateScheme (scheme) {
22
- const stringScheme = String(scheme)
23
- if (!VALID_SCHEME.test(stringScheme)) {
13
+ function decodeValidScheme (scheme) {
14
+ const decodedScheme = unescape(String(scheme))
15
+ if (!VALID_SCHEME.test(decodedScheme)) {
24
16
  throw new TypeError(MALFORMED_SCHEME_ERROR)
25
17
  }
26
- return stringScheme
18
+ return decodedScheme
27
19
  }
28
20
 
29
21
  /**
@@ -96,12 +88,6 @@ function resolve (baseURI, relativeURI, options) {
96
88
  }
97
89
  const resolvedHostIsIP = resolvedHost !== undefined && resolvedHost !== '' &&
98
90
  (isIPv4(resolvedHost) || normalizeIPv6(resolvedHost).isIPV6)
99
- // Inputs are parsed scheme-neutrally, so delimiters and controls in a domain
100
- // host are only detected here, once the final scheme is known. They always
101
- // fail closed, including in percent-encoded hosts.
102
- if (hasForbiddenDomainHost(resolved, options || {}, resolvedSchemeHandler, resolvedHostIsIP)) {
103
- throw new Error(MALFORMED_HOST_ERROR)
104
- }
105
91
  canonicalizeHost(resolved, options || {}, resolvedSchemeHandler, resolvedHostIsIP)
106
92
  // Percent escapes in an ASCII reg-name are encoded data. The WHATWG hostname
107
93
  // parser can reject them even though fast-uri preserves them safely as RFC
@@ -181,17 +167,14 @@ function resolveComponent (base, relative, options, skipNormalization) {
181
167
  if (relative.path[0] === '/') {
182
168
  target.path = removeDotSegments(relative.path)
183
169
  } else {
184
- const baseHasAuthority = base.userinfo !== undefined || base.host !== undefined || base.port !== undefined
185
- if (baseHasAuthority && !base.path) {
170
+ if ((base.userinfo !== undefined || base.host !== undefined || base.port !== undefined) && !base.path) {
186
171
  target.path = '/' + relative.path
187
172
  } else if (!base.path) {
188
173
  target.path = relative.path
189
174
  } else {
190
175
  target.path = base.path.slice(0, base.path.lastIndexOf('/') + 1) + relative.path
191
176
  }
192
- target.path = base.scheme === undefined && !baseHasAuthority && target.path[0] !== '/'
193
- ? removeDotSegmentsRelative(target.path)
194
- : removeDotSegments(target.path)
177
+ target.path = removeDotSegments(target.path)
195
178
  }
196
179
  target.query = relative.query
197
180
  }
@@ -252,7 +235,7 @@ function serialize (cmpts, opts) {
252
235
  const uriTokens = []
253
236
 
254
237
  if (component.scheme) {
255
- component.scheme = validateScheme(component.scheme)
238
+ component.scheme = decodeValidScheme(component.scheme)
256
239
  }
257
240
 
258
241
  // find scheme handler
@@ -262,11 +245,7 @@ function serialize (cmpts, opts) {
262
245
  if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(component, options)
263
246
 
264
247
  const hasAuthority = component.userinfo !== undefined || component.host !== undefined || component.port !== undefined
265
- // A reference with no emitted scheme is path-noscheme: a bare ':' in its
266
- // first path segment would reparse as a scheme (RFC 3986 3.3/4.2). Enforced
267
- // under skipEscape too (resolve()), so the reapply below gates on this flag.
268
- const schemelessReference = (component.scheme === undefined || options.reference === 'suffix') && !hasAuthority
269
- const pathNoScheme = !options.skipEscape && schemelessReference
248
+ const pathNoScheme = !options.skipEscape && component.scheme === undefined && !hasAuthority
270
249
 
271
250
  if (component.path !== undefined) {
272
251
  if (!options.skipEscape) {
@@ -278,7 +257,7 @@ function serialize (cmpts, opts) {
278
257
 
279
258
  if (options.reference !== 'suffix' && component.scheme) {
280
259
  // Scheme handlers may replace the scheme during serialization.
281
- component.scheme = validateScheme(component.scheme)
260
+ component.scheme = decodeValidScheme(component.scheme)
282
261
  uriTokens.push(component.scheme, ':')
283
262
  }
284
263
 
@@ -299,18 +278,13 @@ function serialize (cmpts, opts) {
299
278
  let s = component.path
300
279
 
301
280
  if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
302
- // A relative-path reference keeps its unresolvable leading ".." segments
303
- // and must never become root-relative (RFC 3986 section 5.2.4 applies to
304
- // merged target paths, not to the reference itself).
305
- s = schemelessReference && s[0] !== '/'
306
- ? removeDotSegmentsRelative(s)
307
- : removeDotSegments(s)
281
+ s = removeDotSegments(s)
308
282
  }
309
283
 
310
284
  // Dot-segment removal can expose a colon that was not originally in the
311
285
  // first segment (for example, "./a:b"). Reapply path-noscheme encoding so
312
286
  // the serialized relative reference cannot be reparsed as a URI scheme.
313
- if (schemelessReference) {
287
+ if (pathNoScheme) {
314
288
  s = serializePathEncoding(s, true)
315
289
  }
316
290
 
@@ -430,11 +404,6 @@ function canonicalizeHost (parsed, options, schemeHandler, isIP) {
430
404
  parsed.host[0] === '[' &&
431
405
  parsed.host[parsed.host.length - 1] === ']'
432
406
 
433
- if (hasForbiddenDomainHost(parsed, options, schemeHandler, isIP)) {
434
- parsed.error = parsed.error || MALFORMED_HOST_ERROR
435
- return true
436
- }
437
-
438
407
  if (
439
408
  !options.unicodeSupport &&
440
409
  (!schemeHandler || !schemeHandler.unicodeSupport) &&
@@ -445,63 +414,17 @@ function canonicalizeHost (parsed, options, schemeHandler, isIP) {
445
414
  !bracketedIPLiteral &&
446
415
  nonSimpleDomain(parsed.host)
447
416
  ) {
448
- let url
449
417
  try {
450
- url = new URL('http://' + parsed.host)
418
+ parsed.host = new URL('http://' + parsed.host).hostname
451
419
  } catch (e) {
452
420
  parsed.error = parsed.error || "Host's domain name can not be converted to ASCII: " + e
453
421
  return true
454
422
  }
455
- // The WHATWG parser must have read the whole input as a host. Anything
456
- // else means it found a delimiter fast-uri did not, so its hostname would
457
- // describe a different authority.
458
- if (!isHostOnlyURL(url)) {
459
- parsed.error = parsed.error || MALFORMED_HOST_ERROR
460
- return true
461
- }
462
- parsed.host = url.hostname
463
423
  }
464
424
 
465
425
  return false
466
426
  }
467
427
 
468
- /**
469
- * Whether a domain host contains an ASCII character that RFC 3986 does not
470
- * allow in a reg-name (unreserved, sub-delims, or pct-encoded). Such a host is
471
- * rejected instead of being handed to the WHATWG URL parser, which would treat
472
- * "@" as a userinfo delimiter (silently dropping the data before it) and strip
473
- * TAB, LF, and CR. Non-ASCII characters remain allowed for IDNs.
474
- *
475
- * @param {import('./types/index').URIComponent} parsed
476
- * @param {import('./types/index').Options} options
477
- * @param {{ domainHost?: boolean }|undefined} schemeHandler
478
- * @param {boolean} isIP
479
- * @returns {boolean}
480
- */
481
- function hasForbiddenDomainHost (parsed, options, schemeHandler, isIP) {
482
- return Boolean(
483
- parsed.host &&
484
- isIP === false &&
485
- !isIPLiteral(parsed.host) &&
486
- (options.domainHost || (schemeHandler && schemeHandler.domainHost)) &&
487
- FORBIDDEN_DOMAIN_HOST_CHARACTER.test(parsed.host)
488
- )
489
- }
490
-
491
- /**
492
- * @param {URL} url
493
- * @returns {boolean}
494
- */
495
- function isHostOnlyURL (url) {
496
- return url.username === '' &&
497
- url.password === '' &&
498
- url.port === '' &&
499
- url.pathname === '/' &&
500
- url.search === '' &&
501
- url.hash === '' &&
502
- url.hostname !== ''
503
- }
504
-
505
428
  /**
506
429
  * @param {string} uri
507
430
  * @param {import('./types/index').Options} [opts]
@@ -594,8 +517,9 @@ function parseWithStatus (uri, opts) {
594
517
  parsed.fragment = matches[8]
595
518
 
596
519
  if (parsed.scheme !== undefined) {
597
- if (VALID_SCHEME.test(parsed.scheme)) {
598
- parsed.scheme = parsed.scheme.toLowerCase()
520
+ const decodedScheme = unescape(parsed.scheme)
521
+ if (VALID_SCHEME.test(decodedScheme)) {
522
+ parsed.scheme = decodedScheme.toLowerCase()
599
523
  } else {
600
524
  parsed.error = parsed.error || MALFORMED_SCHEME_ERROR
601
525
  malformedScheme = true
@@ -639,7 +563,7 @@ function parseWithStatus (uri, opts) {
639
563
  }
640
564
 
641
565
  if (malformedIPLiteral) {
642
- parsed.error = parsed.error || MALFORMED_HOST_ERROR
566
+ parsed.error = parsed.error || 'URI host is malformed.'
643
567
  malformedAuthorityOrPort = true
644
568
  }
645
569
  } else {
@@ -352,57 +352,6 @@ function removeDotSegments (path) {
352
352
  return output.join('')
353
353
  }
354
354
 
355
- /**
356
- * Removes dot segments from the path of a relative reference (a path that does
357
- * not start with "/") without changing what it resolves to against any base.
358
- * Unlike `removeDotSegments`, leading ".." segments that cannot be collapsed
359
- * are kept, the result never becomes root-relative, and a result that would be
360
- * empty or start with an empty segment is prefixed with "." (an empty path
361
- * means "same document" and a leading "//" would introduce an authority).
362
- *
363
- * @param {string} path
364
- * @returns {string}
365
- */
366
- function removeDotSegmentsRelative (path) {
367
- if (path === '' || path[0] === '/') {
368
- return removeDotSegments(path)
369
- }
370
-
371
- const segments = path.split('/')
372
- const last = segments.length - 1
373
- /** @type {string[]} */
374
- const output = []
375
- let trailingDirectory = false
376
-
377
- for (let i = 0; i <= last; i++) {
378
- const segment = segments[i]
379
- if (segment === '.' || segment === '..') {
380
- if (segment === '..') {
381
- if (output.length !== 0 && output[output.length - 1] !== '..') {
382
- output.pop()
383
- } else {
384
- output.push('..')
385
- }
386
- }
387
- trailingDirectory = i === last
388
- } else {
389
- output.push(segment)
390
- }
391
- }
392
-
393
- if (trailingDirectory && output[output.length - 1] !== '..') {
394
- output.push('')
395
- }
396
- if (output.length === 0 || output[0] === '' || output[0].includes(':')) {
397
- // An empty path, a leading empty segment ("//"), or a first segment
398
- // containing ":" (which would be mistaken for a scheme, RFC 3986 section
399
- // 4.2) must stay behind a "." segment so the reference keeps its meaning.
400
- output.unshift('.')
401
- }
402
-
403
- return output.join('/')
404
- }
405
-
406
355
  /**
407
356
  * Encodes a host according to the RFC 3986 host grammar. Valid IP literals
408
357
  * have already been checked by `normalizeIPv6`, so their address separators
@@ -908,7 +857,6 @@ module.exports = {
908
857
  encodeFragment,
909
858
  escapePreservingEscapes,
910
859
  removeDotSegments,
911
- removeDotSegmentsRelative,
912
860
  isIPv4,
913
861
  isUUID,
914
862
  normalizeIPv6,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fast-uri",
3
3
  "description": "Dependency-free RFC 3986 URI toolbox",
4
- "version": "4.2.3",
4
+ "version": "4.2.2",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
7
7
  "types": "types/index.d.ts",
@@ -77,13 +77,13 @@ test('serialize uses the RFC 3986 path character set without opening escapes', (
77
77
  )
78
78
  t.equal(
79
79
  fastURI.serialize({ path: './a:b/c:d' }),
80
- './a:b/c:d',
81
- 'a first-segment colon exposed by dot-segment removal is kept behind a "." segment'
80
+ 'a%3Ab/c:d',
81
+ 'escapes a first-segment colon exposed by dot-segment removal'
82
82
  )
83
83
  t.equal(
84
84
  fastURI.normalize('./a:b'),
85
- './a:b',
86
- 'normalization keeps a relative path from becoming a scheme without re-encoding the colon'
85
+ 'a%3Ab',
86
+ 'normalization keeps a relative path from becoming a scheme'
87
87
  )
88
88
  t.equal(
89
89
  fastURI.serialize({ path: '/Kſ' }),
@@ -107,31 +107,3 @@ test('equal distinguishes escaped reserved path data from literal syntax', (t) =
107
107
  )
108
108
  t.end()
109
109
  })
110
-
111
- // A suffix reference never emits its scheme token, so it is a scheme-less
112
- // (path-noscheme) reference: a bare ':' in its first path segment must be
113
- // escaped, or the serialized output reparses as an absolute URI with a scheme.
114
- // @see https://github.com/fastify/fast-uri/security/advisories/GHSA-333x-w4r6-6crp
115
- test('suffix reference escapes a first-segment colon instead of emitting a scheme', (t) => {
116
- const dangerous = /^(?:javascript|data|vbscript):/i
117
- const options = { reference: 'suffix', scheme: 'x' }
118
-
119
- for (const input of ['javascript:alert(1)', '%6Aavascript:alert(1)', 'data:text/html,x', 'vbscript:msgbox(1)']) {
120
- t.notOk(dangerous.test(fastURI.normalize(input, options)), `${input} normalizes to an inert reference`)
121
- }
122
-
123
- t.equal(
124
- fastURI.normalize('javascript:alert(1)', options),
125
- 'javascript%3Aalert(1)',
126
- 'escapes the leading-segment colon to %3A'
127
- )
128
- t.notOk(
129
- dangerous.test(fastURI.resolve('https://a.example/base/', '%6Aavascript:alert(1)', { reference: 'suffix' })),
130
- 'resolve in suffix mode does not emit a live scheme'
131
- )
132
-
133
- // legitimate suffix usage is unchanged
134
- t.equal(fastURI.normalize('path/to/file', options), 'path/to/file', 'plain path unchanged')
135
- t.equal(fastURI.normalize('a/b:c', options), 'a/b:c', 'colon in a later segment stays literal')
136
- t.end()
137
- })
@@ -15,15 +15,7 @@ const malformedSchemes = [
15
15
  'foo_bar:value',
16
16
  'éxample:value',
17
17
  'Kttp://example.com/',
18
- 'ſcheme:value',
19
- // RFC 3986 section 3.1 does not allow percent-encoding in a scheme.
20
- '%4Aavascript:alert(1)',
21
- '%6aavascript:alert(1)',
22
- 'foo%2Bbar:value',
23
- '%u006Aavascript:1',
24
- 'ht%74ps://example.com/',
25
- 'ma%69lto:user@example.org',
26
- '%64ata:text/html,x'
18
+ 'ſcheme:value'
27
19
  ]
28
20
 
29
21
  test('parse validates the decoded scheme against RFC 3986', (t) => {
@@ -31,7 +23,10 @@ test('parse validates the decoded scheme against RFC 3986', (t) => {
31
23
  ['a:value', 'a'],
32
24
  ['HTTP://example.com/', 'http'],
33
25
  ['a1+.-:value', 'a1+.-'],
34
- ['foo+bar:value', 'foo+bar']
26
+ ['%4Aavascript:alert(1)', 'javascript'],
27
+ ['foo%2Bbar:value', 'foo+bar'],
28
+ ['%u006Aavascript:1', 'javascript'],
29
+ ['ht%74ps://example.com/', 'https']
35
30
  ]
36
31
 
37
32
  for (const [uri, scheme] of validSchemes) {
@@ -47,39 +42,15 @@ test('parse validates the decoded scheme against RFC 3986', (t) => {
47
42
  t.end()
48
43
  })
49
44
 
50
- test('percent-encoded schemes do not select scheme handlers', (t) => {
45
+ test('decoded schemes select their scheme handlers', (t) => {
51
46
  t.equal(
52
47
  fastURI.normalize('ht%74ps://example.com:443'),
53
- 'ht%74ps://example.com:443',
54
- 'HTTP normalization does not run for an encoded scheme'
48
+ 'https://example.com/',
49
+ 'HTTP normalization runs after decoding the scheme'
55
50
  )
56
51
 
57
52
  const mailto = fastURI.parse('ma%69lto:user@example.org')
58
- t.equal(mailto.to, undefined, 'mailto parsing does not run for an encoded scheme')
59
- t.equal(mailto.error, MALFORMED_SCHEME_ERROR)
60
- t.end()
61
- })
62
-
63
- test('normalization cannot synthesize a scheme from encoded input', (t) => {
64
- const inputs = [
65
- '%6Aavascript:alert(1)',
66
- '%4A%41%56%41%53%43%52%49%50%54:alert(1)',
67
- '%u006Aavascript:alert(1)',
68
- 'j%61vascript:alert(1)',
69
- '%64ata:text/html,<script>alert(1)</script>',
70
- 'vb%73cript:msgbox(1)'
71
- ]
72
-
73
- for (const uri of inputs) {
74
- const parsed = fastURI.parse(uri)
75
- t.equal(parsed.error, MALFORMED_SCHEME_ERROR, uri + ' is malformed')
76
- t.notOk(/^(?:javascript|data|vbscript):/i.test(String(parsed.scheme) + ':'), uri + ' parsed scheme is not decoded')
77
- t.equal(fastURI.normalize(uri), uri, uri + ' normalizes to itself')
78
- t.equal(fastURI.equal(uri, uri), false, uri + ' is not comparable')
79
- t.throws(() => fastURI.resolve('https://example.com/app/', uri), /URI scheme is malformed\./, uri + ' is rejected by resolve')
80
- }
81
-
82
- t.equal(fastURI.equal('%68ttp://a/', 'http://a/'), false, 'encoded scheme does not alias a plain scheme')
53
+ t.deepEqual(mailto.to, ['user@example.org'], 'mailto parsing runs after decoding the scheme')
83
54
  t.end()
84
55
  })
85
56
 
@@ -122,21 +93,11 @@ test('resolve rejects malformed decoded schemes in either input', (t) => {
122
93
  t.end()
123
94
  })
124
95
 
125
- test('serialize validates component schemes without decoding them', (t) => {
96
+ test('serialize validates decoded component schemes', (t) => {
126
97
  t.equal(
127
- fastURI.serialize({ scheme: 'foo+bar', path: 'value' }),
98
+ fastURI.serialize({ scheme: 'foo%2Bbar', path: 'value' }),
128
99
  'foo+bar:value',
129
- 'valid scheme is serialized'
130
- )
131
- t.throws(
132
- () => fastURI.serialize({ scheme: 'foo%2Bbar', path: 'value' }),
133
- /URI scheme is malformed\./,
134
- 'percent-encoded scheme is rejected'
135
- )
136
- t.throws(
137
- () => fastURI.serialize({ scheme: '%6Aavascript', path: 'alert(1)' }),
138
- /URI scheme is malformed\./,
139
- 'encoded scheme cannot serialize as javascript:'
100
+ 'valid decoded scheme is serialized'
140
101
  )
141
102
  t.throws(
142
103
  () => fastURI.serialize({ scheme: '//evil.example', path: '/pwn' }),
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Returns true if the value is a valid ISO-8601 duration.
3
- * @specification https://tools.ietf.org/html/rfc3339
2
+ * Returns true if the value is a valid duration.
3
+ * @specification https://www.rfc-editor.org/rfc/rfc3339.html#appendix-A
4
4
  */
5
5
  export declare function IsDuration(value: string): boolean;
@@ -1,7 +1,7 @@
1
1
  const Duration = /^P((\d+Y(\d+M(\d+D)?)?|\d+M(\d+D)?|\d+D)(T(\d+H(\d+M(\d+S)?)?|\d+M(\d+S)?|\d+S))?|T(\d+H(\d+M(\d+S)?)?|\d+M(\d+S)?|\d+S)|\d+W)$/;
2
2
  /**
3
- * Returns true if the value is a valid ISO-8601 duration.
4
- * @specification https://tools.ietf.org/html/rfc3339
3
+ * Returns true if the value is a valid duration.
4
+ * @specification https://www.rfc-editor.org/rfc/rfc3339.html#appendix-A
5
5
  */
6
6
  export function IsDuration(value) {
7
7
  return Duration.test(value);
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Returns true if the value is an IdnEmail
3
3
  * @specification https://datatracker.ietf.org/doc/html/rfc4952
4
+ * @specification https://datatracker.ietf.org/doc/html/rfc6531
4
5
  */
5
6
  export declare function IsIdnEmail(value: string): boolean;
@@ -2,6 +2,7 @@ const IdnEmail = /^(?:[A-Za-z0-9!#$%&'*+\/=?^_`{|}~\u{0080}-\u{10FFFF}-]+(?:\.[A
2
2
  /**
3
3
  * Returns true if the value is an IdnEmail
4
4
  * @specification https://datatracker.ietf.org/doc/html/rfc4952
5
+ * @specification https://datatracker.ietf.org/doc/html/rfc6531
5
6
  */
6
7
  export function IsIdnEmail(value) {
7
8
  return IdnEmail.test(value.normalize('NFC'));
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Returns true if the value is a valid internationalized (IDN) hostname.
3
- * @specification https://tools.ietf.org/html/rfc3490
3
+ * @specification https://datatracker.ietf.org/doc/html/rfc5890
4
4
  * @specification https://tools.ietf.org/html/rfc5891
5
5
  * @specification https://tools.ietf.org/html/rfc5892
6
6
  * @specification https://tools.ietf.org/html/rfc5893
@@ -1,7 +1,7 @@
1
1
  import * as Idna from './idna/index.mjs';
2
2
  /**
3
3
  * Returns true if the value is a valid internationalized (IDN) hostname.
4
- * @specification https://tools.ietf.org/html/rfc3490
4
+ * @specification https://datatracker.ietf.org/doc/html/rfc5890
5
5
  * @specification https://tools.ietf.org/html/rfc5891
6
6
  * @specification https://tools.ietf.org/html/rfc5892
7
7
  * @specification https://tools.ietf.org/html/rfc5893
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Returns true if the value is a IPV4 address
3
- * @specification http://tools.ietf.org/html/rfc2673#section-3.2
2
+ * Returns true if the value is an IPv4 address
3
+ * @specification https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2
4
4
  */
5
5
  export declare function IsIPv4(value: string): boolean;
@@ -1,7 +1,7 @@
1
1
  const IPv4 = /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;
2
2
  /**
3
- * Returns true if the value is a IPV4 address
4
- * @specification http://tools.ietf.org/html/rfc2673#section-3.2
3
+ * Returns true if the value is an IPv4 address
4
+ * @specification https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2
5
5
  */
6
6
  export function IsIPv4(value) {
7
7
  return IPv4.test(value);
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * Returns true if the value is an IPv6 address
3
- * @specification http://tools.ietf.org/html/rfc2373#section-2.2
3
+ * @specification https://datatracker.ietf.org/doc/html/rfc4291#section-2.2
4
4
  */
5
5
  export declare function IsIPv6(value: string): boolean;
@@ -1,7 +1,7 @@
1
1
  const IPv6 = /^(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:)?[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)$/i;
2
2
  /**
3
3
  * Returns true if the value is an IPv6 address
4
- * @specification http://tools.ietf.org/html/rfc2373#section-2.2
4
+ * @specification https://datatracker.ietf.org/doc/html/rfc4291#section-2.2
5
5
  */
6
6
  export function IsIPv6(value) {
7
7
  return IPv6.test(value);