@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
@@ -55,7 +55,7 @@ function hasMinimumAccess(actual, required) {
55
55
  }
56
56
 
57
57
  // src/version.ts
58
- var SDK_VERSION = "2.4.11";
58
+ var SDK_VERSION = "2.4.13";
59
59
 
60
60
  // src/verify.ts
61
61
  var DEFAULT_CONFIG = {
@@ -74,22 +74,27 @@ var DEFAULT_CONFIG = {
74
74
  };
75
75
  var initCheckPerformed = false;
76
76
  var deprecationWarningShown = false;
77
- async function performInitCheck(apiBaseUrl, debug) {
77
+ async function performInitCheck(apiBaseUrl, debug, strictInit) {
78
78
  initCheckPerformed = true;
79
79
  try {
80
80
  const probeUrl = `${apiBaseUrl}/agents/verify-access`;
81
81
  const response = await fetch(probeUrl, { method: "HEAD" });
82
82
  const contentType = response.headers.get("content-type") ?? "";
83
83
  if (contentType.startsWith("text/html")) {
84
- console.warn(
85
- `[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.`
86
- );
84
+ 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).`;
85
+ if (strictInit) {
86
+ throw new Error(`${message} (strictInit=true)`);
87
+ }
88
+ console.warn(`${message} Set disableInitChecks: true on GatewayConfig to silence.`);
87
89
  } else if (debug) {
88
90
  console.log(
89
91
  `[VerificationGateway] init check passed for ${apiBaseUrl} (content-type: ${contentType})`
90
92
  );
91
93
  }
92
94
  } catch (err) {
95
+ if (strictInit) {
96
+ throw err;
97
+ }
93
98
  if (debug) {
94
99
  console.log(`[VerificationGateway] init check failed (non-blocking): ${String(err)}`);
95
100
  }
@@ -113,7 +118,23 @@ function getCacheKey(request) {
113
118
  request.counterpartyType || "",
114
119
  request.isSubAgentRequest ? "1" : "0",
115
120
  request.parentAgentId || "",
116
- request.subAgentDepth ?? ""
121
+ request.subAgentDepth ?? "",
122
+ // Audit F-A1-07: previously-missing dimensions that DO affect the
123
+ // backend verdict. Without these, two requests with different
124
+ // durations (e.g. 60s vs 86400s) collided on the same cache key and
125
+ // the shorter-duration allow served the longer-duration request.
126
+ request.durationRequired ?? "",
127
+ request.invocationProtocol || "",
128
+ request.enableRuntimeChallenge ? "1" : "0",
129
+ // callerMetadata fields contribute to risk model; include the ones
130
+ // backend reads. sourceIp/userAgent/forwardedFor change per-request
131
+ // so their inclusion effectively forces a re-check for any varying
132
+ // client (the right behavior — IP-driven anomaly scoring shouldn't
133
+ // be cached across IPs).
134
+ request.callerMetadata?.sourceIp || "",
135
+ request.callerMetadata?.userAgent || "",
136
+ request.callerMetadata?.forwardedFor || "",
137
+ request.callerMetadata?.agentCardUrl || ""
117
138
  ].join("|");
118
139
  }
119
140
  function getCachedResult(request) {
@@ -142,7 +163,7 @@ function createGuidanceResponse(config, reason, options = {}) {
142
163
  const isApiError = source === "api_error";
143
164
  const guidance = isApiError ? {
144
165
  message: "Verification is temporarily unavailable. Retry with exponential backoff; if the issue persists, contact support with the correlationId.",
145
- registrationUrl: `${config.apiBaseUrl.replace("/api", "")}/register`,
166
+ registrationUrl: `${config.apiBaseUrl.replace("/api", "")}/agents/register`,
146
167
  documentationUrl: `${config.apiBaseUrl.replace("/api", "")}/docs/agent-access`,
147
168
  steps: [
148
169
  "Retry the request with exponential backoff",
@@ -150,7 +171,7 @@ function createGuidanceResponse(config, reason, options = {}) {
150
171
  ]
151
172
  } : {
152
173
  message: "This service verifies AI agents before granting access. Please register your agent with AstraSync.",
153
- registrationUrl: `${config.apiBaseUrl.replace("/api", "")}/register`,
174
+ registrationUrl: `${config.apiBaseUrl.replace("/api", "")}/agents/register`,
154
175
  documentationUrl: `${config.apiBaseUrl.replace("/api", "")}/docs/agent-access`,
155
176
  steps: [
156
177
  "Register for an AstraSync account",
@@ -227,12 +248,8 @@ async function callVerifyAccessAPI(config, request) {
227
248
  "Content-Type": "application/json",
228
249
  ...config.customHeaders
229
250
  };
230
- if (credentials.authorizationHeader) {
231
- headers["Authorization"] = credentials.authorizationHeader;
232
- } else if (config.apiKey) {
233
- headers["Authorization"] = `Bearer ${config.apiKey}`;
234
- }
235
251
  if (config.apiKey) {
252
+ headers["Authorization"] = `Bearer ${config.apiKey}`;
236
253
  headers["X-API-Key"] = config.apiKey;
237
254
  }
238
255
  try {
@@ -278,7 +295,11 @@ async function callVerifyAccessAPI(config, request) {
278
295
  async function verify(config, request) {
279
296
  const mergedConfig = { ...DEFAULT_CONFIG, ...config };
280
297
  if (!initCheckPerformed && !mergedConfig.disableInitChecks && mergedConfig.apiBaseUrl) {
281
- void performInitCheck(mergedConfig.apiBaseUrl, mergedConfig.debug);
298
+ if (mergedConfig.strictInit) {
299
+ await performInitCheck(mergedConfig.apiBaseUrl, mergedConfig.debug, true);
300
+ } else {
301
+ void performInitCheck(mergedConfig.apiBaseUrl, mergedConfig.debug, false);
302
+ }
282
303
  }
283
304
  if (!deprecationWarningShown && (config.minTrustScore !== void 0 || config.minTrustScoreForFull !== void 0)) {
284
305
  deprecationWarningShown = true;
@@ -332,7 +353,7 @@ async function verify(config, request) {
332
353
  requiresApproval: apiResponse.access?.requiresApproval,
333
354
  guidance: {
334
355
  message: apiResponse.access?.reason || "Access denied by PDLSS policy",
335
- registrationUrl: `${mergedConfig.apiBaseUrl?.replace("/api", "")}/register`,
356
+ registrationUrl: `${mergedConfig.apiBaseUrl?.replace("/api", "")}/agents/register`,
336
357
  documentationUrl: `${mergedConfig.apiBaseUrl?.replace("/api", "")}/docs/pdlss`
337
358
  },
338
359
  verifiedAt: /* @__PURE__ */ new Date(),
@@ -402,13 +423,15 @@ async function verify(config, request) {
402
423
  result.denialReasons = result.recommendationReasons || [
403
424
  "Access denied by AstraSync recommendation"
404
425
  ];
405
- if (result.runtimeChallenge) {
406
- result.guidance = {
407
- message: `Verification failed: ${result.runtimeChallenge.reason || "runtime challenge failed"}`,
408
- registrationUrl: `${mergedConfig.apiBaseUrl?.replace("/api", "")}/register`,
409
- documentationUrl: `${mergedConfig.apiBaseUrl?.replace("/api", "")}/docs/runtime-challenge`
410
- };
411
- }
426
+ result.guidance = result.runtimeChallenge ? {
427
+ message: `Verification failed: ${result.runtimeChallenge.reason || "runtime challenge failed"}`,
428
+ registrationUrl: `${mergedConfig.apiBaseUrl?.replace("/api", "")}/agents/register`,
429
+ documentationUrl: `${mergedConfig.apiBaseUrl?.replace("/api", "")}/docs/runtime-challenge`
430
+ } : {
431
+ message: result.recommendationReasons?.[0] || "Access denied by AstraSync recommendation",
432
+ registrationUrl: `${mergedConfig.apiBaseUrl?.replace("/api", "")}/agents/register`,
433
+ documentationUrl: `${mergedConfig.apiBaseUrl?.replace("/api", "")}/docs/pdlss`
434
+ };
412
435
  } else if (result.recommendation === "step_up_required") {
413
436
  result.requiresStepUp = true;
414
437
  if (ACCESS_LEVEL_HIERARCHY[result.accessLevel] > ACCESS_LEVEL_HIERARCHY["read-only"]) {
@@ -538,6 +561,18 @@ function performCounterpartyPreCheck(routeConfig, astraCreds, purpose) {
538
561
  }
539
562
 
540
563
  // src/adapters/nextjs.ts
564
+ function escapeHtml(value) {
565
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
566
+ }
567
+ function sanitizeUrl(value, fallback) {
568
+ if (typeof value !== "string" || value.length === 0) return escapeHtml(fallback);
569
+ const trimmed = value.trim();
570
+ if (/^javascript:|^data:|^vbscript:/i.test(trimmed)) return escapeHtml(fallback);
571
+ if (/^https?:\/\//i.test(trimmed) || trimmed.startsWith("/")) {
572
+ return escapeHtml(trimmed);
573
+ }
574
+ return escapeHtml(fallback);
575
+ }
541
576
  function extractCredentialsFromNextRequest(request) {
542
577
  const credentials = {};
543
578
  const astraId = request.headers.get("x-astra-id") || request.headers.get("X-Astra-Id");
@@ -609,10 +644,18 @@ function extractPurpose(request) {
609
644
  }
610
645
  }
611
646
  function generateCommerceShieldHtml(result, options) {
612
- const title = options.commerceShield?.title || "AstraSync Agent Verification";
613
- const message = options.commerceShield?.message || result.guidance?.message || "This site verifies AI agents before granting access. We noticed you're visiting without AstraSync credentials.";
614
- const registrationUrl = result.guidance?.registrationUrl || "https://astrasync.ai/register";
615
- const docsUrl = result.guidance?.documentationUrl || "https://astrasync.ai/docs/agent-access";
647
+ const title = escapeHtml(options.commerceShield?.title || "AstraSync Agent Verification");
648
+ const message = escapeHtml(
649
+ options.commerceShield?.message || result.guidance?.message || "This site verifies AI agents before granting access. We noticed you're visiting without AstraSync credentials."
650
+ );
651
+ const registrationUrl = sanitizeUrl(
652
+ result.guidance?.registrationUrl,
653
+ "https://astrasync.ai/register"
654
+ );
655
+ const docsUrl = sanitizeUrl(
656
+ result.guidance?.documentationUrl,
657
+ "https://astrasync.ai/docs/agent-access"
658
+ );
616
659
  const allowGuest = options.commerceShield?.allowGuestAccess ?? true;
617
660
  return `
618
661
  <!DOCTYPE html>
@@ -734,7 +777,7 @@ function generateCommerceShieldHtml(result, options) {
734
777
  <div class="shield-steps">
735
778
  <h3>To get verified access:</h3>
736
779
  <ol>
737
- <li>Register at <a href="${registrationUrl}">astrasync.ai/register</a></li>
780
+ <li>Register at <a href="${registrationUrl}">astrasync.ai/agents/register</a></li>
738
781
  <li>Create and register your agent</li>
739
782
  <li>Add your ASTRA-ID to request headers</li>
740
783
  <li>Refresh this page</li>
@@ -822,7 +865,7 @@ function createMiddleware(options) {
822
865
  denialReasons: preCheckFailures.map((f) => f.message),
823
866
  guidance: {
824
867
  message: "Request exceeds counterparty-defined PDLSS limits.",
825
- registrationUrl: `${config.apiBaseUrl?.replace("/api", "")}/register`,
868
+ registrationUrl: `${config.apiBaseUrl?.replace("/api", "")}/agents/register`,
826
869
  documentationUrl: `${config.apiBaseUrl?.replace("/api", "")}/docs/pdlss`
827
870
  },
828
871
  verifiedAt: /* @__PURE__ */ new Date()
@@ -865,7 +908,10 @@ function createMiddleware(options) {
865
908
  const result = await verify(config, {
866
909
  credentials,
867
910
  purpose,
868
- action: request.method.toLowerCase(),
911
+ // RFC 7230 § 3.1.1 — HTTP method tokens uppercase by IANA convention.
912
+ // Backend evaluator tolerates either case as defense-in-depth
913
+ // (round-18.6 batch 2); SDK emits canonical form.
914
+ action: request.method.toUpperCase(),
869
915
  resource: pathname,
870
916
  counterpartyUrl,
871
917
  counterpartyType: config.counterpartyType || "website",