Skip to content

Commit 2fde522

Browse files
security: fix critical vulnerabilities (C1, C3, C4, C6) (#5598)
1 parent b9158ae commit 2fde522

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

web/components/templates/auth/authForm.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ const AuthForm = (props: AuthFormProps) => {
5151
const urlParam = fullUrl.substring(startIndex + 4);
5252
const decodedUrl = decodeURIComponent(urlParam);
5353

54-
window.location.href = decodedUrl as string;
54+
// Validate redirect URL to prevent open redirect attacks
55+
try {
56+
const redirectUrl = new URL(decodedUrl, window.location.origin);
57+
if (redirectUrl.origin === window.location.origin) {
58+
window.location.href = redirectUrl.href;
59+
}
60+
} catch {
61+
// Invalid URL, ignore redirect
62+
}
5563
}
5664
}, [router.query, router.asPath]);
5765

web/pages/api/intercom.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,17 @@ export default async function handler(
8585

8686
const payload = JSON.stringify(req.body);
8787

88-
// Debug: Log incoming webhook data
89-
90-
// Verify webhook signature (temporarily disabled for testing)
91-
// if (signature && !verifyIntercomWebhook(payload, signature.replace("sha256=", ""), intercomSecret)) {
92-
// return res.status(401).json({ error: "Invalid signature" });
93-
// }
88+
// Verify webhook signature
89+
if (
90+
!signature ||
91+
!verifyIntercomWebhook(
92+
payload,
93+
signature.replace("sha256=", ""),
94+
intercomSecret
95+
)
96+
) {
97+
return res.status(401).json({ error: "Invalid signature" });
98+
}
9499

95100
const webhookData = req.body as IntercomWebhookPayload;
96101
const service = new IntercomSlackService();

web/pages/api/slack-events.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ export default async function handler(
6969

7070
const payload = JSON.stringify(req.body);
7171

72-
// Verify webhook signature (temporarily disabled for testing)
73-
if (signature && !verifySlackWebhook(payload, signature, slackSecret)) {
72+
// Verify webhook signature
73+
if (!signature || !verifySlackWebhook(payload, signature, slackSecret)) {
7474
return res.status(401).json({ error: "Invalid signature" });
7575
}
76-
// Note: Webhook signature verification is disabled for testing
7776

7877
const eventData = req.body as SlackEventPayload;
7978
const service = new IntercomSlackService();

worker/RequestBodyBufferContainer/src/app.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,10 @@ export function createApp(config: AppConfig, logger: any): FastifyInstance {
226226
try {
227227
const bodyJson = JSON.parse(entry.data.toString("utf8"));
228228

229+
const DANGEROUS_KEYS = new Set(["__proto__", "constructor", "prototype"]);
229230
const applyOverride = (body: any, override: object): object => {
230231
for (const [key, value] of Object.entries(override)) {
232+
if (DANGEROUS_KEYS.has(key)) continue;
231233
if (typeof value !== "object" || value === null || Array.isArray(value)) {
232234
body[key] = value;
233235
} else {

worker/src/RequestBodyBuffer/RequestBodyBuffer_InMemory.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,15 @@ export class RequestBodyBuffer_InMemory implements IRequestBodyBuffer {
5050
}
5151

5252
// eslint-disable-next-line @typescript-eslint/no-explicit-any
53+
private static readonly DANGEROUS_KEYS = new Set([
54+
"__proto__",
55+
"constructor",
56+
"prototype",
57+
]);
58+
5359
private applyOverride(body: any, override: object): object {
5460
for (const [key, value] of Object.entries(override)) {
61+
if (RequestBodyBuffer_InMemory.DANGEROUS_KEYS.has(key)) continue;
5562
if (typeof value !== "object" || value === null || Array.isArray(value)) {
5663
body[key] = value;
5764
} else {

0 commit comments

Comments
 (0)