@astrasyncai/verification-gateway 2.4.11 → 2.4.14

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 (91) hide show
  1. package/dist/adapter-interface/interface.d.mts +2 -2
  2. package/dist/adapter-interface/interface.d.ts +2 -2
  3. package/dist/adapters/express.d.mts +2 -2
  4. package/dist/adapters/express.d.ts +2 -2
  5. package/dist/adapters/express.js +129 -36
  6. package/dist/adapters/express.js.map +1 -1
  7. package/dist/adapters/express.mjs +129 -36
  8. package/dist/adapters/express.mjs.map +1 -1
  9. package/dist/adapters/mcp.d.mts +26 -4
  10. package/dist/adapters/mcp.d.ts +26 -4
  11. package/dist/adapters/mcp.js +94 -28
  12. package/dist/adapters/mcp.js.map +1 -1
  13. package/dist/adapters/mcp.mjs +94 -28
  14. package/dist/adapters/mcp.mjs.map +1 -1
  15. package/dist/adapters/nextjs.d.mts +2 -2
  16. package/dist/adapters/nextjs.d.ts +2 -2
  17. package/dist/adapters/nextjs.js +75 -29
  18. package/dist/adapters/nextjs.js.map +1 -1
  19. package/dist/adapters/nextjs.mjs +75 -29
  20. package/dist/adapters/nextjs.mjs.map +1 -1
  21. package/dist/adapters/sdk.d.mts +2 -2
  22. package/dist/adapters/sdk.d.ts +2 -2
  23. package/dist/adapters/sdk.js +45 -22
  24. package/dist/adapters/sdk.js.map +1 -1
  25. package/dist/adapters/sdk.mjs +45 -22
  26. package/dist/adapters/sdk.mjs.map +1 -1
  27. package/dist/agent/index.d.mts +2 -2
  28. package/dist/agent/index.d.ts +2 -2
  29. package/dist/agent/index.js +29 -0
  30. package/dist/agent/index.js.map +1 -1
  31. package/dist/agent/index.mjs +29 -0
  32. package/dist/agent/index.mjs.map +1 -1
  33. package/dist/browser/background.js +86 -24
  34. package/dist/browser/background.js.map +1 -1
  35. package/dist/browser/background.mjs +86 -24
  36. package/dist/browser/background.mjs.map +1 -1
  37. package/dist/browser/browser-adapter.d.mts +2 -2
  38. package/dist/browser/browser-adapter.d.ts +2 -2
  39. package/dist/cli/index.d.mts +2 -2
  40. package/dist/cli/index.d.ts +2 -2
  41. package/dist/cursor/cursor-adapter.d.mts +2 -2
  42. package/dist/cursor/cursor-adapter.d.ts +2 -2
  43. package/dist/cursor/extension.d.mts +2 -2
  44. package/dist/cursor/extension.d.ts +2 -2
  45. package/dist/cursor/extension.js +86 -24
  46. package/dist/cursor/extension.js.map +1 -1
  47. package/dist/cursor/extension.mjs +86 -24
  48. package/dist/cursor/extension.mjs.map +1 -1
  49. package/dist/{express-C1ePFB7n.d.ts → express-CrfwoNAR.d.ts} +1 -1
  50. package/dist/{express-4WStX3PV.d.mts → express-ienhAXps.d.mts} +1 -1
  51. package/dist/gateway/gateway.d.mts +2 -2
  52. package/dist/gateway/gateway.d.ts +2 -2
  53. package/dist/gateway/gateway.js +86 -24
  54. package/dist/gateway/gateway.js.map +1 -1
  55. package/dist/gateway/gateway.mjs +86 -24
  56. package/dist/gateway/gateway.mjs.map +1 -1
  57. package/dist/git-trigger/git-hooks.d.mts +2 -2
  58. package/dist/git-trigger/git-hooks.d.ts +2 -2
  59. package/dist/{index-ChPX4WHl.d.mts → index-B5e2IDWU.d.mts} +1 -1
  60. package/dist/{index-CzJMCgEy.d.ts → index-CCdZxvAr.d.ts} +71 -6
  61. package/dist/{index-D8IEntil.d.mts → index-CEg_WG6y.d.mts} +71 -6
  62. package/dist/{index-Cjm-zBeZ.d.ts → index-DC5f8eoQ.d.ts} +1 -1
  63. package/dist/index.d.mts +7 -7
  64. package/dist/index.d.ts +7 -7
  65. package/dist/index.js +344 -73
  66. package/dist/index.js.map +1 -1
  67. package/dist/index.mjs +344 -73
  68. package/dist/index.mjs.map +1 -1
  69. package/dist/local-evaluator/evaluator.d.mts +2 -2
  70. package/dist/local-evaluator/evaluator.d.ts +2 -2
  71. package/dist/local-evaluator/evaluator.js +12 -2
  72. package/dist/local-evaluator/evaluator.js.map +1 -1
  73. package/dist/local-evaluator/evaluator.mjs +12 -2
  74. package/dist/local-evaluator/evaluator.mjs.map +1 -1
  75. package/dist/{nextjs-BIORS__0.d.ts → nextjs-66R1KW8e.d.ts} +1 -1
  76. package/dist/{nextjs-CjzHdaXA.d.mts → nextjs-DSpisQst.d.mts} +1 -1
  77. package/dist/{sdk-Chhz-FcT.d.mts → sdk-5U_CBRpr.d.mts} +1 -1
  78. package/dist/{sdk-CqTEQAc6.d.ts → sdk-Bm8np66n.d.ts} +1 -1
  79. package/dist/transport/index.d.mts +2 -2
  80. package/dist/transport/index.d.ts +2 -2
  81. package/dist/transport/index.js +146 -28
  82. package/dist/transport/index.js.map +1 -1
  83. package/dist/transport/index.mjs +146 -28
  84. package/dist/transport/index.mjs.map +1 -1
  85. package/dist/{types-L15pYd2c.d.mts → types-B3USs-Kx.d.mts} +42 -1
  86. package/dist/{types-L15pYd2c.d.ts → types-B3USs-Kx.d.ts} +42 -1
  87. package/dist/{types-DNK2BgIf.d.mts → types-CgDCUfo8.d.mts} +1 -1
  88. package/dist/{types-DoWIuzfj.d.ts → types-R5N4ET6x.d.ts} +1 -1
  89. package/dist/ui/index.d.mts +1 -1
  90. package/dist/ui/index.d.ts +1 -1
  91. package/package.json +1 -1
