Personal Telegram developer console for GitHub

fix: share approval replay state across webhook bot instances

davoodmehraban89 committed Oct 3, 2026 at 05:57 UTC c7ca486941abe310d9bc1ee970772b1234ba98ab
1 file changed +13 -4
src/core/approval.js
+13 -4
@@ -1,5 +1,10 @@
1 const encoder = new TextEncoder();
2
3 +// Shared within a Worker isolate so approval replay state survives across
4 +// separate NexaDevBot instances created for individual webhook requests.
5 +// A durable cross-isolate store is wired in the hardening phase.
6 +const sharedUsedNonces = new Set();
7 +
8 const DEFAULT_CODECS = new Map([
9 ['github.workflow.run.rerun_failed', {
10 code: 'r',
@@ -66,14 +71,18 @@ export class ApprovalService {
71 now = () => Date.now(),
72 ttlMs = 120_000,
73 maxTokenLength = 56,
69 - signatureBytes = 12
74 + signatureBytes = 12,
75 + replayStore = sharedUsedNonces
76 } = {}) {
77 this.secret = String(secret || '');
78 this.now = now;
79 this.ttlMs = ttlMs;
80 this.maxTokenLength = maxTokenLength;
81 this.signatureBytes = signatureBytes;
76 - this.usedNonces = new Set();
82 + if (!replayStore || typeof replayStore.has !== 'function' || typeof replayStore.add !== 'function') {
83 + throw new Error('Approval replay store is invalid');
84 + }
85 + this.replayStore = replayStore;
86 this.keyPromise = null;
87 }
88
@@ -136,8 +145,8 @@ export class ApprovalService {
145
146 async consume(token, expectations = {}) {
147 const payload = await this.verify(token, expectations);
139 - if (this.usedNonces.has(payload.nonce)) throw new Error('Approval token already used');
140 - this.usedNonces.add(payload.nonce);
148 + if (this.replayStore.has(payload.nonce)) throw new Error('Approval token already used');
149 + this.replayStore.add(payload.nonce);
150 return payload;
151 }
152