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/) +})