@@ -18,7 +18,7 @@ function hasMinimumAccess(actual, required) {
18
18
  }
19
19
 
20
20
  // src/version.ts
21
- var SDK_VERSION = "2.4.11";
21
+ var SDK_VERSION = "2.4.13";
22
22
 
23
23
  // src/verify.ts
24
24
  var DEFAULT_CONFIG = {
@@ -37,22 +37,27 @@ var DEFAULT_CONFIG = {
37
37
  };
38
38
  var initCheckPerformed = false;
39
39
  var deprecationWarningShown = false;
40
- async function performInitCheck(apiBaseUrl, debug) {
40
+ async function performInitCheck(apiBaseUrl, debug, strictInit) {
41
41
  initCheckPerformed = true;
42
42
  try {
43
43
  const probeUrl = `${apiBaseUrl}/agents/verify-access`;
44
44
  const response = await fetch(probeUrl, { method: "HEAD" });
45
45
  const contentType = response.headers.get("content-type") ?? "";
46
46
  if (contentType.startsWith("text/html")) {
47
- console.warn(
48
- `[VerificationGateway] apiBaseUrl '${apiBaseUrl}' returned HTML (content-type: ${contentType}). This usually means apiBaseUrl is pointing at a marketing site instead of the API. Expected: 'https://astrasync.ai/api' (prod) or 'https://staging.astrasync.ai/api' (staging). Set disableInitChecks: true on GatewayConfig to silence this warning.`
49
- );
47
+ const message = `[VerificationGateway] apiBaseUrl '${apiBaseUrl}' returned HTML (content-type: ${contentType}). This usually means apiBaseUrl is pointing at a marketing site instead of the API. Expected: 'https://astrasync.ai/api' (prod) or 'https://staging.astrasync.ai/api' (staging).`;
48
+ if (strictInit) {
49
+ throw new Error(`${message} (strictInit=true)`);
50
+ }
51
+ console.warn(`${message} Set disableInitChecks: true on GatewayConfig to silence.`);
50
52
  } else if (debug) {
51
53
  console.log(
52
54
  `[VerificationGateway] init check passed for ${apiBaseUrl} (content-type: ${contentType})`
53
55
  );
54
56
  }
55
57
  } catch (err) {
58
+ if (strictInit) {
59
+ throw err;
60
+ }
56
61
  if (debug) {
57
62
  console.log(`[VerificationGateway] init check failed (non-blocking): ${String(err)}`);
58
63
  }
@@ -76,7 +81,23 @@ function getCacheKey(request) {
76
81
  request.counterpartyType || "",
77
82
  request.isSubAgentRequest ? "1" : "0",
78
83
  request.parentAgentId || "",
79
- request.subAgentDepth ?? ""
84
+ request.subAgentDepth ?? "",
85
+ // Audit F-A1-07: previously-missing dimensions that DO affect the
86
+ // backend verdict. Without these, two requests with different
87
+ // durations (e.g. 60s vs 86400s) collided on the same cache key and
88
+ // the shorter-duration allow served the longer-duration request.
89
+ request.durationRequired ?? "",
90
+ request.invocationProtocol || "",
91
+ request.enableRuntimeChallenge ? "1" : "0",
92
+ // callerMetadata fields contribute to risk model; include the ones
93
+ // backend reads. sourceIp/userAgent/forwardedFor change per-request
94
+ // so their inclusion effectively forces a re-check for any varying
95
+ // client (the right behavior — IP-driven anomaly scoring shouldn't
96
+ // be cached across IPs).
97
+ request.callerMetadata?.sourceIp || "",
98
+ request.callerMetadata?.userAgent || "",
99
+ request.callerMetadata?.forwardedFor || "",
100
+ request.callerMetadata?.agentCardUrl || ""
80
101
  ].join("|");
81
102
  }
82
103
  function getCachedResult(request) {
@@ -105,7 +126,7 @@ function createGuidanceResponse(config, reason, options = {}) {
105
126
  const isApiError = source === "api_error";
106
127
  const guidance = isApiError ? {
107
128
  message: "Verification is temporarily unavailable. Retry with exponential backoff; if the issue persists, contact support with the correlationId.",
108
- registrationUrl: `${config.apiBaseUrl.replace("/api", "")}/register`,
129
+ registrationUrl: `${config.apiBaseUrl.replace("/api", "")}/agents/register`,
109
130
  documentationUrl: `${config.apiBaseUrl.replace("/api", "")}/docs/agent-access`,
110
131
  steps: [
111
132
  "Retry the request with exponential backoff",
@@ -113,7 +134,7 @@ function createGuidanceResponse(config, reason, options = {}) {
113
134
  ]
114
135
  } : {
115
136
  message: "This service verifies AI agents before granting access. Please register your agent with AstraSync.",
116
- registrationUrl: `${config.apiBaseUrl.replace("/api", "")}/register`,
137
+ registrationUrl: `${config.apiBaseUrl.replace("/api", "")}/agents/register`,
117
138
  documentationUrl: `${config.apiBaseUrl.replace("/api", "")}/docs/agent-access`,
118
139
  steps: [
119
140
  "Register for an AstraSync account",
@@ -190,12 +211,8 @@ async function callVerifyAccessAPI(config, request) {
190
211
  "Content-Type": "application/json",
191
212
  ...config.customHeaders
192
213
  };
193
- if (credentials.authorizationHeader) {
194
- headers["Authorization"] = credentials.authorizationHeader;
195
- } else if (config.apiKey) {
196
- headers["Authorization"] = `Bearer ${config.apiKey}`;
197
- }
198
214
  if (config.apiKey) {
215
+ headers["Authorization"] = `Bearer ${config.apiKey}`;
199
216
  headers["X-API-Key"] = config.apiKey;
200
217
  }
201
218
  try {
@@ -241,7 +258,11 @@ async function callVerifyAccessAPI(config, request) {
241
258
  async function verify(config, request) {
242
259
  const mergedConfig = { ...DEFAULT_CONFIG, ...config };
243
260
  if (!initCheckPerformed && !mergedConfig.disableInitChecks && mergedConfig.apiBaseUrl) {
244
- void performInitCheck(mergedConfig.apiBaseUrl, mergedConfig.debug);
261
+ if (mergedConfig.strictInit) {
262
+ await performInitCheck(mergedConfig.apiBaseUrl, mergedConfig.debug, true);
263
+ } else {
264
+ void performInitCheck(mergedConfig.apiBaseUrl, mergedConfig.debug, false);
265
+ }
245
266
  }
246
267
  if (!deprecationWarningShown && (config.minTrustScore !== void 0 || config.minTrustScoreForFull !== void 0)) {
247
268
  deprecationWarningShown = true;
@@ -295,7 +316,7 @@ async function verify(config, request) {
295
316
  requiresApproval: apiResponse.access?.requiresApproval,
296
317
  guidance: {
297
318
  message: apiResponse.access?.reason || "Access denied by PDLSS policy",
298
- registrationUrl: `${mergedConfig.apiBaseUrl?.replace("/api", "")}/register`,
319
+ registrationUrl: `${mergedConfig.apiBaseUrl?.replace("/api", "")}/agents/register`,
299
320
  documentationUrl: `${mergedConfig.apiBaseUrl?.replace("/api", "")}/docs/pdlss`
300
321
  },
301
322
  verifiedAt: /* @__PURE__ */ new Date(),
@@ -365,13 +386,15 @@ async function verify(config, request) {
365
386
  result.denialReasons = result.recommendationReasons || [
366
387
  "Access denied by AstraSync recommendation"
367
388
  ];
368
- if (result.runtimeChallenge) {
369
- result.guidance = {
370
- message: `Verification failed: ${result.runtimeChallenge.reason || "runtime challenge failed"}`,
371
- registrationUrl: `${mergedConfig.apiBaseUrl?.replace("/api", "")}/register`,
372
- documentationUrl: `${mergedConfig.apiBaseUrl?.replace("/api", "")}/docs/runtime-challenge`
373
- };
374
- }
389
+ result.guidance = result.runtimeChallenge ? {
390
+ message: `Verification failed: ${result.runtimeChallenge.reason || "runtime challenge failed"}`,
391
+ registrationUrl: `${mergedConfig.apiBaseUrl?.replace("/api", "")}/agents/register`,
392
+ documentationUrl: `${mergedConfig.apiBaseUrl?.replace("/api", "")}/docs/runtime-challenge`
393
+ } : {
394
+ message: result.recommendationReasons?.[0] || "Access denied by AstraSync recommendation",
395
+ registrationUrl: `${mergedConfig.apiBaseUrl?.replace("/api", "")}/agents/register`,
396
+ documentationUrl: `${mergedConfig.apiBaseUrl?.replace("/api", "")}/docs/pdlss`
397
+ };
375
398
  } else if (result.recommendation === "step_up_required") {
376
399
  result.requiresStepUp = true;
377
400
  if (ACCESS_LEVEL_HIERARCHY[result.accessLevel] > ACCESS_LEVEL_HIERARCHY["read-only"]) {
@@ -501,6 +524,18 @@ function performCounterpartyPreCheck(routeConfig, astraCreds, purpose) {
501
524
  }
502
525
 
503
526
  // src/adapters/nextjs.ts
527
+ function escapeHtml(value) {
528
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
529
+ }
530
+ function sanitizeUrl(value, fallback) {
531
+ if (typeof value !== "string" || value.length === 0) return escapeHtml(fallback);
532
+ const trimmed = value.trim();
533
+ if (/^javascript:|^data:|^vbscript:/i.test(trimmed)) return escapeHtml(fallback);
534
+ if (/^https?:\/\//i.test(trimmed) || trimmed.startsWith("/")) {
535
+ return escapeHtml(trimmed);
536
+ }
537
+ return escapeHtml(fallback);
538
+ }
504
539
  function extractCredentialsFromNextRequest(request) {
505
540
  const credentials = {};
506
541
  const astraId = request.headers.get("x-astra-id") || request.headers.get("X-Astra-Id");
@@ -572,10 +607,18 @@ function extractPurpose(request) {
572
607
  }
573
608
  }
574
609
  function generateCommerceShieldHtml(result, options) {
575
- const title = options.commerceShield?.title || "AstraSync Agent Verification";
576
- const message = options.commerceShield?.message || result.guidance?.message || "This site verifies AI agents before granting access. We noticed you're visiting without AstraSync credentials.";
577
- const registrationUrl = result.guidance?.registrationUrl || "https://astrasync.ai/register";
578
- const docsUrl = result.guidance?.documentationUrl || "https://astrasync.ai/docs/agent-access";
610
+ const title = escapeHtml(options.commerceShield?.title || "AstraSync Agent Verification");
611
+ const message = escapeHtml(
612
+ options.commerceShield?.message || result.guidance?.message || "This site verifies AI agents before granting access. We noticed you're visiting without AstraSync credentials."
613
+ );
614
+ const registrationUrl = sanitizeUrl(
615
+ result.guidance?.registrationUrl,
616
+ "https://astrasync.ai/register"
617
+ );
618
+ const docsUrl = sanitizeUrl(
619
+ result.guidance?.documentationUrl,
620
+ "https://astrasync.ai/docs/agent-access"
621
+ );
579
622
  const allowGuest = options.commerceShield?.allowGuestAccess ?? true;
580
623
  return `
581
624
  <!DOCTYPE html>
@@ -697,7 +740,7 @@ function generateCommerceShieldHtml(result, options) {
697
740
  <div class="shield-steps">
698
741
  <h3>To get verified access:</h3>
699
742
  <ol>
700
- <li>Register at <a href="${registrationUrl}">astrasync.ai/register</a></li>
743
+ <li>Register at <a href="${registrationUrl}">astrasync.ai/agents/register</a></li>
701
744
  <li>Create and register your agent</li>
702
745
  <li>Add your ASTRA-ID to request headers</li>
703
746
  <li>Refresh this page</li>
@@ -785,7 +828,7 @@ function createMiddleware(options) {
785
828
  denialReasons: preCheckFailures.map((f) => f.message),
786
829
  guidance: {
787
830
  message: "Request exceeds counterparty-defined PDLSS limits.",
788
- registrationUrl: `${config.apiBaseUrl?.replace("/api", "")}/register`,
831
+ registrationUrl: `${config.apiBaseUrl?.replace("/api", "")}/agents/register`,
789
832
  documentationUrl: `${config.apiBaseUrl?.replace("/api", "")}/docs/pdlss`
790
833
  },
791
834
  verifiedAt: /* @__PURE__ */ new Date()
@@ -828,7 +871,10 @@ function createMiddleware(options) {
828
871
  const result = await verify(config, {
829
872
  credentials,
830
873
  purpose,
831
- action: request.method.toLowerCase(),
874
+ // RFC 7230 § 3.1.1 — HTTP method tokens uppercase by IANA convention.
875
+ // Backend evaluator tolerates either case as defense-in-depth
876
+ // (round-18.6 batch 2); SDK emits canonical form.
877
+ action: request.method.toUpperCase(),
832
878
  resource: pathname,
833
879
  counterpartyUrl,
834
880
  counterpartyType: config.counterpartyType || "website",