@openclaw/sms 2026.6.11-beta.2 → 2026.6.33

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.
@@ -6,14 +6,15 @@ import { createMessageReceiptFromOutboundResults, defineChannelMessageAdapter, w
6
6
  import { createConditionalWarningCollector } from "openclaw/plugin-sdk/channel-policy";
7
7
  import { createEmptyChannelDirectoryAdapter } from "openclaw/plugin-sdk/directory-runtime";
8
8
  import { normalizeStringEntries } from "openclaw/plugin-sdk/string-coerce-runtime";
9
- import { chunkTextForOutbound, stripMarkdown } from "openclaw/plugin-sdk/text-chunking";
9
+ import { chunkTextForOutbound, sanitizeAssistantVisibleText, stripMarkdown } from "openclaw/plugin-sdk/text-chunking";
10
10
  import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID$1, listCombinedAccountIds, resolveAccountEntry, resolveListedDefaultAccountId, resolveMergedAccountConfig } from "openclaw/plugin-sdk/account-resolution";
11
11
  import { parseStrictInteger } from "openclaw/plugin-sdk/number-runtime";
12
12
  import { buildSecretInputSchema, hasConfiguredSecretInput, normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-input";
13
13
  import { AllowFromListSchema, DmPolicySchema, buildChannelConfigSchema, requireOpenAllowFrom } from "openclaw/plugin-sdk/channel-config-primitives";
14
14
  import { requireChannelOpenAllowFrom } from "openclaw/plugin-sdk/extension-shared";
15
15
  import { z } from "zod";
16
- import { createFixedWindowRateLimiter, readRequestBodyWithLimit, registerPluginHttpRoute } from "openclaw/plugin-sdk/webhook-ingress";
16
+ import { createFixedWindowRateLimiter, readRequestBodyWithLimit, registerPluginHttpRoute, resolveRequestClientIp } from "openclaw/plugin-sdk/webhook-ingress";
17
+ import { performance } from "node:perf_hooks";
17
18
  import { resolveStableChannelMessageIngress } from "openclaw/plugin-sdk/channel-ingress-runtime";
18
19
  import { createChannelPairingChallengeIssuer } from "openclaw/plugin-sdk/channel-pairing";
19
20
  import { createHmac, timingSafeEqual } from "node:crypto";
@@ -262,17 +263,16 @@ function requestSearch(req) {
262
263
  return "";
263
264
  }
264
265
  }
