Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 56 additions & 26 deletions internal/api/web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ async function showBlastRadius(identityID, name) {
panel.textContent = "Loading blast radius…";
try {
const result = await fetchJSON(`/v1/identity/blast-radius?identity_id=${encodeURIComponent(identityID)}`);
const items = (result.reachable || []).slice(0, 8).map((n) => `${n.name} (${n.type})`).join(", ");
panel.innerHTML = `<strong>Blast radius — ${name}</strong><br>${result.summary}${items ? `<br><span class="meta">${items}</span>` : ""}`;
const items = (result.reachable || []).slice(0, 8).map((n) => `${escapeHTML(n.name)} (${escapeHTML(n.type)})`).join(", ");
panel.innerHTML = `<p class="blast-kicker">Identity blast radius</p><p class="blast-name">${escapeHTML(name)}</p><p class="blast-summary">${escapeHTML(result.summary || "")}</p>${items ? `<p class="meta">${items}</p>` : ""}`;
} catch (err) {
panel.textContent = `Blast radius failed: ${err.message}`;
}
Expand Down Expand Up @@ -559,21 +559,23 @@ function severityClass(level) {
function renderStats(stats) {
const el = document.getElementById("stats");
const cards = [
["Nodes", stats.nodes],
["Edges", stats.edges],
["Findings", stats.by_type?.Finding || 0],
["Workloads", stats.by_type?.Workload || 0],
["Nodes", stats.nodes, "#22d3ee"],
["Edges", stats.edges, "#6366f1"],
["Findings", stats.by_type?.Finding || 0, "#fb923c"],
["Workloads", stats.by_type?.Workload || 0, "#34d399"],
];
el.innerHTML = cards.map(([label, value]) => `
<div class="stat-card">
<div class="label">${label}</div>
<div class="value">${value ?? 0}</div>
</div>
el.innerHTML = cards.map(([label, value, accent]) => `
<article class="stat-card" style="--stat-accent: ${accent}">
<p class="label">${label}</p>
<p class="value">${value ?? 0}</p>
</article>
`).join("");
}

function renderFindings(findings, partial) {
const el = document.getElementById("findings");
const count = document.getElementById("findings-count");
if (count) count.textContent = findings.length ? (partial ? `${findings.length}+` : String(findings.length)) : "0";
const partialNote = partial
? "<p class=\"meta\">This list is partial. More findings are past the pages loaded here.</p>"
: "";
Expand All @@ -585,23 +587,34 @@ function renderFindings(findings, partial) {
const f = item.finding;
const props = f.properties || {};
const severity = props.severity || "info";
const level = severityClass(severity);
const score = props.normalized_score ?? "";
const pathLine = Array.isArray(item.path) && item.path.length
? `<div class="meta">${item.path.map((id) => escapeHTML(id)).join(" → ")}</div>`
: "";
return `
<article class="finding" data-target="${item.affected_resource_id || ""}">
<span class="severity ${severityClass(severity)}">${severity}${score === "" ? "" : " " + score}</span>
<div class="title">${f.name}</div>
<div class="meta">${props.description || props.title || ""}</div>
<article class="finding ${level}" data-target="${escapeAttr(item.affected_resource_id || "")}" tabindex="0">
<span class="severity ${level}">${escapeHTML(severity)}${score === "" ? "" : " " + escapeHTML(score)}</span>
<div class="title">${escapeHTML(f.name || "")}</div>
<div class="meta">${escapeHTML(props.description || props.title || "")}</div>
${pathLine}
<div class="resource">${item.affected_resource_name || "Unknown resource"}</div>
<div class="resource">${escapeHTML(item.affected_resource_name || "Unknown resource")}</div>
</article>
`;
}).join("") + partialNote;

el.querySelectorAll(".finding").forEach((card) => {
card.addEventListener("click", () => highlightNode(card.dataset.target));
const select = () => {
el.querySelectorAll(".finding.is-selected").forEach((other) => other.classList.remove("is-selected"));
card.classList.add("is-selected");
highlightNode(card.dataset.target);
};
card.addEventListener("click", select);
card.addEventListener("keydown", (event) => {
if (event.key !== "Enter" && event.key !== " ") return;
event.preventDefault();
select();
});
});
}

Expand All @@ -612,15 +625,19 @@ function toVisNodes(nodes) {
id: n.id,
label: n.name,
title: n.type,
borderWidth: 2,
shape: "box",
margin: 10,
borderWidth: 1.5,
shapeProperties: { borderRadius: 8 },
color: {
background: "#0d1420",
border: color,
highlight: { background: "#132033", border: "#22d3ee" },
hover: { background: "#111827", border: color },
},
font: { color: "#e2e8f0", size: 13, face: "IBM Plex Sans, system-ui, sans-serif" },
shadow: { enabled: true, color: color, size: 16, x: 0, y: 0 },
shadow: { enabled: true, color: color, size: 14, x: 0, y: 0 },
widthConstraint: { maximum: 180 },
};
});
}
Expand All @@ -631,7 +648,8 @@ function toVisEdges(edges) {
to: e.target_id,
label: e.type,
title: (e.properties && e.properties.reason) || e.type,
arrows: "to",
arrows: { to: { enabled: true, scaleFactor: 0.55 } },
width: 1.4,
color: { color: "rgba(34, 211, 238, 0.45)", highlight: "#22d3ee", hover: "#a5f3fc" },
font: {
align: "middle",
Expand All @@ -641,6 +659,7 @@ function toVisEdges(edges) {
strokeWidth: 4,
strokeColor: "#070b12",
},
smooth: { type: "continuous", roundness: 0.25 },
}));
}

Expand All @@ -652,14 +671,21 @@ function renderGraph(nodes, edges) {
edges: new vis.DataSet(toVisEdges(edges)),
};
const options = {
physics: { stabilization: true },
interaction: { hover: true },
nodes: { shape: "dot", size: 16 },
edges: { width: 1.5, smooth: { type: "continuous" } },
physics: {
barnesHut: {
gravitationalConstant: -14000,
centralGravity: 0.18,
springLength: 170,
springConstant: 0.035,
damping: 0.45,
},
stabilization: { iterations: 160 },
},
interaction: { hover: true, tooltipDelay: 80, hideEdgesOnDrag: true },
};
network = new vis.Network(container, graphData, options);
network.once("stabilizationIterationsDone", () => {
network.fit({ animation: false, padding: 72 });
network.fit({ animation: false, padding: 64 });
});
network.on("click", async (params) => {
if (!params.nodes.length) return;
Expand Down Expand Up @@ -717,6 +743,10 @@ function escapeHTML(value) {
.replaceAll(">", "&gt;");
}

function escapeAttr(value) {
return escapeHTML(value).replaceAll('"', "&quot;");
}

function auditsForPath(audits, index) {
const row = (audits || []).find((item) => item.index === index);
return row?.events || [];
Expand Down Expand Up @@ -750,7 +780,7 @@ function renderPathDetail(paths, edges, truncation, audits) {
}).join("");
const eventList = events ? `<p class="meta">CloudTrail</p><ul>${events}</ul>` : "";
const names = path.map((node) => escapeHTML(node.name)).join(" → ");
return `<p><strong>Path ${index + 1}.</strong> ${names}</p><ol>${hops.join("")}</ol>${eventList}`;
return `<article class="path-card"><p class="path-index">Path ${index + 1}</p><p class="path-title">${names}</p><ol>${hops.join("")}</ol>${eventList}</article>`;
}).join("");
}

Expand Down
32 changes: 21 additions & 11 deletions internal/api/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<body>
<header>
<div class="brand">
<svg class="logo-icon" width="40" height="40" viewBox="0 0 32 32" fill="none" aria-hidden="true">
<svg class="logo-icon" width="32" height="32" viewBox="0 0 32 32" fill="none" aria-hidden="true">
<rect width="32" height="32" rx="8" fill="#0D1420" stroke="#1E293B" />
<circle cx="16" cy="16" r="5" stroke="url(#brandGrad)" stroke-width="2" />
<circle cx="9" cy="10" r="2" fill="#6366F1" />
Expand All @@ -33,7 +33,7 @@ <h1 class="brand-name">OpenSource<span class="brand-accent">OM</span></h1>
<div id="account" class="account hidden">
<span id="account-label"></span>
<div class="settings">
<button id="settings-btn" type="button" aria-expanded="false" aria-controls="settings-menu" aria-haspopup="true">
<button id="settings-btn" class="btn btn-secondary" type="button" aria-expanded="false" aria-controls="settings-menu" aria-haspopup="true">
Settings
<span class="chevron" aria-hidden="true"></span>
</button>
Expand All @@ -49,8 +49,8 @@ <h1 class="brand-name">OpenSource<span class="brand-accent">OM</span></h1>
</header>

<section id="gate" class="gate">
<div class="gate-brand">
<svg class="logo-icon" width="64" height="64" viewBox="0 0 32 32" fill="none" aria-hidden="true">
<div class="gate-brand" aria-hidden="true">
<svg class="logo-icon" width="48" height="48" viewBox="0 0 32 32" fill="none">
<rect width="32" height="32" rx="8" fill="#0D1420" stroke="#1E293B" />
<circle cx="16" cy="16" r="5" stroke="url(#gateGrad)" stroke-width="2" />
<circle cx="9" cy="10" r="2" fill="#6366F1" />
Expand All @@ -64,9 +64,8 @@ <h1 class="brand-name">OpenSource<span class="brand-accent">OM</span></h1>
</linearGradient>
</defs>
</svg>
<p class="brand-name">OpenSource<span class="brand-accent">OM</span></p>
<p class="gate-tag">Graph-native cloud security</p>
</div>
<p class="eyebrow">Console</p>
<h2 id="gate-title">Sign in</h2>
<p id="gate-message">Checking session…</p>
<div id="gate-actions" class="gate-actions"></div>
Expand All @@ -75,26 +74,37 @@ <h2 id="gate-title">Sign in</h2>
<section id="token-banner" class="token-banner hidden" role="status">
<p>This API token is for scripts. Copy it now. It will not be shown again.</p>
<input id="token-value" readonly aria-label="Secret" />
<button id="token-dismiss" type="button">Dismiss</button>
<button id="token-dismiss" class="btn btn-secondary" type="button">Dismiss</button>
</section>
<section id="security-panel" class="admins hidden"></section>
<section id="admins-panel" class="admins hidden"></section>
<section id="stats" class="stats hidden"></section>

<main id="console" class="layout hidden">
<aside>
<h2>Findings</h2>
<div class="panel-heading">
<div>
<p class="panel-kicker">Prioritized</p>
<h2>Findings</h2>
</div>
<span id="findings-count" class="count-pill">—</span>
</div>
<div id="findings" class="findings"></div>
</aside>
<section class="graph-panel">
<div class="graph-toolbar">
<h2>Graph Explorer</h2>
<div class="panel-heading">
<div>
<p class="panel-kicker">Query the model</p>
<h2>Graph Explorer</h2>
</div>
</div>
<div class="toolbar-actions">
<select id="query-select" aria-label="Graph query">
<option value="">Full graph snapshot</option>
</select>
<button id="rules-btn" type="button">Run CSPM rules</button>
<button id="refresh-btn" type="button">Refresh</button>
<button id="rules-btn" class="btn btn-primary" type="button">Run CSPM rules</button>
<button id="refresh-btn" class="btn btn-secondary" type="button">Refresh</button>
</div>
</div>
<ul class="legend" aria-label="Node types">
Expand Down
Loading
Loading