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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(aws-marketplace): accept SNS messages only from the SNS service endpoint, not any amazonaws.com host
nirholasf50dfe3094e2
diff --git a/api/_lib/aws-marketplace.js b/api/_lib/aws-marketplace.jsindex 00e689b3b..3583d6480 100644--- a/api/_lib/aws-marketplace.js+++ b/api/_lib/aws-marketplace.js@@ -237,20 +237,32 @@ export function assertAwsHttpsUrl(value, label) {} catch {throw new Error(`Untrusted ${label}: ${value}`);}- if (parsed.protocol !== 'https:' || !parsed.hostname.endsWith('.amazonaws.com')) {+ // The SNS service endpoint itself, never any `*.amazonaws.com` host: that+ // suffix also covers S3 buckets and API Gateway stages anyone can create,+ // which let a forger host their own signing certificate (and so sign any+ // message they liked) or bounce this request through a redirect.+ if (parsed.protocol !== 'https:' || !SNS_HOST_RE.test(parsed.hostname) || parsed.username || parsed.password) {throw new Error(`Untrusted ${label}: ${value}`);}return parsed;}+const SNS_HOST_RE = /^sns\.[a-z0-9-]+\.amazonaws\.com(\.cn)?$/;+// AWS publishes every SNS signing certificate under this file name.+const SNS_CERT_PATH_RE = /^\/SimpleNotificationService-[A-Za-z0-9]+\.pem$/;+async function fetchCert(url) {if (certCache.has(url)) return certCache.get(url);- // Only trust certs hosted on *.amazonaws.com over HTTPS.- assertAwsHttpsUrl(url, 'SNS signing cert URL');+ // Only trust certificates served by the SNS endpoint itself, at AWS's+ // certificate path, and never follow a redirect off it.+ const parsed = assertAwsHttpsUrl(url, 'SNS signing cert URL');+ if (!SNS_CERT_PATH_RE.test(parsed.pathname) || parsed.search) {+ throw new Error(`Untrusted SNS signing cert URL: ${url}`);+ }// The PEM is cached per URL above, so this is paid once per cert rotation.- const res = await fetchUpstream(url, {}, { name: 'aws-sns-cert', timeoutMs: 8_000, attempts: 3, okWhen: () => true });+ const res = await fetchUpstream(url, { redirect: 'error' }, { name: 'aws-sns-cert', timeoutMs: 8_000, attempts: 3, okWhen: () => true });if (!res.ok) throw new Error(`Failed to fetch SNS cert: ${res.status}`);const pem = await res.text();certCache.set(url, pem);diff --git a/api/aws-marketplace/subscription.js b/api/aws-marketplace/subscription.jsindex 2424c342a..5363481dc 100644--- a/api/aws-marketplace/subscription.js+++ b/api/aws-marketplace/subscription.js@@ -184,7 +184,7 @@ async function handleSns(req, res, msg) {}try {// Confirming is idempotent (the token is single-purpose), so one retry is safe.- await fetchUpstream(subscribeUrl, {}, { timeoutMs: 8_000, attempts: 2 });+ await fetchUpstream(subscribeUrl, { redirect: 'error' }, { timeoutMs: 8_000, attempts: 2 });} catch (err) {console.error('[aws-marketplace/subscription] failed to confirm SNS subscription', err?.message);}diff --git a/tests/api/aws-marketplace-sns.test.js b/tests/api/aws-marketplace-sns.test.jsindex 59ee72426..0802402a3 100644--- a/tests/api/aws-marketplace-sns.test.js+++ b/tests/api/aws-marketplace-sns.test.js@@ -180,6 +180,15 @@ describe('assertAwsHttpsUrl', () => {.toThrow(/untrusted/i);});+ it('refuses an attacker-creatable amazonaws.com host (S3 bucket, API Gateway)', () => {+ for (const u of [+ 'https://attacker-bucket.s3.amazonaws.com/SimpleNotificationService-x.pem',+ 'https://abc123.execute-api.us-east-1.amazonaws.com/prod/c.pem',+ ]) {+ expect(() => assertAwsHttpsUrl(u, 'SNS signing cert URL')).toThrow(/untrusted/i);+ }+ });+it('refuses a non-HTTPS scheme', () => {expect(() => assertAwsHttpsUrl('http://sns.us-east-1.amazonaws.com/c.pem', 'SNS signing cert URL')).toThrow(/untrusted/i);