265
- function configuredUrlHasQuery(url) {
266
+ function stripUrlFragment(url) {
266
267
  const hashIndex = url.indexOf("#");
267
- return (hashIndex === -1 ? url : url.slice(0, hashIndex)).includes("?");
268
+ return hashIndex === -1 ? url : url.slice(0, hashIndex);
268
269
  }
269
270
  function resolveTwilioWebhookSignatureUrl(params) {
270
- if (configuredUrlHasQuery(params.publicWebhookUrl)) return params.publicWebhookUrl;
271
+ const signatureBaseUrl = stripUrlFragment(params.publicWebhookUrl);
272
+ if (signatureBaseUrl.includes("?")) return signatureBaseUrl;
271
273
  const search = requestSearch(params.req);
272
- if (!search) return params.publicWebhookUrl;
273
- const hashIndex = params.publicWebhookUrl.indexOf("#");
274
- if (hashIndex === -1) return `${params.publicWebhookUrl}${search}`;
275
- return `${params.publicWebhookUrl.slice(0, hashIndex)}${search}${params.publicWebhookUrl.slice(hashIndex)}`;
274
+ if (!search) return signatureBaseUrl;
275
+ return `${signatureBaseUrl}${search}`;
276
276
  }
277
277
  var TwilioSmsApiError = class extends Error {
278
278
  constructor(httpStatus, responseText, operation = "send") {
@@ -538,7 +538,7 @@ async function sendSmsViaTwilio(params) {
538
538
  //#endregion
539
539
  //#region extensions/sms/src/send.ts
540
540
  function toSmsPlainText(text) {
541
- return stripMarkdown(text.replace(/```[^\n]*\n?([\s\S]*?)```/g, (_match, body) => body.trim()).replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g, (_match, label, url) => {
541
+ return stripMarkdown(sanitizeAssistantVisibleText(text).replace(/```[^\n]*\n?([\s\S]*?)```/g, (_match, body) => body.trim()).replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g, (_match, label, url) => {
542
542
  const cleanLabel = label.trim();
543
543
  const cleanUrl = url.trim();
544
544
  return cleanLabel && cleanLabel !== cleanUrl ? `${cleanLabel} (${cleanUrl})` : cleanUrl;
@@ -719,48 +719,94 @@ async function dispatchSmsInboundEvent(params) {
719
719
  }
720
720
  //#endregion
721
721
  //#region extensions/sms/src/webhook.ts
722
- const rateLimiter = createFixedWindowRateLimiter({
723
- maxRequests: 30,
722
+ const INVALID_REQUEST_MAX_REQUESTS = 300;
723
+ const CALLBACK_DISPATCH_MAX_REQUESTS = 30;
724
+ const invalidRequestRateLimiter = createFixedWindowRateLimiter({
725
+ maxRequests: INVALID_REQUEST_MAX_REQUESTS,
726
+ windowMs: 6e4,
727
+ maxTrackedKeys: 5e3
728
+ });
729
+ const callbackDispatchRateLimiter = createFixedWindowRateLimiter({
730
+ maxRequests: CALLBACK_DISPATCH_MAX_REQUESTS,
724
731
  windowMs: 6e4,
725
732
  maxTrackedKeys: 5e3
726
733
  });
727
734
  const REPLAY_CACHE_TTL_MS = 10 * 6e4;
728
735
  const REPLAY_CACHE_MAX_KEYS = 1e4;
729
- const replayCache = /* @__PURE__ */ new Map();
736
+ const replayGuardsByAccount = /* @__PURE__ */ new Map();
737
+ function createSmsWebhookReplayGuard(options = {}) {
738
+ const ttlMs = options.ttlMs ?? REPLAY_CACHE_TTL_MS;
739
+ const maxKeys = options.maxKeys ?? REPLAY_CACHE_MAX_KEYS;
740
+ const now = options.now ?? (() => performance.now());
741
+ const entries = /* @__PURE__ */ new Map();
742
+ const pruneExpired = (nowMs) => {
743
+ for (const [key, expiresAt] of entries) {
744
+ if (expiresAt > nowMs) break;
745
+ entries.delete(key);
746
+ }
747
+ };
748
+ return { remember: (messageSid) => {
749
+ const nowMs = now();
750
+ pruneExpired(nowMs);
751
+ if (entries.has(messageSid)) return { kind: "replayed" };
752
+ if (entries.size >= maxKeys) {
753
+ const oldestExpiresAt = entries.values().next().value ?? nowMs;
754
+ return {
755
+ kind: "saturated",
756
+ retryAfterMs: Math.max(0, oldestExpiresAt - nowMs)
757
+ };
758
+ }
759
+ entries.set(messageSid, nowMs + ttlMs);
760
+ return { kind: "accepted" };
761
+ } };
762
+ }
763
+ function resolveSmsWebhookReplayGuard(account) {
764
+ const key = `${account.accountId}\0${account.accountSid}`;
765
+ const existing = replayGuardsByAccount.get(key);
766
+ if (existing) return existing;
767
+ const created = createSmsWebhookReplayGuard();
768
+ replayGuardsByAccount.set(key, created);
769
+ return created;
770
+ }
730
771
  function headerValue(value) {
731
772
  if (Array.isArray(value)) return value[0];
732
773
  return value;
733
774
  }
734
- function rateLimitKey(req) {
735
- return req.socket?.remoteAddress ?? "unknown";
775
+ function resolvedClientAddress(params) {
776
+ return resolveRequestClientIp(params.req, params.cfg.gateway?.trustedProxies, params.cfg.gateway?.allowRealIpFallback === true) ?? params.req.socket?.remoteAddress ?? "unknown";
736
777
  }
737
- function rememberWebhookMessage(params) {
738
- const now = params.now ?? Date.now();
739
- for (const [key, expiresAt] of replayCache) {
740
- if (expiresAt > now && replayCache.size <= REPLAY_CACHE_MAX_KEYS) break;
741
- replayCache.delete(key);
742
- }
743
- const key = `${params.accountId}:${params.messageSid}`;
744
- if ((replayCache.get(key) ?? 0) > now) return false;
745
- replayCache.set(key, now + REPLAY_CACHE_TTL_MS);
778
+ function rateLimitKey(params) {
779
+ return `${params.account.accountId}:${params.account.webhookPath}:${params.clientAddress}`;
780
+ }
781
+ function rejectInvalidRequestRateLimit(params) {
782
+ params.log?.warn?.(`SMS webhook invalid-request rate limit exceeded for ${params.key}`);
783
+ respondTwiml(params.res, 429, "Rate limit exceeded");
746
784
  return true;
747
785
  }
748
- function createSmsWebhookHandler(params) {
786
+ function createSmsWebhookHandler(params, webhookReplayGuard = resolveSmsWebhookReplayGuard(params.account)) {
749
787
  return async (req, res) => {
750
788
  if (req.method !== "POST") {
751
789
  respondTwiml(res, 405, "Method not allowed");
752
790
  return true;
753
791
  }
754
- const key = rateLimitKey(req);
755
- if (rateLimiter.isRateLimited(key)) {
756
- params.log?.warn?.(`SMS webhook rate limit exceeded for ${key}`);
757
- respondTwiml(res, 429, "Rate limit exceeded");
758
- return true;
759
- }
792
+ const clientAddress = resolvedClientAddress({
793
+ cfg: params.cfg,
794
+ req
795
+ });
796
+ const key = rateLimitKey({
797
+ account: params.account,
798
+ clientAddress
799
+ });
800
+ const invalidRequestRateLimited = invalidRequestRateLimiter.isRateLimited(key);
760
801
  let form;
761
802
  try {
762
803
  form = await readTwilioWebhookForm(req);
763
804
  } catch {
805
+ if (invalidRequestRateLimited) return rejectInvalidRequestRateLimit({
806
+ key,
807
+ log: params.log,
808
+ res
809
+ });
764
810
  respondTwiml(res, 400, "Invalid request body");
765
811
  return true;
766
812
  }
@@ -774,6 +820,11 @@ function createSmsWebhookHandler(params) {
774
820
  authToken: params.account.authToken,
775
821
  form
776
822
  })) {
823
+ if (invalidRequestRateLimited) return rejectInvalidRequestRateLimit({
824
+ key,
825
+ log: params.log,
826
+ res
827
+ });
777
828
  params.log?.warn?.("SMS webhook rejected invalid Twilio signature");
778
829
  respondTwiml(res, 403, "Invalid signature");
779
830
  return true;
@@ -781,22 +832,47 @@ function createSmsWebhookHandler(params) {
781
832
  }
782
833
  const msg = buildTwilioInboundMessage(form);
783
834
  if (!msg) {
835
+ if (invalidRequestRateLimited) return rejectInvalidRequestRateLimit({
836
+ key,
837
+ log: params.log,
838
+ res
839
+ });
784
840
  respondTwiml(res, 400, "Missing SMS payload");
785
841
  return true;
786
842
  }
787
843
  if (msg.accountSid && msg.accountSid !== params.account.accountSid) {
844
+ if (invalidRequestRateLimited) return rejectInvalidRequestRateLimit({
845
+ key,
846
+ log: params.log,
847
+ res
848
+ });
788
849
  params.log?.warn?.("SMS webhook rejected mismatched Twilio AccountSid");
789
850
  respondTwiml(res, 403, "Invalid account");
790
851
  return true;
791
852
  }
792
- if (!rememberWebhookMessage({
793
- accountId: params.account.accountId,
794
- messageSid: msg.messageSid
795
- })) {
853
+ if (invalidRequestRateLimited && params.account.dangerouslyDisableSignatureValidation) return rejectInvalidRequestRateLimit({
854
+ key,
855
+ log: params.log,
856
+ res
857
+ });
858
+ if (callbackDispatchRateLimiter.isRateLimited(key)) {
859
+ params.log?.warn?.(`SMS webhook rate limit exceeded for ${key}`);
860
+ respondTwiml(res, 429, "Rate limit exceeded");
861
+ return true;
862
+ }
863
+ const replayDecision = webhookReplayGuard.remember(msg.messageSid);
864
+ if (replayDecision.kind === "replayed") {
796
865
  params.log?.warn?.(`SMS webhook ignored replayed message ${msg.messageSid}`);
797
866
  respondTwiml(res, 200);
798
867
  return true;
799
868
  }
869
+ if (replayDecision.kind === "saturated") {
870
+ const retryAfterSeconds = Math.max(1, Math.ceil(replayDecision.retryAfterMs / 1e3));
871
+ params.log?.warn?.("SMS webhook replay cache is full of unexpired message SIDs");
872
+ res.setHeader("Retry-After", String(retryAfterSeconds));
873
+ respondTwiml(res, 429, "Replay cache saturated");
874
+ return true;
875
+ }
800
876
  dispatchSmsInboundEvent({
801
877
  cfg: params.cfg,
802
878
  account: params.account,
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@openclaw/sms",
3
- "version": "2026.6.11-beta.2",
3
+ "version": "2026.6.33",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@openclaw/sms",
9
- "version": "2026.6.11-beta.2",
9
+ "version": "2026.6.33",
10
10
  "dependencies": {
11
11
  "zod": "4.4.3"
12
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/sms",
3
- "version": "2026.6.11-beta.2",
3
+ "version": "2026.6.33",
4
4
  "description": "OpenClaw SMS channel plugin for Twilio text messages.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,10 +26,10 @@
26
26
  "quickstartAllowFrom": true
27
27
  },
28
28
  "compat": {
29
- "pluginApi": ">=2026.6.11-beta.2"
29
+ "pluginApi": ">=2026.6.33"
30
30
  },
31
31
  "build": {
32
- "openclawVersion": "2026.6.11-beta.2",
32
+ "openclawVersion": "2026.6.33",
33
33
  "bundledDist": false
34
34
  },
35
35
  "install": {
@@ -54,7 +54,7 @@
54
54
  "README.md"
55
55
  ],
56
56
  "peerDependencies": {
57
- "openclaw": ">=2026.6.11-beta.2"
57
+ "openclaw": ">=2026.6.33"
58
58
  },
59
59
  "peerDependenciesMeta": {
60
60
  "openclaw": {