Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Validate SSO redirect URLs before setting auth token

Mike Caod44592ddb5f9
diff --git a/src/app/sso/SSOPage.tsx b/src/app/sso/SSOPage.tsx
index 3cc950938..bf7fbb484 100644
--- a/src/app/sso/SSOPage.tsx
+++ b/src/app/sso/SSOPage.tsx
@@ -4,6 +4,12 @@ import { useRouter, useSearchParams } from 'next/navigation';
import { useEffect } from 'react';
import { setClientAuthToken } from '@/lib/client';
+function isSafeRedirectUrl(url: string): boolean {
+ // Must start with a single slash (relative path)
+ // Block protocol handlers (javascript:, data:, etc.) and protocol-relative URLs (//)
+ return url.startsWith('/') && !url.startsWith('//') && !url.includes(':');
+}
+
export function SSOPage() {
const router = useRouter();
const search = useSearchParams();
@@ -12,8 +18,12 @@ export function SSOPage() {
useEffect(() => {
if (url && token) {
- setClientAuthToken(token);
+ if (!isSafeRedirectUrl(url)) {
+ router.push('/');
+ return;
+ }
+ setClientAuthToken(token);
router.push(url);
}
}, [router, url, token]);