diff --git a/cmd/admin/static/js/query.js b/cmd/admin/static/js/query.js index b09ebfca..a0d00ad2 100644 --- a/cmd/admin/static/js/query.js +++ b/cmd/admin/static/js/query.js @@ -117,9 +117,23 @@ function confirmDeleteSavedQueries(_names, _url) { $("#confirmModal").modal(); } -function queryResultLink(link, query, url) { - var external_link = ''; - return '' + query + " - " + external_link + " "; +function escapeHTML(value) { + return String(value).replace(/&/g, "&").replace(//g, ">").replace(/"/g, """).replace(/'/g, "'"); +} + +function safeHref(href) { + const s = String(href || "").trim(); + const lower = s.toLowerCase(); + // Allow relative URLs (path, hash, or query only) + if (s.startsWith("/") || s.startsWith("#") || s.startsWith("?")) { + return s; + } + // Allow only http and https absolute URLs + if (lower.startsWith("http://") || lower.startsWith("https://")) { + return s; + } + // Fallback for disallowed or empty URLs + return "#"; } function toggleSaveQuery() { diff --git a/cmd/admin/templates/queries.html b/cmd/admin/templates/queries.html index 3708d5e5..67c5237a 100644 --- a/cmd/admin/templates/queries.html +++ b/cmd/admin/templates/queries.html @@ -1,4 +1,4 @@ - + {{ $metadata := .Metadata }} {{ $leftmeta := .LeftMetadata }} {{ template "page-head" . }} @@ -13,9 +13,11 @@