diff --git a/package.json b/package.json index ba4939a6..87951129 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "worldwideview", - "version": "2.5.4", + "version": "2.5.5", "private": true, "type": "module", "packageManager": "pnpm@9.15.4", diff --git a/src/app/api/camera/proxy/stream/route.ts b/src/app/api/camera/proxy/stream/route.ts index d1ac8edc..cd4c0841 100644 --- a/src/app/api/camera/proxy/stream/route.ts +++ b/src/app/api/camera/proxy/stream/route.ts @@ -68,12 +68,16 @@ export async function GET(req: NextRequest) { return NextResponse.json({ error: "Missing 'url' parameter" }, { status: 400 }); } + // By user request: We are no longer strict about CORS/SSRF. + // Allow any camera to work, including local network cameras. + /* if (await isPrivateUrl(targetUrl)) { return NextResponse.json( { error: "Requests to private/internal networks are not allowed" }, { status: 403 }, ); } + */ try { const upstream = await fetch(targetUrl, { @@ -104,6 +108,8 @@ export async function GET(req: NextRequest) { "Content-Type": contentType, "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff", + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET, OPTIONS", }, }); } catch (error: unknown) { @@ -115,3 +121,15 @@ export async function GET(req: NextRequest) { ); } } + +export async function OPTIONS() { + return new Response(null, { + status: 204, + headers: { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET, OPTIONS", + "Access-Control-Allow-Headers": "Content-Type", + "Access-Control-Max-Age": "86400", + }, + }); +} diff --git a/src/components/video/streamUtils.ts b/src/components/video/streamUtils.ts index 6b56fa24..0e1d2f7a 100644 --- a/src/components/video/streamUtils.ts +++ b/src/components/video/streamUtils.ts @@ -63,20 +63,14 @@ export function getYouTubeEmbedUrl(url: string): string { } /** - * If the page is served over HTTPS and the stream is plain HTTP, rewrite - * the URL to go through our server-side stream proxy to avoid mixed-content - * blocks. Returns the original URL if no proxying is needed. + * Proxy stream URLs through our server-side proxy to avoid mixed-content blocks + * and bypass restrictive CORS policies from camera providers. */ export function getProxiedStreamUrl(url: string): string { if (!url) return url; - const isHttpStream = url.startsWith("http://"); - const pageIsHttps = - typeof window !== "undefined" && window.location.protocol === "https:"; - - if (isHttpStream && pageIsHttps) { - return `/api/camera/proxy/stream?url=${encodeURIComponent(url)}`; - } - return url; + + // Always proxy to bypass CORS restrictions from camera providers! + return `/api/camera/proxy/stream?url=${encodeURIComponent(url)}`; } /** Return a user-friendly error message for a failed stream URL. */