Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat: enforce AWS Marketplace cancellation in x402 access hook

nirholasa5cdf3fbde31
diff --git a/api/_lib/aws-marketplace-bridge.js b/api/_lib/aws-marketplace-bridge.js
index 2b7696135..65fa6ff7b 100644
--- a/api/_lib/aws-marketplace-bridge.js
+++ b/api/_lib/aws-marketplace-bridge.js
@@ -38,6 +38,28 @@ import {
const AWS_META_KEY = 'aws_customer_identifier';
+/**
+ * Returns true when an x402 subscription belongs to an AWS Marketplace
+ * customer whose AWS-side subscription_status is no longer active. The
+ * access-control hook calls this so cancellations are enforced even before
+ * the SNS unsubscribe-success notification revokes the x402 row (delivery
+ * can lag by minutes). Returns false when the subscription isn't AWS-issued.
+ */
+export async function isAwsCustomerInactive(subscription) {
+ if (!subscription) return false;
+ if (subscription.meta?.source !== 'aws-marketplace') return false;
+ const customerId = subscription.meta?.[AWS_META_KEY];
+ if (!customerId) return false;
+ const [row] = await sql`
+ select subscription_status
+ from aws_marketplace_customers
+ where customer_identifier = ${customerId}
+ limit 1
+ `;
+ if (!row) return true;
+ return row.subscription_status === 'cancelled' || row.subscription_status === 'expired';
+}
+
function rateLimitForCustomer(customer) {
// Per-offer rate-limit overrides via env. Pattern: AWS_MP_RATE_LIMIT_<OFFER_ID>.
// Falls back to the default. Useful when a single product code has multiple
diff --git a/api/_lib/x402/access-control.js b/api/_lib/x402/access-control.js
index 63aa331b1..b69f19ce8 100644
--- a/api/_lib/x402/access-control.js
+++ b/api/_lib/x402/access-control.js
@@ -24,7 +24,10 @@ import {
lookupSubscription,
} from './api-keys.js';
import { clientIp } from '../rate-limit.js';
-import { meterAwsSubscriptionUsage } from '../aws-marketplace-bridge.js';
+import {
+ isAwsCustomerInactive,
+ meterAwsSubscriptionUsage,
+} from '../aws-marketplace-bridge.js';
const API_KEY_HEADER = 'x-api-key';
@@ -126,6 +129,20 @@ export function installAccessControl({ requiredScope, resolveCaller } = {}) {
});
return { abort: true, status: 403, reason: 'Subscription expired' };
}
+ // Defense-in-depth for AWS Marketplace: when AWS has cancelled the
+ // customer's subscription but the unsubscribe-success SNS notification
+ // hasn't yet revoked the x402 row, abort here. Without this, a few
+ // minutes of zombie bypass would slip through during the SNS lag.
+ if (await isAwsCustomerInactive(sub)) {
+ logAccess({
+ callerId: `abort:aws_inactive:${sub.id}`,
+ route,
+ reason: 'AWS Marketplace subscription inactive',
+ granted: false,
+ meta,
+ });
+ return { abort: true, status: 403, reason: 'AWS Marketplace subscription inactive' };
+ }
const rl = await checkRateLimit(sub, route);
if (!rl.allowed) {
logAccess({