From d1431cfdcde0dd24c94c54b8e6e36bde8725c4d0 Mon Sep 17 00:00:00 2001 From: Coff0xc <184964491+Coff0xc@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:07:20 +0000 Subject: [PATCH] fix(web): only http(s) asset URLs become service hrefs The Services tab wrote the stored asset URL into href with no scheme check. A javascript: or data: value stored via insert_assets or the asset API became a clickable link. Non-http(s) URLs now render as text. --- CHANGELOG.md | 1 + web/src/app/(main)/function/assets/page.tsx | 10 ++++++---- web/src/lib/http-href.test.mjs | 19 +++++++++++++++++++ web/src/lib/http-href.ts | 18 ++++++++++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 web/src/lib/http-href.test.mjs create mode 100644 web/src/lib/http-href.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 99167e1..2e4b446 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ All notable changes to this project are documented in this file. The format is b ### Fixed - **Findings CSV formula cells**: `FindingsCSV` prefixes name, class, summary, task, and other text fields that start with `=`, `+`, `-`, `@`, tab, or CR so Excel/LibreOffice do not evaluate them as formulas when the export is opened. +- **Asset service links**: the Services tab only uses an asset URL as `href` when it is `http:` or `https:`. `javascript:`, `data:`, and other schemes render as text. - **ask_operator image_path**: the screenshot path must resolve inside the task working directory (`/tasks/`). Absolute paths, `..` segments, and symlinks that leave that directory are refused, so the tool cannot copy an arbitrary server image into the operator transcript. - **insert_assets fail-closed**: when intercept or task allow/block rules cannot be loaded, `insert_assets` refuses the whole call instead of evaluating an empty rule set (which allowed every asset). The tool result does not include the underlying database error. - **BlobRange length no longer wraps int64**: `offset+length > size` overflowed when length was near MaxInt64, so the cap was skipped and `make([]byte, length)` could exhaust memory. The bound is now `length > size-offset`. diff --git a/web/src/app/(main)/function/assets/page.tsx b/web/src/app/(main)/function/assets/page.tsx index a9abecb..6d70f91 100644 --- a/web/src/app/(main)/function/assets/page.tsx +++ b/web/src/app/(main)/function/assets/page.tsx @@ -60,6 +60,7 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { api } from "@/lib/api"; import { parseCompanyScopeText } from "@/lib/company-scope"; +import { httpHref } from "@/lib/http-href"; import type { Asset, Company, CompanyScopeRule } from "@/lib/types"; import { cn } from "@/lib/utils"; @@ -605,10 +606,11 @@ export default function AssetsPage() { const isHttp = a.service_type === "http"; const svc = a.service_name || (isHttp ? "http" : "") || a.service_type || ""; let domainCell: React.ReactNode = "—"; - if (isHttp && a.url) { + const href = isHttp ? httpHref(a.url) : undefined; + if (href) { domainCell = ( ); - } else if (a.domain) { - domainCell = a.domain; + } else if (a.domain || a.url) { + domainCell = a.domain || a.url; } return ( diff --git a/web/src/lib/http-href.test.mjs b/web/src/lib/http-href.test.mjs new file mode 100644 index 0000000..3c344cf --- /dev/null +++ b/web/src/lib/http-href.test.mjs @@ -0,0 +1,19 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { httpHref } from "./http-href.ts"; + +test("httpHref allows http and https", () => { + assert.equal(httpHref("https://example.com/a"), "https://example.com/a"); + assert.equal(httpHref("http://192.0.2.1:8080/x"), "http://192.0.2.1:8080/x"); + assert.equal(httpHref(" https://example.com/a "), "https://example.com/a"); +}); + +test("httpHref refuses javascript, data, and junk", () => { + assert.equal(httpHref("javascript:alert(1)"), undefined); + assert.equal(httpHref("JAVASCRIPT:alert(1)"), undefined); + assert.equal(httpHref("data:text/html,x"), undefined); + assert.equal(httpHref("vbscript:x"), undefined); + assert.equal(httpHref("/relative"), undefined); + assert.equal(httpHref(""), undefined); + assert.equal(httpHref(null), undefined); +}); diff --git a/web/src/lib/http-href.ts b/web/src/lib/http-href.ts new file mode 100644 index 0000000..c2a5f14 --- /dev/null +++ b/web/src/lib/http-href.ts @@ -0,0 +1,18 @@ +// httpHref returns raw when it is an http(s) URL, otherwise undefined. +// Asset URLs are operator/target-supplied; javascript: and data: must not +// become href values. +export function httpHref(raw: string | undefined | null): string | undefined { + const s = (raw ?? "").trim(); + if (!s) { + return undefined; + } + try { + const u = new URL(s); + if (u.protocol === "http:" || u.protocol === "https:") { + return u.href; + } + } catch { + // not a URL + } + return undefined; +}