Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c60a0c9d56 | ||
|
|
05b2dce394 | ||
|
|
390518be0f | ||
|
|
e07bc60672 | ||
|
|
d75618f9aa | ||
|
|
aa34e1c49d |
No files matched your search
@@ -0,0 +1 @@
|
||||
docker run --rm -v nmn55t4io3myfubs72worn7k_wwv-data:/data nouchka/sqlite3 /data/wwv.db "UPDATE InstalledPlugin SET config = json_set(config, '$.format', 'static', '$.dataFile', 'https://cdn.jsdelivr.net/npm/@worldwideview/[email protected]/data/military-bases.geojson') WHERE pluginId = 'military-bases';"
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "worldwideview",
|
||||
"version": "1.13.0",
|
||||
"version": "1.13.4",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"setup": "node scripts/setup.mjs",
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
UPDATE installed_plugins SET config = json_set(config, '$.format', 'static', '$.dataFile', 'https://cdn.jsdelivr.net/npm/@worldwideview/[email protected]/data/military-bases.geojson') WHERE pluginId = 'military-bases';
|
||||
@@ -24,7 +24,7 @@ export async function GET() {
|
||||
return NextResponse.json({ cameras: cache.data, cached: true, stale: true });
|
||||
}
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch GDOT cameras", details: error.message },
|
||||
{ error: "Failed to fetch GDOT cameras" },
|
||||
{ status: 502 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,11 +4,14 @@ import { isAuthEnabled } from "@/core/edition";
|
||||
import { cameraProxyLimiter } from "@/lib/rateLimiters";
|
||||
import { getClientIp } from "@/lib/rateLimit";
|
||||
|
||||
import dns from "dns/promises";
|
||||
|
||||
/**
|
||||
* Block requests to private/internal networks to prevent SSRF attacks.
|
||||
* Resolves the domain to an IP address first to prevent basic DNS rebinding.
|
||||
* Allows any external URL (needed for user-configured custom camera sources).
|
||||
*/
|
||||
function isPrivateUrl(urlStr: string): boolean {
|
||||
async function isPrivateUrl(urlStr: string): Promise<boolean> {
|
||||
try {
|
||||
const parsed = new URL(urlStr);
|
||||
const host = parsed.hostname;
|
||||
@@ -19,21 +22,36 @@ function isPrivateUrl(urlStr: string): boolean {
|
||||
// If developer overrides local restrictions, bypass checks
|
||||
if (process.env.WWV_PROXY_ALLOW_LOCAL === "true") return false;
|
||||
|
||||
// Block localhost variants
|
||||
// Block localhost variants upfront
|
||||
if (host === "localhost" || host === "127.0.0.1" || host === "::1") return true;
|
||||
|
||||
// Block private IPv4 ranges
|
||||
const parts = host.split(".").map(Number);
|
||||
// Block cloud metadata endpoints explicitly
|
||||
if (host === "metadata.google.internal") return true;
|
||||
|
||||
// Resolve the host to its IP address to prevent DNS rebinding
|
||||
let resolvedIp: string;
|
||||
try {
|
||||
const lookupResult = await dns.lookup(host);
|
||||
resolvedIp = lookupResult.address;
|
||||
} catch {
|
||||
return true; // DNS resolution failed
|
||||
}
|
||||
|
||||
// Block private IPv4 ranges using resolved IP
|
||||
const parts = resolvedIp.split(".").map(Number);
|
||||
if (parts.length === 4 && parts.every((n) => !isNaN(n))) {
|
||||
if (parts[0] === 10) return true; // 10.0.0.0/8
|
||||
if (parts[0] === 172 && parts[1] >= 16 && parts[1] <= 31) return true; // 172.16.0.0/12
|
||||
if (parts[0] === 192 && parts[1] === 168) return true; // 192.168.0.0/16
|
||||
if (parts[0] === 169 && parts[1] === 254) return true; // link-local
|
||||
if (parts[0] === 0) return true; // 0.0.0.0/8
|
||||
if (parts[0] === 127) return true; // 127.0.0.0/8
|
||||
}
|
||||
|
||||
// Block simple IPv6 private/local ranges
|
||||
if (resolvedIp === "::1" || resolvedIp.startsWith("fe80:") || resolvedIp.startsWith("fc") || resolvedIp.startsWith("fd")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Block cloud metadata endpoints
|
||||
if (host === "metadata.google.internal") return true;
|
||||
|
||||
return false;
|
||||
} catch {
|
||||
@@ -60,7 +78,7 @@ export async function GET(req: NextRequest) {
|
||||
return NextResponse.json({ error: "Missing 'url' parameter" }, { status: 400 });
|
||||
}
|
||||
|
||||
if (isPrivateUrl(targetUrl)) {
|
||||
if (await isPrivateUrl(targetUrl)) {
|
||||
return NextResponse.json(
|
||||
{ error: "Requests to private/internal networks are not allowed" },
|
||||
{ status: 403 },
|
||||
|
||||
@@ -7,7 +7,9 @@ import { getClientIp } from "@/lib/rateLimit";
|
||||
const BLOCKED_HOSTS = ["localhost", "127.0.0.1", "::1", "metadata.google.internal"];
|
||||
const MAX_STREAM_DURATION_MS = 5 * 60 * 1000; // 5 minutes
|
||||
|
||||
function isPrivateUrl(urlStr: string): boolean {
|
||||
import dns from "dns/promises";
|
||||
|
||||
async function isPrivateUrl(urlStr: string): Promise<boolean> {
|
||||
try {
|
||||
const parsed = new URL(urlStr);
|
||||
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return true;
|
||||
@@ -18,14 +20,28 @@ function isPrivateUrl(urlStr: string): boolean {
|
||||
|
||||
if (BLOCKED_HOSTS.includes(host)) return true;
|
||||
|
||||
const parts = host.split(".").map(Number);
|
||||
let resolvedIp: string;
|
||||
try {
|
||||
const lookupResult = await dns.lookup(host);
|
||||
resolvedIp = lookupResult.address;
|
||||
} catch {
|
||||
return true; // DNS resolution failed
|
||||
}
|
||||
|
||||
const parts = resolvedIp.split(".").map(Number);
|
||||
if (parts.length === 4 && parts.every((n) => !isNaN(n))) {
|
||||
if (parts[0] === 10) return true;
|
||||
if (parts[0] === 172 && parts[1] >= 16 && parts[1] <= 31) return true;
|
||||
if (parts[0] === 192 && parts[1] === 168) return true;
|
||||
if (parts[0] === 169 && parts[1] === 254) return true;
|
||||
if (parts[0] === 0) return true;
|
||||
if (parts[0] === 127) return true;
|
||||
}
|
||||
|
||||
if (resolvedIp === "::1" || resolvedIp.startsWith("fe80:") || resolvedIp.startsWith("fc") || resolvedIp.startsWith("fd")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch {
|
||||
return true;
|
||||
@@ -52,7 +68,7 @@ export async function GET(req: NextRequest) {
|
||||
return NextResponse.json({ error: "Missing 'url' parameter" }, { status: 400 });
|
||||
}
|
||||
|
||||
if (isPrivateUrl(targetUrl)) {
|
||||
if (await isPrivateUrl(targetUrl)) {
|
||||
return NextResponse.json(
|
||||
{ error: "Requests to private/internal networks are not allowed" },
|
||||
{ status: 403 },
|
||||
|
||||
@@ -56,7 +56,7 @@ export async function GET() {
|
||||
});
|
||||
}
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch traffic cameras", details: error.message },
|
||||
{ error: "Failed to fetch traffic cameras" },
|
||||
{ status: 502 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { auth } from "@/lib/auth";
|
||||
import { issueMarketplaceToken } from "@/lib/marketplace/marketplaceToken";
|
||||
import { grantTokenLimiter } from "@/lib/rateLimiters";
|
||||
import { getClientIp } from "@/lib/rateLimit";
|
||||
import { isPluginInstallEnabled } from "@/core/edition";
|
||||
import { isPluginInstallEnabled, isDemo, isDemoAdmin } from "@/core/edition";
|
||||
|
||||
const ALLOWED_REDIRECT_HOSTS = new Set([
|
||||
"localhost",
|
||||
@@ -50,16 +50,20 @@ export async function GET(request: NextRequest) {
|
||||
const session = await auth();
|
||||
|
||||
if (!session?.user) {
|
||||
// Use forwarded host or Host header for correct public URL behind reverse proxy
|
||||
const host = request.headers.get("x-forwarded-host") ?? request.headers.get("host") ?? request.nextUrl.host;
|
||||
const proto = request.headers.get("x-forwarded-proto") ?? (request.nextUrl.protocol.replace(":", ""));
|
||||
const origin = `${proto}://${host}`;
|
||||
// Use configured app URL to prevent Host header injection open redirects
|
||||
const origin = process.env.NEXT_PUBLIC_APP_URL || process.env.APP_URL || request.nextUrl.origin;
|
||||
const loginUrl = new URL("/login", origin);
|
||||
const callbackUrl = request.nextUrl.pathname + request.nextUrl.search;
|
||||
loginUrl.searchParams.set("callbackUrl", `${origin}${callbackUrl}`);
|
||||
|
||||
// Construct a relative path for callback to ensure it redirects back to the identical host
|
||||
const callbackPath = request.nextUrl.pathname + request.nextUrl.search;
|
||||
loginUrl.searchParams.set("callbackUrl", callbackPath);
|
||||
return NextResponse.redirect(loginUrl);
|
||||
}
|
||||
|
||||
if (isDemo && !isDemoAdmin(session)) {
|
||||
return NextResponse.json({ error: "Admin access required on Demo edition" }, { status: 403 });
|
||||
}
|
||||
|
||||
if (!redirectTo || !isSafeRedirect(redirectTo)) {
|
||||
return NextResponse.json({ error: "Invalid or missing redirectTo" }, { status: 400 });
|
||||
}
|
||||
|
||||
@@ -49,8 +49,10 @@ export async function GET(request: NextRequest) {
|
||||
|
||||
// Not logged in — send to login with this URL as callbackUrl
|
||||
if (!session?.user) {
|
||||
const loginUrl = new URL("/login", request.nextUrl.origin);
|
||||
loginUrl.searchParams.set("callbackUrl", request.nextUrl.toString());
|
||||
const origin = process.env.NEXT_PUBLIC_APP_URL || process.env.APP_URL || request.nextUrl.origin;
|
||||
const loginUrl = new URL("/login", origin);
|
||||
const callbackPath = request.nextUrl.pathname + request.nextUrl.search;
|
||||
loginUrl.searchParams.set("callbackUrl", callbackPath);
|
||||
return NextResponse.redirect(loginUrl);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,13 +21,7 @@ export async function POST(request: Request) {
|
||||
);
|
||||
}
|
||||
|
||||
// On demo, only the admin session may install plugins
|
||||
if (isDemo && !isDemoAdmin(await auth())) {
|
||||
return withCors(
|
||||
NextResponse.json({ error: "Admin access required" }, { status: 403 }),
|
||||
request,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
const rateLimited = marketplaceApiLimiter.check(getClientIp(request));
|
||||
if (rateLimited) return withCors(rateLimited, request);
|
||||
@@ -38,7 +32,7 @@ export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { pluginId, version, manifest } = body;
|
||||
console.log("[Marketplace Install Route] Payload received:", JSON.stringify(body, null, 2));
|
||||
console.log(`[Marketplace Install Route] Installing plugin: ${pluginId} v${version || "1.0.0"}`);
|
||||
|
||||
if (!pluginId || typeof pluginId !== "string") {
|
||||
return withCors(
|
||||
|
||||
@@ -43,8 +43,11 @@ export async function GET(request: Request) {
|
||||
|
||||
const plugins = [...activeDbPlugins, ...builtInRecords];
|
||||
|
||||
const session = await auth();
|
||||
const canManagePlugins = !isDemo || isDemoAdmin(session);
|
||||
let canManagePlugins = !isDemo;
|
||||
if (isDemo) {
|
||||
const authError = await validateMarketplaceAuth(request);
|
||||
canManagePlugins = authError === null;
|
||||
}
|
||||
|
||||
return withCors(NextResponse.json({ plugins, canManagePlugins }), request);
|
||||
} catch (err) {
|
||||
@@ -57,8 +60,11 @@ export async function GET(request: Request) {
|
||||
installedAt: "",
|
||||
}));
|
||||
|
||||
const session = await auth();
|
||||
const canManagePlugins = !isDemo || isDemoAdmin(session);
|
||||
let canManagePlugins = !isDemo;
|
||||
if (isDemo) {
|
||||
const authError = await validateMarketplaceAuth(request);
|
||||
canManagePlugins = authError === null;
|
||||
}
|
||||
|
||||
return withCors(NextResponse.json({ plugins: fallback, canManagePlugins }), request);
|
||||
}
|
||||
|
||||
@@ -22,13 +22,7 @@ export async function POST(request: Request) {
|
||||
);
|
||||
}
|
||||
|
||||
// On demo, only the admin session may uninstall plugins
|
||||
if (isDemo && !isDemoAdmin(await auth())) {
|
||||
return withCors(
|
||||
NextResponse.json({ error: "Admin access required" }, { status: 403 }),
|
||||
request,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
const rateLimited = marketplaceApiLimiter.check(getClientIp(request));
|
||||
if (rateLimited) return withCors(rateLimited, request);
|
||||
|
||||
@@ -92,14 +92,11 @@ export async function POST(req: Request) {
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: "All Overpass mirrors failed or timed out. The OSM servers are likely under heavy load.",
|
||||
lastError
|
||||
},
|
||||
{ status: lastError?.status || 504 }
|
||||
{ error: "All Overpass mirrors failed or timed out. The OSM servers are likely under heavy load." },
|
||||
{ status: 504 }
|
||||
);
|
||||
} catch (e: any) {
|
||||
console.error(`[OSMSearchProxy] Internal error:`, e);
|
||||
return NextResponse.json({ error: e.message }, { status: 500 });
|
||||
return NextResponse.json({ error: "Internal server error" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,6 @@ export function useMarketplaceSync() {
|
||||
}
|
||||
}
|
||||
|
||||
/** Load a single manifest into the plugin manager. */
|
||||
async function loadManifest(manifest: PluginManifest) {
|
||||
if (!manifest.id || loadedIds.current.has(manifest.id)) return;
|
||||
if (pluginManager.getPlugin(manifest.id)) {
|
||||
@@ -73,7 +72,23 @@ export function useMarketplaceSync() {
|
||||
try {
|
||||
console.log(`[MarketplaceSync] Loading manifest: ${manifest.id}`);
|
||||
await pluginManager.loadFromManifest(manifest);
|
||||
initLayer(manifest.id);
|
||||
|
||||
let shouldEnable = false;
|
||||
if (isDemo) {
|
||||
const envVar = process.env.NEXT_PUBLIC_DEMO_DEFAULT_PLUGINS || "";
|
||||
const demoDefaultPlugins = new Set<string>();
|
||||
envVar.split(",").forEach((s) => {
|
||||
const clean = s.trim();
|
||||
if (clean) demoDefaultPlugins.add(clean);
|
||||
});
|
||||
shouldEnable = demoDefaultPlugins.has(manifest.id);
|
||||
}
|
||||
|
||||
initLayer(manifest.id, shouldEnable);
|
||||
if (shouldEnable) {
|
||||
await pluginManager.enablePlugin(manifest.id);
|
||||
}
|
||||
|
||||
loadedIds.current.add(manifest.id);
|
||||
console.log(`[MarketplaceSync] Hot-loaded plugin "${manifest.id}"`);
|
||||
} catch (err) {
|
||||
|
||||
@@ -48,5 +48,11 @@ export function injectHostGlobals(): void {
|
||||
CameraStream,
|
||||
};
|
||||
|
||||
if (process.env.NEXT_PUBLIC_DEFAULT_ENGINE_URL) {
|
||||
(globalThis as any).__WWV_ENGINE_URL__ = process.env.NEXT_PUBLIC_DEFAULT_ENGINE_URL;
|
||||
} else {
|
||||
(globalThis as any).__WWV_ENGINE_URL__ = typeof window !== 'undefined' ? window.location.origin : 'http://localhost:5001';
|
||||
}
|
||||
|
||||
console.log("[HostGlobals] React and SDK injected for dynamic plugins");
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { verifyMarketplaceToken } from "./marketplaceToken";
|
||||
import { isDemo, isDemoAdmin } from "@/core/edition";
|
||||
|
||||
/**
|
||||
* Validate marketplace API access. Accepts (in order):
|
||||
@@ -13,7 +14,12 @@ export async function validateMarketplaceAuth(
|
||||
): Promise<NextResponse | null> {
|
||||
// 1. Try session auth first
|
||||
const session = await auth();
|
||||
if (session?.user) return null;
|
||||
if (session?.user) {
|
||||
if (isDemo && !isDemoAdmin(session)) {
|
||||
return NextResponse.json({ error: "Admin access required" }, { status: 403 });
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 2. Try marketplace JWT bearer token
|
||||
const authHeader = request.headers.get("authorization");
|
||||
|
||||
@@ -20,7 +20,7 @@ export const cameraProxyLimiter = new RateLimiter({
|
||||
/** /api/marketplace/install-redirect — prevents install spam. */
|
||||
export const installLimiter = new RateLimiter({
|
||||
windowMs: 60_000,
|
||||
maxRequests: 10,
|
||||
maxRequests: 60,
|
||||
});
|
||||
|
||||
/** /api/marketplace/grant-token — prevents JWT generation spam. */
|
||||
@@ -32,7 +32,7 @@ export const grantTokenLimiter = new RateLimiter({
|
||||
/** /api/marketplace/status, install, uninstall — general marketplace API. */
|
||||
export const marketplaceApiLimiter = new RateLimiter({
|
||||
windowMs: 60_000,
|
||||
maxRequests: 20,
|
||||
maxRequests: 60,
|
||||
});
|
||||
|
||||
/** /api/auth/[...nextauth] — prevents credential brute-force. */
|
||||
|
||||
+10
-4
@@ -47,14 +47,20 @@ export default async function proxy(req: NextRequest) {
|
||||
|
||||
// Not logged in — check if first-run (no users)
|
||||
try {
|
||||
const url = new URL("/api/auth/setup-status", req.nextUrl.origin);
|
||||
const res = await fetch(url);
|
||||
const appUrl = process.env.NEXT_PUBLIC_APP_URL || process.env.APP_URL || `http://127.0.0.1:${process.env.PORT || "3000"}`;
|
||||
const url = new URL("/api/auth/setup-status", appUrl);
|
||||
const res = await fetch(url.toString(), {
|
||||
headers: {
|
||||
"User-Agent": "WorldWideView-Middleware",
|
||||
}
|
||||
});
|
||||
const data = await res.json();
|
||||
if (data.needsSetup) {
|
||||
return NextResponse.redirect(new URL("/setup", req.nextUrl));
|
||||
return NextResponse.redirect(new URL("/setup", req.nextUrl)); // NextResponse.redirect correctly bounds redirect to client
|
||||
}
|
||||
} catch {
|
||||
} catch (e) {
|
||||
// Fall through to login redirect
|
||||
console.error("[proxy.ts] Failed to fetch setup status:", e);
|
||||
}
|
||||
|
||||
return NextResponse.redirect(new URL("/login", req.nextUrl));
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
**Describe the bug**
|
||||
Plugins fail to load on the production Coolify deployment:
|
||||
1. `military-bases` fails to load with `ManifestLoadError: Failed to load valid WorldPlugin from bundle`.
|
||||
2. Several runtime plugins (satellite, iranwarlive, gps-jamming) try to fetch from `localhost:5001` resulting in connection refused in production.
|
||||
|
||||
**To Reproduce**
|
||||
1. Deploy WWV to a non-local environment like Coolify.
|
||||
2. Enable `military-bases`. Observe error in console.
|
||||
3. Enable `satellite` or other data plugins. Observe the browser network tab failing to reach `localhost:5001`.
|
||||
|
||||
**Expected behavior**
|
||||
Plugins correctly inherit `NEXT_PUBLIC_DEFAULT_ENGINE_URL` dynamically from the host `globalThis` environment. Static plugins correctly instantiate as static instead of evaluating to a bundle.
|
||||
|
||||
**Screenshots/Logs**
|
||||
`[MarketplaceSync] Failed to load "military-bases": ... Failed to load valid WorldPlugin from bundle`
|
||||
|
||||
**Environment:**
|
||||
- OS: Server/Coolify
|
||||
- Browser: Any
|
||||
- WorldWideView Edition: demo
|
||||
Reference in new issue
Block a user