fix: critical security issues - webhook bypass, SSRF, XSS
This commit is contained in:
parent
bba19442f4
commit
6a38ba4adc
2 changed files with 49 additions and 13 deletions
|
|
@ -2,6 +2,10 @@ import { Router, Request, Response } from "express";
|
|||
import Stripe from "stripe";
|
||||
import { createProKey, revokeByCustomer } from "../services/keys.js";
|
||||
|
||||
function escapeHtml(s: string): string {
|
||||
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
||||
}
|
||||
|
||||
let _stripe: Stripe | null = null;
|
||||
function getStripe(): Stripe {
|
||||
if (!_stripe) {
|
||||
|
|
@ -69,7 +73,7 @@ a { color: #4f9; }
|
|||
<div class="card">
|
||||
<h1>🎉 Welcome to Pro!</h1>
|
||||
<p>Your API key:</p>
|
||||
<div class="key" onclick="navigator.clipboard.writeText('${keyInfo.key}')" title="Click to copy">${keyInfo.key}</div>
|
||||
<div class="key" onclick="navigator.clipboard.writeText('${escapeHtml(keyInfo.key)}')" title="Click to copy">${escapeHtml(keyInfo.key)}</div>
|
||||
<p><strong>Save this key!</strong> It won't be shown again.</p>
|
||||
<p>10,000 PDFs/month • All endpoints • Priority support</p>
|
||||
<p><a href="/docs">View API docs →</a></p>
|
||||
|
|
@ -87,16 +91,17 @@ router.post("/webhook", async (req: Request, res: Response) => {
|
|||
|
||||
let event: Stripe.Event;
|
||||
|
||||
if (webhookSecret && sig) {
|
||||
try {
|
||||
event = getStripe().webhooks.constructEvent(req.body, sig, webhookSecret);
|
||||
} catch (err: any) {
|
||||
console.error("Webhook signature verification failed:", err.message);
|
||||
res.status(400).json({ error: "Invalid signature" });
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
event = req.body as Stripe.Event;
|
||||
if (!webhookSecret || !sig) {
|
||||
res.status(400).json({ error: "Missing webhook secret or signature" });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
event = getStripe().webhooks.constructEvent(req.body, sig, webhookSecret);
|
||||
} catch (err: any) {
|
||||
console.error("Webhook signature verification failed:", err.message);
|
||||
res.status(400).json({ error: "Invalid signature" });
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event.type) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue