From 38706449f4f9090134b63c2510dc5900434ec3d7 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com.> Date: Fri, 8 Aug 2025 14:05:29 +0100 Subject: [PATCH] Created formatType() function and Fixed URL validation --- .../main/resources/static/js/githubVersion.js | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/app/core/src/main/resources/static/js/githubVersion.js b/app/core/src/main/resources/static/js/githubVersion.js index d71266fae..6660f8766 100644 --- a/app/core/src/main/resources/static/js/githubVersion.js +++ b/app/core/src/main/resources/static/js/githubVersion.js @@ -16,6 +16,17 @@ function compareVersions(version1, version2) { return 0; } +function formatType() { + // Map Java License enum to API types + let type = 'normal'; + if (licenseType === 'PRO') { + type = 'pro'; + } else if (licenseType === 'ENTERPRISE') { + type = 'enterprise'; + } + return type; +} + function getDownloadUrl() { // Only show download for non-Docker installations if (machineType === 'Docker' || machineType === 'Kubernetes') { @@ -47,13 +58,7 @@ function getDownloadUrl() { } async function getUpdateSummary() { - // Map Java License enum to API types - let type = 'normal'; - if (licenseType === 'PRO') { - type = 'pro'; - } else if (licenseType === 'ENTERPRISE') { - type = 'enterprise'; - } + const type = formatType(); const url = `https://supabase.stirling.com/functions/v1/updates?from=${currentVersion}&type=${type}&login=${activeSecurity}&summary=true`; console.log("Fetching update summary from:", url); try { @@ -73,13 +78,7 @@ async function getUpdateSummary() { } async function getFullUpdateInfo() { - // Map Java License enum to API types - let type = 'normal'; - if (licenseType === 'PRO') { - type = 'pro'; - } else if (licenseType === 'ENTERPRISE') { - type = 'enterprise'; - } + const type = formatType(); const url = `https://supabase.stirling.com/functions/v1/updates?from=${currentVersion}&type=${type}&login=${activeSecurity}&summary=false`; console.log("Fetching full update info from:", url); try { @@ -215,6 +214,17 @@ async function showUpdateModal() { .replace(/\//g, '/'); } + // Utility function to validate and sanitize URLs + function isValidUrl(url) { + if (typeof url !== 'string') return false; + try { + const urlObj = new URL(url); + return urlObj.protocol === 'https:' || urlObj.protocol === 'http:'; + } catch { + return false; + } + } + // Create initial modal with loading state const initialModalHtml = ` @@ -332,7 +342,7 @@ async function showUpdateModal() { ${version.compatibility.breaking_changes ? ` ` : ''}