From 47c1af7015726b766d3d3dbee0c6864ccaebc76f Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 27 Sep 2026 15:46:26 +0000 Subject: [PATCH] =?UTF-8?q?Stripe:=20Testadresse=20STRIPE=5FAPI=5FBASE=20n?= =?UTF-8?q?ur=20f=C3=BCr=20127.0.0.1/localhost?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ein verirrter Wert in Produktion kann den Live-Schlüssel so nie an einen fremden Server schicken; getStripe() bricht mit klarer Meldung ab. Co-Authored-By: Claude Opus 5.5 --- server/services/stripeBilling.js | 6 +++++- test/stripeApiBase.test.js | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/stripeApiBase.test.js diff --git a/server/services/stripeBilling.js b/server/services/stripeBilling.js index 01417c4..adbec07 100644 --- a/server/services/stripeBilling.js +++ b/server/services/stripeBilling.js @@ -32,9 +32,13 @@ export function getStripe() { } if (!stripeClient) { const options = { maxNetworkRetries: 2 } - // Tests: Stripe-Nachbau auf 127.0.0.1 (config.stripe.apiBase ist in Produktion leer) + // Tests: Stripe-Nachbau auf 127.0.0.1 (config.stripe.apiBase ist in Produktion leer). Nur lokale + // Adressen, damit ein verirrter Wert den Schlüssel nie an einen fremden Server schickt. if (config.stripe.apiBase) { const base = new URL(config.stripe.apiBase) + if (!['127.0.0.1', 'localhost'].includes(base.hostname)) { + throw new Error(`STRIPE_API_BASE darf nur auf 127.0.0.1 oder localhost zeigen, nicht auf ${base.hostname}.`) + } Object.assign(options, { host: base.hostname, port: Number(base.port), protocol: base.protocol.replace(':', '') }) } stripeClient = new Stripe(config.stripe.secretKey, options) diff --git a/test/stripeApiBase.test.js b/test/stripeApiBase.test.js new file mode 100644 index 0000000..41c47a1 --- /dev/null +++ b/test/stripeApiBase.test.js @@ -0,0 +1,11 @@ +import { test } from 'node:test' +import assert from 'node:assert/strict' + +// Fehlkonfiguration in Produktion: STRIPE_API_BASE zeigt auf einen fremden Server +process.env.STRIPE_SECRET_KEY = 'sk_live_nicht_echt' +process.env.STRIPE_API_BASE = 'https://stripe.fremd.example' +const { getStripe } = await import('../server/services/stripeBilling.js') + +test('STRIPE_API_BASE außerhalb von 127.0.0.1/localhost: kein Stripe-Client, klare Meldung', () => { + assert.throws(() => getStripe(), /STRIPE_API_BASE/) +})