mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-19 06:30:54 +08:00
Merge pull request #341 from Coff0xc/fix/asset-http-href
fix(web): only http(s) asset URLs become service hrefs
This commit is contained in:
@@ -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 (`<data>/tasks/<id>`). 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`.
|
||||
|
||||
@@ -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 = (
|
||||
<a
|
||||
href={a.url}
|
||||
href={href}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="text-blue-600 hover:underline dark:text-blue-400"
|
||||
@@ -616,8 +618,8 @@ export default function AssetsPage() {
|
||||
{a.domain || a.url}
|
||||
</a>
|
||||
);
|
||||
} else if (a.domain) {
|
||||
domainCell = a.domain;
|
||||
} else if (a.domain || a.url) {
|
||||
domainCell = a.domain || a.url;
|
||||
}
|
||||
return (
|
||||
<TableRow key={a.id} className={selected.has(a.id) ? "bg-muted/40" : undefined}>
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user