url-safety-validator-mcp 1.2.21 → 1.2.22

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  All notable changes to URL Safety Validator MCP are documented here.
4
4
 
5
+ ## [1.2.22] — 2026-06-18
6
+ - feat: revoke API key on Stripe refund
7
+
5
8
  ## [1.2.21] — 2026-06-17
6
9
  - fix: Stripe webhook now validates payment_link ID — ignores events not belonging to this server
7
10
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "url-safety-validator-mcp",
3
3
  "mcpName": "io.github.OjasKord/url-safety-validator-mcp",
4
- "version": "1.2.21",
4
+ "version": "1.2.22",
5
5
  "description": "URL safety checker for AI agents. Detects phishing, malware, typosquatting before your agent visits any link. BLOCK/ALLOW verdict in one call.",
6
6
  "main": "src/server.js",
7
7
  "scripts": {
package/src/server.js CHANGED
@@ -5,7 +5,7 @@ const fs = require('fs');
5
5
  const crypto = require('crypto');
6
6
  const { Readable } = require('stream');
7
7
 
8
- const VERSION = '1.2.21';
8
+ const VERSION = '1.2.22';
9
9
  const PRO_UPGRADE_URL = 'https://buy.stripe.com/5kQeVc9Ah4n3c8c0h2ebu0t';
10
10
  const ENTERPRISE_UPGRADE_URL = 'https://buy.stripe.com/4gMdR88wddXDfko0h2ebu0u';
11
11
  const ALLOWED_PAYMENT_LINK_IDS = ['plink_1TQzIHD6WvRe6sn3820kFk07', 'plink_1TQzJdD6WvRe6sn3GN8mQkj9'];
@@ -158,6 +158,26 @@ async function redisExpire(key, seconds) {
158
158
  } catch(e) { console.error('[Redis] redisExpire failed:', e); }
159
159
  }
160
160
 
161
+ async function redisDelete(key) {
162
+ try {
163
+ const res = await fetch(
164
+ `${UPSTASH_URL}/del/${encodeURIComponent(key)}`,
165
+ { method: 'POST', headers: { Authorization: `Bearer ${UPSTASH_TOKEN}` } }
166
+ );
167
+ const data = await res.json();
168
+ if (data.error) console.error('[Redis] redisDelete error:', data.error, 'key:', key);
169
+ } catch(e) { console.error('[Redis] redisDelete failed:', e); }
170
+ }
171
+
172
+ async function findCheckoutSessionEmail(paymentIntentId) {
173
+ const res = await fetch(
174
+ `https://api.stripe.com/v1/checkout/sessions?payment_intent=${encodeURIComponent(paymentIntentId)}`,
175
+ { headers: { Authorization: `Bearer ${process.env.STRIPE_SECRET_KEY}` } }
176
+ );
177
+ const data = await res.json();
178
+ return data.data?.[0]?.customer_details?.email || data.data?.[0]?.customer_email || null;
179
+ }
180
+
161
181
  async function redisKeys(pattern) {
162
182
  try {
163
183
  const res = await fetch(
@@ -712,6 +732,40 @@ const server = http.createServer(async (req, res) => {
712
732
  sendApiKeyEmail(email, key, 'pro').catch(err => console.error('[stripe] Email send failed:', err.message));
713
733
  }
714
734
  }
735
+ if (event.type === 'charge.refunded') {
736
+ if (!process.env.STRIPE_SECRET_KEY) {
737
+ console.error('[url-safety] STRIPE_SECRET_KEY not set — cannot revoke key on refund');
738
+ res.writeHead(200, cors); res.end(JSON.stringify({ received: true, ignored: true })); return;
739
+ }
740
+ const paymentIntentId = event.data.object.payment_intent;
741
+ if (!paymentIntentId) {
742
+ console.log('[url-safety] charge.refunded missing payment_intent — ignoring.');
743
+ res.writeHead(200, cors); res.end(JSON.stringify({ received: true, ignored: true })); return;
744
+ }
745
+ try {
746
+ const refundEmail = await findCheckoutSessionEmail(paymentIntentId);
747
+ if (!refundEmail) {
748
+ console.log('[url-safety] No checkout session/email found for refunded payment_intent ' + paymentIntentId);
749
+ res.writeHead(200, cors); res.end(JSON.stringify({ received: true, ignored: true })); return;
750
+ }
751
+ let revokedKey = null;
752
+ for (const [k, record] of apiKeys.entries()) {
753
+ if (record.email === refundEmail) { revokedKey = k; break; }
754
+ }
755
+ if (!revokedKey) {
756
+ console.log('[url-safety] No API key found for ' + refundEmail + ' — refund received, nothing to revoke');
757
+ res.writeHead(200, cors); res.end(JSON.stringify({ received: true, ignored: true })); return;
758
+ }
759
+ apiKeys.delete(revokedKey);
760
+ await redisDelete(`${REDIS_PREFIX}:key:${revokedKey}`);
761
+ saveStats();
762
+ console.log('[Webhook] API key revoked for ' + refundEmail + ' — refund received');
763
+ res.writeHead(200, cors); res.end(JSON.stringify({ received: true, revoked: true })); return;
764
+ } catch(e) {
765
+ console.error('[url-safety] charge.refunded handling error:', e.message);
766
+ res.writeHead(200, cors); res.end(JSON.stringify({ received: true, ignored: true })); return;
767
+ }
768
+ }
715
769
  res.writeHead(200, cors); res.end(JSON.stringify({ received: true }));
716
770
  } catch(e) {
717
771
  res.writeHead(400, cors); res.end(JSON.stringify({ error: e.message }));