@tangle-network/agent-interface 0.26.0 → 0.26.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.
@@ -1,6 +1,5 @@
1
1
  import { z } from "zod";
2
2
  import { agentCandidateGitHubRepositorySchema, gitObjectSchema, isSafeRelativePath, isWellFormedUnicode, looksLikeCredential, sha256DigestSchema, } from "./agent-candidate-schema-common.js";
3
- const base64Pattern = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
4
3
  const base64Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
5
4
  const s3BucketPattern = /^(?!\d+\.\d+\.\d+\.\d+$)[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/;
6
5
  const awsRegionPattern = /^[a-z]{2}(?:-gov)?-[a-z]+-\d$/;
@@ -11,6 +10,30 @@ function decodedBase64ByteLength(value) {
11
10
  const padding = value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0;
12
11
  return (value.length / 4) * 3 - padding;
13
12
  }
13
+ function hasBase64Shape(value) {
14
+ // Nested quantified regexes overflow V8's stack on multi-megabyte archives.
15
+ // A direct ASCII scan keeps validation linear without changing the wire format.
16
+ if (value.length % 4 !== 0)
17
+ return false;
18
+ let contentLength = value.length;
19
+ while (contentLength > 0 && value.charCodeAt(contentLength - 1) === 0x3d) {
20
+ contentLength--;
21
+ }
22
+ const paddingLength = value.length - contentLength;
23
+ if (paddingLength > 2)
24
+ return false;
25
+ for (let index = 0; index < contentLength; index++) {
26
+ const code = value.charCodeAt(index);
27
+ const isAlphabet = (code >= 0x41 && code <= 0x5a) ||
28
+ (code >= 0x61 && code <= 0x7a) ||
29
+ (code >= 0x30 && code <= 0x39) ||
30
+ code === 0x2b ||
31
+ code === 0x2f;
32
+ if (!isAlphabet)
33
+ return false;
34
+ }
35
+ return true;
36
+ }
14
37
  function hasCanonicalBase64Padding(value) {
15
38
  if (value.endsWith("==")) {
16
39
  const index = base64Alphabet.indexOf(value.at(-3) ?? "");
@@ -53,7 +76,9 @@ export const agentCandidateArtifactRefSchema = z
53
76
  export const agentCandidateEmbeddedArtifactSchema = z
54
77
  .object({
55
78
  encoding: z.literal("base64"),
56
- content: z.string().regex(base64Pattern),
79
+ content: z
80
+ .string()
81
+ .refine(hasBase64Shape, "content must be canonical base64"),
57
82
  sha256: sha256DigestSchema,
58
83
  byteLength: z.number().int().nonnegative(),
59
84
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-interface",
3
- "version": "0.26.0",
3
+ "version": "0.26.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",