diff --git a/PUBLIC_SOURCE_EXPORT.md b/PUBLIC_SOURCE_EXPORT.md index ddf3d5f..ebc87a6 100644 --- a/PUBLIC_SOURCE_EXPORT.md +++ b/PUBLIC_SOURCE_EXPORT.md @@ -1,3 +1,3 @@ # Public source export -This source snapshot was generated from the private canonical repository at revision `b1c0935a15f5b37e107c7e8764044711415f14e1`. It contains no private Git history or operational evidence. Changes are published from the canonical repository. +This source snapshot was generated from the private canonical repository at revision `7a60c53ee2c1daebecd66a01656e323f1db72e56`. It contains no private Git history or operational evidence. Changes are published from the canonical repository. diff --git a/PUBLIC_SOURCE_MANIFEST.json b/PUBLIC_SOURCE_MANIFEST.json index be32d30..0552042 100644 --- a/PUBLIC_SOURCE_MANIFEST.json +++ b/PUBLIC_SOURCE_MANIFEST.json @@ -1,6 +1,6 @@ { "schemaVersion": 1, - "sourceRevision": "b1c0935a15f5b37e107c7e8764044711415f14e1", + "sourceRevision": "7a60c53ee2c1daebecd66a01656e323f1db72e56", "files": [ { "path": ".dockerignore", @@ -44,8 +44,8 @@ }, { "path": "backend/app/acquisition.py", - "sha256": "1c1877d1d720c66d62a6a6f518a1752f649f6b0a2fa2fda766c093d39a4f6367", - "bytes": 10499 + "sha256": "f5c10c027af35afbf47ffe21041fea5b74778e0411be3b582b7b8a224a9d09cc", + "bytes": 10698 }, { "path": "backend/app/architecture.py", @@ -62,6 +62,11 @@ "sha256": "e4795d7d60fe15fc133b2216a33b11b02086d86c4baa87de0d17d3e55ab0dbbb", "bytes": 13958 }, + { + "path": "backend/app/icons.py", + "sha256": "405206f32bbb6556708b54efcfc8ca5426ce08292dfc776c1796edde89008e7b", + "bytes": 6202 + }, { "path": "backend/app/jobs.py", "sha256": "f4deb3732d995f602980f41623e16bba5255b7125cf1dff03534cea5f571a0b4", @@ -69,8 +74,8 @@ }, { "path": "backend/app/main.py", - "sha256": "b8898a7ddb4d328b52d2e7141d50610f6ee4ac27eaa57276d095590cd4d708ba", - "bytes": 20288 + "sha256": "06eb422e6a3a42add652557852e2a6ab55c1b63f843490c6788069e0317ecd52", + "bytes": 21812 }, { "path": "backend/app/models.py", @@ -147,6 +152,11 @@ "sha256": "33a4761b7982cf1cfe492ce27174e7bf8a9b4f73bb0c6a1e41ad32357c092300", "bytes": 8017 }, + { + "path": "backend/tests/test_icons.py", + "sha256": "3e5edc43facb1366c1d8c81ec0b1a0f729eaff32f7c202a265a605ecf7aa731e", + "bytes": 5010 + }, { "path": "backend/tests/test_jobs.py", "sha256": "33917d488a72071412b524d4dc4f00fbce2035559227b3d1134f95d7337c9625", @@ -204,8 +214,8 @@ }, { "path": "docs/ARCHITECTURE.md", - "sha256": "41253e1aa1f0a816316bdf2e0d559575beb3936c538509d4d7becd4e2cd7f012", - "bytes": 15543 + "sha256": "55fde435a5ef76f520e85a9f5c7ffd7aeb6ed4bb6c327430482a1d45f5b39eef", + "bytes": 16369 }, { "path": "docs/screenshots/demo-explorer.png", @@ -249,18 +259,18 @@ }, { "path": "frontend/package-lock.json", - "sha256": "afeb669147a6a98f76c28f7f2a706595b05db881a0c76a0d7c15348c64717d4b", - "bytes": 113084 + "sha256": "7f61db141dd820899f08365cee3986f9346f7416e4411f2e7454fc583676ad72", + "bytes": 112965 }, { "path": "frontend/package.json", - "sha256": "ac706aaddfd7774ce5f0b302b3640c7570eb06c2505709c0277d97a31cbfcb2c", - "bytes": 724 + "sha256": "d73f1f5e655b78608a211b6ead339d2fb5b068a62688617458a7eadaef7762cb", + "bytes": 768 }, { "path": "frontend/playwright.config.ts", - "sha256": "7ab6930d8e7227cc1086e76a5f344e70291271a868ab72e1d36e060a7340e9d4", - "bytes": 1277 + "sha256": "3e663809a4c076a9fc4a3db5a7a4b3e7183ca979a31dcc542c5d435302055b95", + "bytes": 1445 }, { "path": "frontend/public/brand/repopulse-logo-light.svg", @@ -299,8 +309,8 @@ }, { "path": "frontend/src/App.tsx", - "sha256": "ff1d4c047772383148bc7a82a762fb5822ea1bfdb8814d97dfc0e980903f7fa3", - "bytes": 46711 + "sha256": "6df7a0b9d20304af203300346ae49c795f71f481242523f568f990e584d07669", + "bytes": 48190 }, { "path": "frontend/src/FindingsView.test.tsx", @@ -349,8 +359,8 @@ }, { "path": "frontend/src/components/DashboardView.tsx", - "sha256": "d5992db6a78aa4ec5f69220bdb4ccc0f964d5180112a0a772e750322ead883a6", - "bytes": 9042 + "sha256": "469c926bf27b13755431b15959588a7e93c517ee58a9dc2bef29b7ff9b7505a7", + "bytes": 11534 }, { "path": "frontend/src/components/DependenciesView.tsx", @@ -362,16 +372,26 @@ "sha256": "020f8299012d53bcac643897ba01d3c463f10cdd76e034ddeeff0436cb52409f", "bytes": 4280 }, + { + "path": "frontend/src/components/HealthRing.tsx", + "sha256": "955ff28d691ef51cecc3ee9079b4a35fb8541892760da3f65721790197615233", + "bytes": 2689 + }, { "path": "frontend/src/components/HistoryView.tsx", - "sha256": "d440eb2e92a7932f35f4e80f51d41be775e82c94d1f2997f1c6a979078398816", - "bytes": 4232 + "sha256": "f2a0a4f8494f8067daedb529d95a2a333ae125cc5f1e02554a9bc4c984896c9a", + "bytes": 6885 }, { "path": "frontend/src/components/HotspotsView.tsx", "sha256": "a47d2086e406d9c998f5c38a8b4cf721fb1fa0c1360f73e334da454ea7653453", "bytes": 1677 }, + { + "path": "frontend/src/components/Icon.tsx", + "sha256": "c2436035be6dcc10d62ed8ce3d8d5a6fa083cd42c5aeb4cb8af71601dbf7efce", + "bytes": 3623 + }, { "path": "frontend/src/components/OverviewView.tsx", "sha256": "c882afcdccb2eda69f5303d6d5b09da4a0d025b858ecfc97892c58ea17a58e52", @@ -384,13 +404,18 @@ }, { "path": "frontend/src/components/PortfolioAtlas.tsx", - "sha256": "db41966552e858eb37d4491606e1acca2ba837e8fb5ee8ab24e41105c67c0a4a", - "bytes": 5181 + "sha256": "e3e2e4c8dafc3c71c8dbf833d76f0aaca9b03ed30df5a298b2246af4cb5f9f76", + "bytes": 4247 }, { "path": "frontend/src/components/RemediationCenter.tsx", - "sha256": "027dc97bd1240558bc464fb38afe5d6e5ca8cc48c7a0202a756701c90b51e543", - "bytes": 2289 + "sha256": "961156d35c6e87aa42af0455a1cca9f8dad354545952081f4625c0a4c556a899", + "bytes": 2458 + }, + { + "path": "frontend/src/components/RepoAvatar.tsx", + "sha256": "78971cae26b5b9c05e4ca9336d4e78e5621fad5399f4d6cbb6bce2df285da32c", + "bytes": 1780 }, { "path": "frontend/src/components/RepositoryVisual.test.tsx", @@ -409,8 +434,8 @@ }, { "path": "frontend/src/main.tsx", - "sha256": "77aaa85d0a532963cd63d1c6171a833f73b608dd83b4085f855b279dbe922939", - "bytes": 227 + "sha256": "328b81d8983b19d4c32324b3328beab2a616c08e862b60150bbc721662a22690", + "bytes": 272 }, { "path": "frontend/src/navigation.test.ts", @@ -424,8 +449,8 @@ }, { "path": "frontend/src/styles.css", - "sha256": "93418ab9fa63bde731c390890a17c1494cae0c96f383423c6160c25d74650a43", - "bytes": 92024 + "sha256": "607e176f4c94c98c90015ea791020eb44bcdef4c5f16624272182d2bd9376ee6", + "bytes": 74524 }, { "path": "frontend/src/test-fixtures.ts", @@ -439,8 +464,8 @@ }, { "path": "frontend/vite.config.ts", - "sha256": "6d4431025685e7e3a6e32ff65a93d7f203c36fa1be9227ad236885c15616d7a7", - "bytes": 538 + "sha256": "92e303ee41b3664bac1b58cf85669e46e46ee5fce747d95a45a169e7fd12655a", + "bytes": 759 }, { "path": "package-lock.json", diff --git a/backend/app/acquisition.py b/backend/app/acquisition.py index 7374cec..4813b1f 100644 --- a/backend/app/acquisition.py +++ b/backend/app/acquisition.py @@ -92,6 +92,10 @@ class GitAcquirer: safe = re.sub(r"[^A-Za-z0-9._-]", "_", identity) return self.mirrors_root / f"{safe}.git" + def mirror_path(self, repository: Repository) -> Path: + """Return the bare mirror location for read-only consumers such as icon discovery.""" + return self._mirror_path(repository) + def _worktree_path(self, job_id: str) -> Path: if not SAFE_JOB_ID.fullmatch(job_id): raise AcquisitionError("invalid_job", "Scan job identity is invalid") diff --git a/backend/app/icons.py b/backend/app/icons.py new file mode 100644 index 0000000..bbf6d78 --- /dev/null +++ b/backend/app/icons.py @@ -0,0 +1,145 @@ +"""Read-only project icon discovery from retained bare mirrors. + +A repository's own favicon or logo makes it recognisable in the catalog. The icon is +resolved from the existing mirror at an exact revision, never from a worktree and never +by fetching: the scanned repository and the mirror are not modified. Candidates are +ranked deterministically, size-bounded and content-checked before they are served. +""" + +from __future__ import annotations + +import re +import subprocess +from collections import OrderedDict +from dataclasses import dataclass +from pathlib import Path +from threading import Lock + +from .processes import git_environment, run_bounded + +SAFE_REVISION = re.compile(r"^[0-9a-fA-F]{7,64}$") +SAFE_OBJECT = re.compile(r"^[0-9a-f]{40,64}$") +MAX_ICON_BYTES = 128 * 1024 +MAX_TREE_ENTRIES = 200_000 +MIN_RASTER_BYTES = 3 * 1024 + +_ICON_NAME = re.compile(r"^(favicon|icon|app-icon|logo|logo-mark|apple-touch-icon)([._-][a-z0-9-]*)?\.(svg|png|webp|ico)$", re.IGNORECASE) +_EXCLUDED_SEGMENT = re.compile( + r"^(node_modules|vendor|third_party|\.git|dist|build-cache|coverage|tests?|__tests__|fixtures?|examples?|screens|screenshots|mockups?|templates?)$", + re.IGNORECASE, +) +_PREFERRED_DIRECTORY = {"public": 0, "static": 1, "app": 1, "assets": 2, "icons": 2, "images": 3, "wwwroot": 1, "media": 3, "build": 4, "resources": 4, "build-resources": 4} +_NAME_RANK = {"favicon": 0, "icon": 1, "app-icon": 1, "logo-mark": 2, "logo": 3, "apple-touch-icon": 4} +_FORMAT_RANK = {"svg": 0, "png": 1, "webp": 2, "ico": 3} +MEDIA_TYPES = {"svg": "image/svg+xml", "png": "image/png", "webp": "image/webp", "ico": "image/x-icon"} + + +@dataclass(frozen=True) +class ProjectIcon: + path: str + media_type: str + content: bytes + + +def _rank(path: str, size: int) -> tuple[int, int, int, int, int, int, str] | None: + parts = path.split("/") + name = parts[-1] + match = _ICON_NAME.fullmatch(name) + if not match or size <= 0 or size > MAX_ICON_BYTES: + return None + directories = parts[:-1] + if any(_EXCLUDED_SEGMENT.fullmatch(segment) for segment in directories): + return None + if len(directories) > 6: + return None + directory_rank = min((_PREFERRED_DIRECTORY.get(segment.casefold(), 6) for segment in directories), default=5) + extension = match.group(3).casefold() + sized_variant = 1 if match.group(2) and re.search(r"\d", match.group(2)) else 0 + # Tiny raster favicons (16/32 px) look blurry at avatar size; prefer a larger raster. + low_resolution = 1 if extension != "svg" and size < MIN_RASTER_BYTES else 0 + return ( + _FORMAT_RANK[extension], + low_resolution, + _NAME_RANK[match.group(1).casefold()], + directory_rank + sized_variant, + len(directories), + size, + path, + ) + + +def _looks_like(content: bytes, extension: str) -> bool: + if extension == "png": + return content.startswith(b"\x89PNG\r\n\x1a\n") + if extension == "ico": + return content[:4] == b"\x00\x00\x01\x00" + if extension == "webp": + return content[:4] == b"RIFF" and content[8:12] == b"WEBP" + head = content[:2048].lstrip().lower() + return head.startswith((b" None: + self.mirrors_root = mirrors_root + self.timeout = timeout + self.cache_size = cache_size + self._cache: OrderedDict[tuple[str, str], ProjectIcon | None] = OrderedDict() + self._lock = Lock() + + def _git(self, mirror: Path, args: list[str]) -> bytes: + result = run_bounded(["git", "--git-dir", str(mirror), *args], timeout=self.timeout, env=git_environment()) + return result.stdout + + def resolve(self, mirror: Path, revision: str) -> ProjectIcon | None: + if not SAFE_REVISION.fullmatch(revision): + return None + try: + mirror.resolve().relative_to(self.mirrors_root.resolve()) + except (OSError, RuntimeError, ValueError): + return None + key = (str(mirror), revision.casefold()) + with self._lock: + if key in self._cache: + self._cache.move_to_end(key) + return self._cache[key] + icon = self._discover(mirror, revision) if mirror.is_dir() else None + with self._lock: + self._cache[key] = icon + self._cache.move_to_end(key) + while len(self._cache) > self.cache_size: + self._cache.popitem(last=False) + return icon + + def _discover(self, mirror: Path, revision: str) -> ProjectIcon | None: + try: + listing = self._git(mirror, ["ls-tree", "-r", "-l", "--full-tree", "-z", f"{revision}^{{tree}}"]) + except (OSError, subprocess.SubprocessError): + return None + candidates: list[tuple[tuple[int, int, int, int, int, int, str], str, str]] = [] + for index, entry in enumerate(listing.split(b"\x00")): + if index >= MAX_TREE_ENTRIES or not entry: + continue + try: + meta, raw_path = entry.split(b"\t", 1) + _mode, kind, obj, size = meta.split() + path = raw_path.decode("utf-8") + except ValueError: + continue + if kind != b"blob" or not size.isdigit(): + continue + obj_id = obj.decode("ascii", errors="ignore") + rank = _rank(path, int(size)) + if rank is not None and SAFE_OBJECT.fullmatch(obj_id): + candidates.append((rank, obj_id, path)) + for _rank_key, obj_id, path in sorted(candidates)[:8]: + try: + content = self._git(mirror, ["cat-file", "blob", obj_id]) + except (OSError, subprocess.SubprocessError): + continue + extension = path.rsplit(".", 1)[-1].casefold() + if len(content) <= MAX_ICON_BYTES and _looks_like(content, extension): + return ProjectIcon(path=path, media_type=MEDIA_TYPES[extension], content=content) + return None diff --git a/backend/app/main.py b/backend/app/main.py index 8083fd2..48a8257 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -18,6 +18,8 @@ from starlette.types import Scope from .acquisition import GitAcquirer from .gitea import GiteaClient +from .icons import SAFE_REVISION as SAFE_ICON_REVISION +from .icons import ProjectIconResolver from .jobs import ScanJobRunner from .models import ( RepositoryDetail, @@ -56,6 +58,7 @@ MAX_CONCURRENT_SCANS = 1 SCAN_SLOTS = BoundedSemaphore(MAX_CONCURRENT_SCANS) gitea_client = GiteaClient() repository_acquirer = GitAcquirer() +project_icons = ProjectIconResolver(repository_acquirer.mirrors_root) job_runner: ScanJobRunner | None = None _api_mutation_lock = Lock() _MAINTENANCE_ENTER_PATH = "/api/v1/operator/maintenance/enter" @@ -280,6 +283,30 @@ def get_repository(repository_id: str) -> RepositoryDetail: return repository +ICON_HEADERS = { + "Cache-Control": "public, max-age=86400", + "X-Content-Type-Options": "nosniff", + # Repository-supplied SVG is untrusted: never allow script, network or embedding. + "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; img-src data:; sandbox", + "Cross-Origin-Resource-Policy": "same-origin", +} + + +@app.get("/api/v1/repositories/{repository_id}/icon") +def repository_icon(repository_id: str, rev: str | None = Query(default=None, max_length=64)) -> Response: + """Serve the project's own favicon or logo from its mirror at the retained revision.""" + + repository = store.get_repository(repository_id) + if repository is None: + raise HTTPException(status_code=404, detail="Repository not found") + known = {value.casefold() for value in (repository.last_scan_revision, repository.latest_revision) if value} + revision = rev if rev and SAFE_ICON_REVISION.fullmatch(rev) and rev.casefold() in known else repository.last_scan_revision or repository.latest_revision + icon = project_icons.resolve(repository_acquirer.mirror_path(repository), revision) if revision else None + if icon is None: + return Response(status_code=status.HTTP_404_NOT_FOUND, headers={"Cache-Control": "public, max-age=3600"}) + return Response(icon.content, media_type=icon.media_type, headers=ICON_HEADERS) + + @app.get("/api/v1/repositories/{repository_id}/scans", response_model=list[ScanSummary]) def list_repository_scans( repository_id: str, diff --git a/backend/tests/test_icons.py b/backend/tests/test_icons.py new file mode 100644 index 0000000..62bed92 --- /dev/null +++ b/backend/tests/test_icons.py @@ -0,0 +1,106 @@ +from __future__ import annotations + +import subprocess +from pathlib import Path + +from app.icons import MAX_ICON_BYTES, ProjectIconResolver + +PNG = b"\x89PNG\r\n\x1a\n" + b"\x00" * 32 +SVG = b'' + + +def _mirror(tmp_path: Path, files: dict[str, bytes]) -> tuple[Path, Path, str]: + source = tmp_path / "source" + source.mkdir() + for relative, content in files.items(): + target = source / relative + target.parent.mkdir(parents=True, exist_ok=True) + target.write_bytes(content) + subprocess.run(["git", "init", "--quiet", str(source)], check=True) + subprocess.run(["git", "-C", str(source), "config", "user.email", "test@example.com"], check=True) + subprocess.run(["git", "-C", str(source), "config", "user.name", "RepoPulse Test"], check=True) + subprocess.run(["git", "-C", str(source), "add", "."], check=True) + subprocess.run(["git", "-C", str(source), "commit", "--quiet", "-m", "initial"], check=True) + revision = subprocess.run(["git", "-C", str(source), "rev-parse", "HEAD"], check=True, capture_output=True, text=True).stdout.strip() + mirrors = tmp_path / "mirrors" + mirrors.mkdir() + mirror = mirrors / "gitea-1.git" + subprocess.run(["git", "clone", "--quiet", "--mirror", str(source), str(mirror)], check=True) + return mirrors, mirror, revision + + +def test_prefers_a_public_svg_favicon_over_logos_and_excluded_fixtures(tmp_path: Path) -> None: + mirrors, mirror, revision = _mirror(tmp_path, { + "README.md": b"# Demo\n", + "docs/logo.png": PNG, + "tests/fixtures/favicon.svg": SVG, + "node_modules/pkg/favicon.svg": SVG, + "frontend/public/favicon.svg": SVG, + "frontend/public/icons.svg": SVG, + }) + icon = ProjectIconResolver(mirrors).resolve(mirror, revision) + assert icon is not None + assert icon.path == "frontend/public/favicon.svg" + assert icon.media_type == "image/svg+xml" + assert icon.content == SVG + + +def test_rejects_content_that_does_not_match_its_extension_and_oversized_files(tmp_path: Path) -> None: + mirrors, mirror, revision = _mirror(tmp_path, { + "public/favicon.svg": b"#!/bin/sh\necho not an image\n", + "public/logo.png": b"not a png", + "public/icon.png": PNG + b"\x00" * MAX_ICON_BYTES, + "app/icon.png": PNG, + }) + icon = ProjectIconResolver(mirrors).resolve(mirror, revision) + assert icon is not None + assert icon.path == "app/icon.png" + assert icon.media_type == "image/png" + + +def test_prefers_a_larger_raster_over_a_tiny_favicon(tmp_path: Path) -> None: + mirrors, mirror, revision = _mirror(tmp_path, { + "frontend/public/icons/favicon-16.png": PNG, + "frontend/public/icons/apple-touch-icon.png": PNG + bytes(8000), + }) + icon = ProjectIconResolver(mirrors).resolve(mirror, revision) + assert icon is not None + assert icon.path == "frontend/public/icons/apple-touch-icon.png" + + +def test_missing_icons_unknown_revisions_and_foreign_mirrors_resolve_to_none(tmp_path: Path) -> None: + mirrors, mirror, revision = _mirror(tmp_path, {"README.md": b"# Demo\n"}) + resolver = ProjectIconResolver(mirrors) + assert resolver.resolve(mirror, revision) is None + assert resolver.resolve(mirror, "not-a-revision") is None + assert resolver.resolve(mirror, "0" * 40) is None + assert resolver.resolve(tmp_path / "source" / ".git", revision) is None + + +def test_icon_endpoint_serves_the_mirror_icon_with_strict_headers(tmp_path: Path, monkeypatch) -> None: + from fastapi.testclient import TestClient + + from app import main as main_module + from app.models import Repository + from app.store import ScanStore + + mirrors, _mirror_path, revision = _mirror(tmp_path, {"public/favicon.svg": SVG}) + store = ScanStore(str(tmp_path / "history.db")) + repository = Repository(id="gitea:1", provider="gitea", provider_repository_id="1", owner="Jens", name="Demo", full_name="Jens/Demo", latest_revision=revision) + store.upsert_repository(repository) + empty = Repository(id="gitea:2", provider="gitea", provider_repository_id="2", owner="Jens", name="Empty", full_name="Jens/Empty") + store.upsert_repository(empty) + monkeypatch.setattr(main_module, "store", store) + monkeypatch.setattr(main_module, "project_icons", ProjectIconResolver(mirrors)) + monkeypatch.setattr(main_module.repository_acquirer, "mirrors_root", mirrors) + client = TestClient(main_module.app) + + response = client.get(f"/api/v1/repositories/gitea:1/icon?rev={revision}") + assert response.status_code == 200 + assert response.content == SVG + assert response.headers["content-type"].startswith("image/svg+xml") + assert "sandbox" in response.headers["content-security-policy"] + assert response.headers["x-content-type-options"] == "nosniff" + + assert client.get("/api/v1/repositories/gitea:2/icon").status_code == 404 + assert client.get("/api/v1/repositories/gitea:404/icon").status_code == 404 diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index adad891..0b6ba47 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -37,6 +37,8 @@ For a Gitea job, the requested SHA is captured at enqueue time. The acquirer use ## Scan boundary +Project icons are resolved read-only from the existing bare mirror at the repository's retained scan revision (`GET /api/v1/repositories/{id}/icon`). The resolver lists the tree with `git ls-tree`, ranks favicon/icon/logo candidates deterministically (SVG first, larger rasters over tiny favicons, `public`/`static`/`app` directories first, tests, fixtures, vendored and screenshot paths excluded), reads at most 128 KiB per blob with `git cat-file` and serves the file only when its content matches its extension. It never fetches, never touches a worktree and caches results per revision in memory. Responses carry `nosniff` and a sandboxing `Content-Security-Policy`, because repository-supplied SVG is untrusted; the frontend renders icons through `` and falls back to readiness-tinted initials when no icon exists. + When `REPOPULSE_SCAN_ROOT` is configured, every local scan path is resolved and checked against that root before analysis. Compose sets the root to `/scan` and mounts the user-selected source directory read-only. The scanner then resolves every candidate file, rejects symlinked files and directories (including symlink ancestors), and requires the resolved file to remain below the scan root. This prevents the API from being used as a generic filesystem browser outside the configured analysis boundary. Gitea worktrees are acquired into `/data`, not `/scan`, and are controlled by repository-ID/job-ID validation. ## Persistence and deployment boundary diff --git a/frontend/package-lock.json b/frontend/package-lock.json index c893df1..759236a 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -8,12 +8,13 @@ "name": "repopulse-frontend", "version": "1.5.1", "dependencies": { + "@fontsource-variable/inter": "^5.3.0", "@xyflow/react": "^12.8.5", "react": "^19.1.1", "react-dom": "^19.1.1" }, "devDependencies": { - "@playwright/test": "^1.55.0", + "@playwright/test": "^1.64.1", "@testing-library/dom": "^10.4.1", "@testing-library/react": "^16.3.3", "@types/react": "^19.1.12", @@ -983,6 +984,15 @@ } } }, + "node_modules/@fontsource-variable/inter": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource-variable/inter/-/inter-5.3.0.tgz", + "integrity": "sha512-OupL48va4JNofb97w6NYeF9S7W/kHNKM0Er8Dem5nqi4jeOLrVJDoE8tZEpnMJmtkvNbB1EIPPwHcdkF6b1oUA==", + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.13", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", @@ -1054,19 +1064,19 @@ } }, "node_modules/@playwright/test": { - "version": "1.55.0", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.55.0.tgz", - "integrity": "sha512-04IXzPwHrW69XusN/SIdDdKZBzMfOT9UNT/YiJit/xpy2VuAoB8NHc8Aplb96zsWDddLnbkPL3TsmrS04ZU2xQ==", + "version": "1.64.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.64.1.tgz", + "integrity": "sha512-IaYGml/nSOiZWROfPtuIL7neuu9qDOZ3TNvNljUIrhDMxiGTgPjzj/g9p9RxpS2tSepPDRY+UwAaEeiKtUvIAg==", "dev": true, "license": "Apache-2.0", "dependencies": { - "playwright": "1.55.0" + "playwright": "1.64.1" }, "bin": { "playwright": "cli.js" }, "engines": { - "node": ">=18" + "node": ">=20" } }, "node_modules/@rolldown/pluginutils": { @@ -2592,50 +2602,32 @@ } }, "node_modules/playwright": { - "version": "1.55.0", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.55.0.tgz", - "integrity": "sha512-sdCWStblvV1YU909Xqx0DhOjPZE4/5lJsIS84IfN9dAZfcl/CIZ5O8l3o0j7hPMjDvqoTF8ZUcc+i/GL5erstA==", + "version": "1.64.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.64.1.tgz", + "integrity": "sha512-HCrVhHr5QQuwYoswEUGTb7gGp522yflbv/ST8nF4sFWGuLjQCt17Q/EubpGGSNKYn1tsTCPZxqHhHCfVURu7UA==", "dev": true, "license": "Apache-2.0", "dependencies": { - "playwright-core": "1.55.0" + "playwright-core": "1.64.1" }, "bin": { "playwright": "cli.js" }, "engines": { - "node": ">=18" - }, - "optionalDependencies": { - "fsevents": "2.3.2" + "node": ">=20" } }, "node_modules/playwright-core": { - "version": "1.55.0", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.55.0.tgz", - "integrity": "sha512-GvZs4vU3U5ro2nZpeiwyb0zuFaqb9sUiAJuyrWpcGouD8y9/HLgGbNRjIph7zU9D3hnPaisMl9zG9CgFi/biIg==", + "version": "1.64.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.64.1.tgz", + "integrity": "sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ==", "dev": true, "license": "Apache-2.0", "bin": { "playwright-core": "cli.js" }, "engines": { - "node": ">=18" - } - }, - "node_modules/playwright/node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "hasInstallScript": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + "node": ">=20" } }, "node_modules/postcss": { diff --git a/frontend/package.json b/frontend/package.json index 129a2a2..c54a595 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -11,12 +11,13 @@ "test:e2e": "playwright test" }, "dependencies": { + "@fontsource-variable/inter": "^5.3.0", "@xyflow/react": "^12.8.5", "react": "^19.1.1", "react-dom": "^19.1.1" }, "devDependencies": { - "@playwright/test": "^1.55.0", + "@playwright/test": "^1.64.1", "@testing-library/dom": "^10.4.1", "@testing-library/react": "^16.3.3", "@types/react": "^19.1.12", diff --git a/frontend/playwright.config.ts b/frontend/playwright.config.ts index 7598543..51fb492 100644 --- a/frontend/playwright.config.ts +++ b/frontend/playwright.config.ts @@ -2,7 +2,7 @@ import { defineConfig, devices } from '@playwright/test' export default defineConfig({ testDir: './e2e', - timeout: 30_000, + timeout: 60_000, // one long end-to-end journey; cold Vite compiles on a loaded runner need headroom fullyParallel: false, workers: 6, reporter: 'list', @@ -30,7 +30,7 @@ export default defineConfig({ command: 'node e2e/start-vite.mjs', url: 'http://127.0.0.1:4173', reuseExistingServer: false, - timeout: 30_000, + timeout: 60_000, // one long end-to-end journey; cold Vite compiles on a loaded runner need headroom }, ], }) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index ddcd153..c34b437 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -3,6 +3,9 @@ import { type FormEvent, lazy, Suspense, useCallback, useEffect, useMemo, useRef import { api, type AppMeta, type RepositorySummary, type ScanComparison, type ScanJob, type ScanReport, type ScanSummary, type TrendPoint } from './api' import { filterRepositories, orderSwitcherRepositories, paginateRepositories, readinessLabel, repositoryReadiness, sortRepositories, stateLabel, type CatalogFilters, type CatalogSort, type CatalogSortKey, type Readiness } from './catalog' import { BrandLockup, BrandMark } from './components/Brand' +import { Icon, type IconName } from './components/Icon' +import { HealthRing } from './components/HealthRing' +import { RepoAvatar } from './components/RepoAvatar' import { DashboardView } from './components/DashboardView' import { DependenciesView } from './components/DependenciesView' import { FindingsView } from './components/FindingsView' @@ -40,7 +43,7 @@ function formatDate(value: string | null) { if (!value) return 'Never'; const da function formatRelativeDate(value: string | null) { if (!value) return 'Never scanned'; const difference = Date.now() - new Date(value).getTime(); if (Number.isNaN(difference)) return 'Unknown'; if (difference < 3_600_000) return `${Math.max(1, Math.floor(difference / 60_000))}m ago`; if (difference < 86_400_000) return `${Math.floor(difference / 3_600_000)}h ago`; return `${Math.floor(difference / 86_400_000)}d ago` } function downloadText(filename: string, content: string, mime: string) { const url = URL.createObjectURL(new Blob([content], { type: mime })); const anchor = document.createElement('a'); anchor.href = url; anchor.download = filename; anchor.style.display = 'none'; document.body.appendChild(anchor); anchor.click(); window.setTimeout(() => { anchor.remove(); URL.revokeObjectURL(url) }, 0) } function reportFilename(repositoryName: string, format: 'html' | 'json') { const safeName = repositoryName.replace(/[\u0000-\u001f\u007f<>:"/\\|?*]/g, '_').replace(/[ .]+$/g, '').slice(0, 100).replace(/[ .]+$/g, '') || 'repository'; return `repopulse-${safeName}.${format}` } -function detailViewLabel(view: DetailView, report: ScanReport | null) { if (view === 'overview') return 'Overview'; if (view === 'findings') return `Findings (${report?.findings.filter((finding) => !finding.suppressed).length ?? 0})`; if (view === 'architecture') return `Architecture (${report?.architecture.nodes.length ?? 0})`; if (view === 'hotspots') return `Hotspots (${report?.hotspots.length ?? 0})`; if (view === 'dependencies') return 'Dependencies'; if (view === 'history') return 'History'; return 'Scan runs' } +function detailViewLabel(view: DetailView, report: ScanReport | null) { if (view === 'overview') return 'Overview'; if (view === 'findings') return report ? `Findings (${report.findings.filter((finding) => !finding.suppressed).length})` : 'Findings'; if (view === 'architecture') return report ? `Architecture (${report.architecture.nodes.length})` : 'Architecture'; if (view === 'hotspots') return report ? `Hotspots (${report.hotspots.length})` : 'Hotspots'; if (view === 'dependencies') return 'Dependencies'; if (view === 'history') return 'History'; return 'Scan runs' } export default function App() { const [route, setRoute] = useState(() => parseRoute(window.location.pathname)) @@ -162,20 +165,29 @@ export default function App() { const selectScan = async (summary: ScanSummary) => { try { setBusy(true); setError(null); setReport(await api.repositoryScan(summary.repository_id, summary.id)); navigate({ page: 'repositories', repositoryId: summary.repository_id, view: 'overview' }) } catch (err) { setError(err instanceof Error ? err.message : 'Could not load the selected scan.') } finally { setBusy(false) } } const exportReport = async (format: 'html' | 'json') => { if (!report) return; try { downloadText(reportFilename(report.repository_name, format), await api.exportReport(report.id, format), format === 'html' ? 'text/html' : 'application/json') } catch (err) { setError(err instanceof Error ? err.message : 'Report export failed.') } } - const renderGlobalNav = () => - const renderTopbar = () =>
handleNavigation(event, { page: 'dashboard' })} aria-label="RepoPulse dashboard">{renderGlobalNav()}
+ const navItems: { page: Route['page']; label: string; href: string; icon: IconName; count?: number }[] = [ + { page: 'dashboard', label: 'Dashboard', href: '/', icon: 'dashboard' }, + { page: 'repositories', label: 'Repositories', href: '/repositories', icon: 'repositories', count: repositories.length }, + { page: 'activity', label: 'Activity', href: '/activity', icon: 'activity' }, + { page: 'queue', label: 'Scan queue', href: '/queue', icon: 'queue', count: repositories.filter((repository) => repository.active_job_id || repository.state === 'queued' || repository.state === 'scanning').length || undefined }, + { page: 'settings', label: 'Settings', href: '/settings', icon: 'settings' }, + ] + const lastSync = meta?.gitea.last_sync && typeof meta.gitea.last_sync === 'object' && 'synced_at' in meta.gitea.last_sync ? String(meta.gitea.last_sync.synced_at) : null + const renderGlobalNav = () => + const renderSidebar = () => + const renderTopbar = () =>
handleNavigation(event, { page: 'dashboard' })} aria-label="RepoPulse home">
- const renderCatalogPage = () =>
Repository explorer

Repositories {repositories.length}

High-density catalog controls when you need breadth; switch to visual identity tiles when you need pattern recognition.

updateCatalogFilter('query', event.target.value)} placeholder="Search name, owner or full name" />⌘K
{filteredRepositories.length} matching {repositories.length} repositories
{catalogLoading ?
: catalogWindow.items.length ? <>{catalogView === 'table' ?
{catalogWindow.items.map((repository) => { const readiness = repositoryReadiness(repository); const pinned = pinnedIds.includes(repository.id); return selectRepository(repository)} onKeyDown={(event) => { if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); selectRepository(repository) } }}> })}
ReadinessBranch
{repository.full_name}{repository.private ? 'Private' : 'Public'} · {repository.provider} · {repository.archived ? 'Archived' : 'Active'}
{repository.default_branch}{formatRelativeDate(repository.last_scan_at)}{formatDate(repository.last_scan_at)}{repository.last_scan_health ?? '—'}
:
{catalogWindow.items.map((repository) => { const pinned = pinnedIds.includes(repository.id); const readiness = repositoryReadiness(repository); return