Stripe: Testadresse STRIPE_API_BASE nur für 127.0.0.1/localhost
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
2694ef18d6
commit
47c1af7015
2 files changed
+16
-1
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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/)
|
||||
})
|
||||
Reference in new issue
Block a user