74465ea38fdb

show private repos and source to the signed-in operator (v3.2.14)

time
2026-11-20 17:05 UTC · 1 week ago
machine
Junes-MacBook-Pro.local
agent
gpt-6.2-sol
session
show private repos to operator
parent
d6d38726fc8c
15 files package.json+1 −1public/js/kepr.js+3 −2public/js/nav.js+23 −3src/pages/files.ts+9 −11src/pages/front.ts+26 −21src/pages/housekeeping.ts+2 −2src/pages/layout.ts+28 −15src/pages/library.ts+18 −7src/pages/profile.ts+12 −11src/pages/repo.ts+18 −16src/pages/save.ts+14 −16src/server/app.ts+2 −2src/server/db.ts+9 −8src/server/login.ts+1 −2tests/front.test.ts+68 −1
package.json+1 −1
@@ -1,6 +1,6 @@11 {22 	"name": "kepr",3-	"version": "3.2.13",3+	"version": "3.2.14",44 	"private": true,55 	"type": "module",66 	"scripts": {

view file

public/js/kepr.js+3 −2
@@ -501,7 +501,8 @@501501 	root.style.height = `${root.offsetHeight}px`;502502 	root.style.overflowY = "hidden";503503 	const key = `kepr:atlas:${root.dataset.repo}`;504-	const opened = new Set(remembered(key));504+	const privateView = document.body.hasAttribute("data-private-view");505+	const opened = new Set(privateView ? [] : remembered(key));505506 	// `?open=<folder>` from a file page's breadcrumb unfolds that folder, without remembering it.506507 	const unfold = new URLSearchParams(location.search).get("open");507508 	const onPath = (path) => unfold !== null && `${unfold}/`.startsWith(`${path}/`);@@ -511,7 +512,7 @@511512 			if (filter.value.trim()) return;512513 			if (folder.open) opened.add(folder.dataset.path);513514 			else opened.delete(folder.dataset.path);514-			remember(key, [...opened]);515+			if (!privateView) remember(key, [...opened]);515516 		});516517 	}517518 	const panels = new Map();

view file

public/js/nav.js+23 −3
@@ -1,7 +1,7 @@11 // The navbar when signed in: "admin" and "log out" in place of "log in". Loaded right after the2-// nav, before the rest of the page, so the signed-out links never show first. Pages are the same3-// for everyone; the readable kepr_editor cookie, set beside the session, carries the form token4-// that log out posts back. Only the private notification preview needs a request.2+// nav, before the rest of the page, so the signed-out links never show first. The readable3+// kepr_editor cookie carries the form token that log out posts back. Only the notification preview4+// needs a request.55 // Suppress the dense static dots before the timeline markup can paint.66 document.documentElement.classList.add("timeline-pending");77 // A failed deferred script never reaches the timeline's finally block.@@ -30,6 +30,26 @@3030 		button.type = "submit";3131 		button.textContent = "log out";3232 		form.append(field, button);33+		form.addEventListener("submit", async (event) => {34+			event.preventDefault();35+			button.disabled = true;36+			try {37+				// A regular form post under no-referrer gives Chromium a null Origin.38+				const response = await fetch(form.action, {39+					method: "POST",40+					body: new FormData(form),41+					redirect: "manual",42+					referrer: location.origin,43+					referrerPolicy: "same-origin",44+				});45+				if (response.type !== "opaqueredirect") throw new Error(`HTTP ${response.status}`);46+				location.assign("/");47+			} catch (error) {48+				console.error("Could not log out", error);49+				button.textContent = "retry log out";50+				button.disabled = false;51+			}52+		});3353 		const bell = document.createElement("details");3454 		bell.className = "nav-notifications";3555 		const toggle = document.createElement("summary");

view file

src/pages/files.ts+9 −11
@@ -5,12 +5,12 @@55 import { highlightLines } from "./highlight.ts";66 import { type Html, html } from "./html.ts";77 import {8+	browserPage,89 	cacheFor,910 	formatSize,1011 	notFound,11-	openPublicRepo,12+	openBrowserRepo,1213 	type PageContext,13-	page,1414 	pathUrl,1515 } from "./layout.ts";1616 import { registerHeavyLimit } from "./limit.ts";@@ -42,14 +42,12 @@4242 		const body = html`${breadcrumb(found)}4343 <h1 class="file-page-title">${title}</h1>4444 ${await fileBody(found, c.req.query("view") === "source")}`;45-		return c.html(46-			page(ctx, {47-				title: `${title} · ${found.repo}`,48-				description: found.path,49-				path: c.req.path,50-				body,51-			}),52-		);45+		return browserPage(c, ctx, {46+			title: `${title} · ${found.repo}`,47+			description: found.path,48+			path: c.req.path,49+			body,50+		});5351 	});5452 5553 	app.get("/:repo/raw/:path{.+}", (c) => {@@ -77,7 +75,7 @@7775 function findFile(c: Context, ctx: PageContext): Found | null {7876 	const name = c.req.param("repo") as string;7977 	const path = c.req.param("path") as string;80-	const repo = openPublicRepo(ctx, name);78+	const repo = openBrowserRepo(ctx, c, name);8179 	if (!repo || !isSafePath(path)) return null;8280 	const at = c.req.query("at") ?? null;8381 	const saveId = at === null ? headId(repo.mirror) : (saveByPrefix(repo.mirror, at)?.id ?? null);

view file

src/pages/front.ts+26 −21
@@ -2,8 +2,14 @@22 import { headId, knownObjects, languageLines, tarballGeneration } from "../mirror/queries.ts";33 import { setting } from "../server/db.ts";44 import { type Html, html } from "./html.ts";5-import { cacheFor, type PageContext, page, plural } from "./layout.ts";6-import { type LibraryRepo, publicLibrary, recentSaves, repoCards } from "./library.ts";5+import { browserPage, cacheFor, type PageContext, plural } from "./layout.ts";6+import {7+	type LibraryRepo,8+	libraryRepos,9+	privateRepoCards,10+	recentSaves,11+	repoCards,12+} from "./library.ts";713 814 const TICKER_ROWS = 7;915 const TICKER_ITEMS = 10;@@ -12,7 +18,7 @@1218 /** §21.1's front page and §21.3's browse. */1319 export function registerFrontPages(app: Hono, ctx: PageContext): void {1420 	app.get("/", (c) => {15-		const library = publicLibrary(ctx);21+		const library = libraryRepos(ctx);1622 		const tagline = setting(ctx.kepr, "tagline") ?? "";1723 		// §21.1: distinct objects across every public repo's real saves.1824 		const known = knownThings(library);@@ -21,12 +27,12 @@2127 			.sort((a, b) => (b.stats.updated ?? 0) - (a.stats.updated ?? 0))2228 			.slice(0, LATEST_OFFERED);2329 		cacheFor(c, false);24-		return c.html(25-			page(ctx, {26-				title: "",27-				description: tagline,28-				path: "/",29-				body: html`${ticker(library)}30+		const privateCards = privateRepoCards(c, ctx);31+		return browserPage(c, ctx, {32+			title: "",33+			description: tagline,34+			path: "/",35+			body: html`${ticker(library)}3036 <section class="headline">3137 <div class="headline-text">3238 <h1>The library knows<br>${plural(known, "thing")}.</h1>@@ -38,27 +44,26 @@3844 	latest.length > 0 &&3945 	html`<section class="featured"><h2 class="featured-label mono">latest offered</h2>${repoCards(latest)}</section>`4046 }47+${privateCards}4148 <p class="landing-self-host mono"><a href="/docs">run your own library →</a></p>`,42-			}),43-		);49+		});4450 	});4551 	app.get("/browse", (c) => {46-		const library = publicLibrary(ctx);52+		const library = libraryRepos(ctx);4753 		cacheFor(c, false);48-		return c.html(49-			page(ctx, {50-				title: "browse",51-				description: `Every public repository, ${plural(library.length, "repo")}.`,52-				path: "/browse",53-				body: html`<h1 class="file-page-title">browse</h1>54+		const privateCards = privateRepoCards(c, ctx);55+		return browserPage(c, ctx, {56+			title: "browse",57+			description: `Every public repository, ${plural(library.length, "repo")}.`,58+			path: "/browse",59+			body: html`<h1 class="file-page-title">browse</h1>5460 <p class="muted mono">${plural(library.length, "repo")}</p>5561 ${5662 	library.length > 05763 		? repoCards(library)5864 		: html`<p class="muted mono save-empty">nothing public yet</p>`59-}`,60-			}),61-		);65+}${privateCards}`,66+		});6267 	});6368 }6469 

view file

src/pages/housekeeping.ts+2 −2
@@ -1,7 +1,7 @@11 import { readFileSync } from "node:fs";22 import { join } from "node:path";33 import type { Hono } from "hono";4-import { publicRepoNames } from "../server/db.ts";4+import { repoNames } from "../server/db.ts";55 import type { PageContext } from "./layout.ts";66 77 // Kepr 2's mark, in Kepr's gold.@@ -71,7 +71,7 @@7171 			url("/browse", "daily", "0.9"),7272 			url("/docs", "weekly", "0.8"),7373 			// Repo names are [A-Za-z0-9._-] (§9.2's check at sync), so they need no XML escaping.74-			...publicRepoNames(ctx.kepr).map((name) => url(`/${name}`, "daily", "0.7")),74+			...repoNames(ctx.kepr).map((name) => url(`/${name}`, "daily", "0.7")),7575 		];7676 		return c.body(7777 			`<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls.join(

view file

src/pages/layout.ts+28 −15
@@ -1,12 +1,13 @@11 import type { Database } from "bun:sqlite";22 import type { Context } from "hono";33 import { openMirror } from "../mirror/store.ts";4-import { publicRepo, type RepoSettings, setting } from "../server/db.ts";4+import { findRepo, type RepoSettings, setting } from "../server/db.ts";5+import { signedIn } from "../server/login.ts";56 import { type Html, html } from "./html.ts";67 78 export type PageContext = { domain: string; kepr: Database; mirrorDir: string };89 9-export type PublicRepo = { settings: RepoSettings; mirror: Database };10+export type PublicRepo = { settings: RepoSettings; mirror: Database; private?: boolean };1011 1112 // Static files are cached for an hour; the release in their URLs makes a new one load at once.1213 const { version } = (await Bun.file(`${import.meta.dir}/../../package.json`).json()) as {@@ -18,18 +19,23 @@1819 // immutable, and `private`, so no shared cache keeps it after the repo turns private (§20).1920 const SAVE_CACHE = "private, max-age=31536000";2021 21-/**22- * The gate of §20: a private repo and an unknown one both come back null, and so both 404 alike.23- */24-export function openPublicRepo(25-	ctx: Pick<PageContext, "kepr" | "mirrorDir">,26-	name: string,27-): PublicRepo | null {28-	const settings = publicRepo(ctx.kepr, name);29-	return settings ? { settings, mirror: openMirror(ctx.mirrorDir, name) } : null;22+/** Callers must verify the operator session before opening a private repo. */23+export function openRepo(ctx: PageContext, name: string, visibility: 0 | 1 = 1): PublicRepo | null {24+	const settings = findRepo(ctx.kepr, name, visibility);25+	if (!settings) return null;26+	return { settings, mirror: openMirror(ctx.mirrorDir, name), private: visibility === 0 };3027 }28+export const openPublicRepo = (ctx: PageContext, name: string) => openRepo(ctx, name);3129 30+export function openBrowserRepo(ctx: PageContext, c: Context, name: string): PublicRepo | null {31+	const repo = openPublicRepo(ctx, name);32+	if (repo || !signedIn(ctx, c)) return repo;33+	c.header("Cache-Control", "no-store");34+	return openRepo(ctx, name, 0);35+}36+3237 export function cacheFor(c: Context, atSave: boolean): void {38+	if (c.res.headers.get("Cache-Control") === "no-store") return;3339 	c.header("Cache-Control", atSave ? SAVE_CACHE : HEAD_CACHE);3440 }3541 @@ -37,16 +43,23 @@3743 	c.header("Cache-Control", "no-store");3844 	const body = html`<h1 class="file-page-title">Not found</h1>3945 		<p class="muted">Nothing lives at this address.</p>`;40-	return c.html(page(ctx, { title: "Not found", description: "", path: c.req.path, body }), 404);46+	return c.html(47+		page(ctx, { title: "Not found", description: "", path: c.req.path, body }, true),48+		404,49+	);4150 }4251 4352 type PageOptions = { title: string; description: string; path: string; body: Html };4453 45-export function page(ctx: PageContext, options: PageOptions): string {54+export function browserPage(c: Context, ctx: PageContext, options: PageOptions): Response {55+	return c.html(page(ctx, options, c.res.headers.get("Cache-Control") === "no-store"));56+}57+58+export function page(ctx: PageContext, options: PageOptions, privateView = false): string {4659 	const site = setting(ctx.kepr, "site_name") ?? "kepr";4760 	const branding = setting(ctx.kepr, "branding");4861 	// Visitors are counted, never the operator's console or sign-in.49-	const tracked = !/^\/(admin|sign-in|connect)(\/|$)/.test(options.path);62+	const tracked = !privateView && !/^\/(admin|sign-in|connect)(\/|$)/.test(options.path);5063 	const umamiSrc = tracked && setting(ctx.kepr, "umami_src");5164 	const umamiId = setting(ctx.kepr, "umami_id");5265 	// The front page is the site itself, so its title is the bare site name.@@ -74,7 +87,7 @@7487 <script src="/static/js/kepr.js?v=${version}" defer></script>7588 ${umamiSrc && umamiId && html`<script defer src="${umamiSrc}" data-website-id="${umamiId}"></script>`}7689 </head>77-<body>90+<body${privateView && html` data-private-view`}>7891 <nav>7992 <a class="wordmark" href="/" aria-label="${8093 		site

view file

src/pages/library.ts+18 −7
@@ -1,22 +1,33 @@1+import type { Context } from "hono";12 import { newestSaves, type RepoStats, repoStats, type Save } from "../mirror/queries.ts";2-import { publicRepoNames } from "../server/db.ts";3+import { repoNames } from "../server/db.ts";4+import { signedIn } from "../server/login.ts";35 import { type Html, html } from "./html.ts";4-import { openPublicRepo, type PageContext, type PublicRepo, plural } from "./layout.ts";6+import { openRepo, type PageContext, type PublicRepo, plural } from "./layout.ts";57 import { repoIntro } from "./repo.ts";68 7-/** A public repo as the front page, browse and the profile show it. */89 export type LibraryRepo = PublicRepo & { stats: RepoStats; description: string };910 1011 export type RecentSave = { repo: string; save: Save };1112 12-/** Every public repo in card order (§20: private ones never reach a page, count or card). */13-export function publicLibrary(ctx: PageContext): LibraryRepo[] {14-	return publicRepoNames(ctx.kepr).flatMap((name) => {15-		const repo = openPublicRepo(ctx, name);13+export function libraryRepos(ctx: PageContext, visibility: 0 | 1 = 1): LibraryRepo[] {14+	return repoNames(ctx.kepr, visibility).flatMap((name) => {15+		const repo = openRepo(ctx, name, visibility);1616 		if (!repo) return [];1717 		const description = repoIntro(repo)?.text ?? "";1818 		return [{ ...repo, stats: repoStats(repo.mirror), description }];1919 	});20+}21+22+export function privateRepoCards(c: Context, ctx: PageContext): Html | null {23+	c.header("Vary", "Cookie", { append: true });24+	if (!signedIn(ctx, c)) return null;25+	c.header("Cache-Control", "no-store");26+	const repos = libraryRepos(ctx, 0);27+	return repos.length28+		? html`<section class="featured"><h2 class="featured-label mono">private repos</h2>29+${repoCards(repos)}</section>`30+		: null;2031 }2132 2233 /** The newest saves across the library, checkpoints never among them. */

view file

src/pages/profile.ts+12 −11
@@ -5,10 +5,11 @@55 import { publicDownloadCount } from "../releases/releases.ts";66 import { setting } from "../server/db.ts";77 import { type Html, html } from "./html.ts";8-import { cacheFor, notFound, type PageContext, page, relativeTime } from "./layout.ts";8+import { browserPage, cacheFor, notFound, type PageContext, relativeTime } from "./layout.ts";99 import {1010 	type LibraryRepo,11-	publicLibrary,11+	libraryRepos,12+	privateRepoCards,1213 	type RecentSave,1314 	recentSaves,1415 	repoCards,@@ -24,15 +25,15 @@2425 	app.get("/:handle{@[^/]+}", (c) => {2526 		const handle = setting(ctx.kepr, "handle") ?? "";2627 		if (handle === "" || c.req.param("handle") !== `@${handle}`) return notFound(c, ctx);27-		const library = publicLibrary(ctx);28+		const library = libraryRepos(ctx);2829 		const bio = setting(ctx.kepr, "bio") ?? "";2930 		cacheFor(c, false);30-		return c.html(31-			page(ctx, {32-				title: `@${handle}`,33-				description: bio || `@${handle}'s repositories.`,34-				path: `/@${handle}`,35-				body: html`<div class="profile">31+		const privateCards = privateRepoCards(c, ctx);32+		return browserPage(c, ctx, {33+			title: `@${handle}`,34+			description: bio || `@${handle}'s repositories.`,35+			path: `/@${handle}`,36+			body: html`<div class="profile">3637 ${cover(ctx, handle, recentSaves(library, HEX_COLUMNS))}3738 <section class="profile-portrait-section">3839 <div class="profile-left">@@ -49,9 +50,9 @@4950 <div class="profile-section-label">repos · ${library.length}</div>5051 ${repoCards(library)}5152 </section>53+${privateCards}5254 </div>`,53-			}),54-		);55+		});5556 	});5657 }5758 

view file

src/pages/repo.ts+18 −16
@@ -19,12 +19,12 @@1919 import { atlasPanel, atlasPickerRows, atlasSection } from "./atlas.ts";2020 import { type Html, html } from "./html.ts";2121 import {22+	browserPage,2223 	cacheFor,2324 	notFound,24-	openPublicRepo,25+	openBrowserRepo,2526 	type PageContext,2627 	type PublicRepo,27-	page,2828 	plural,2929 	relativeTime,3030 } from "./layout.ts";@@ -42,7 +42,7 @@4242 4343 export function registerRepoPage(app: Hono, ctx: PageContext): void {4444 	app.get("/:repo", (c) => {45-		const repo = openPublicRepo(ctx, c.req.param("repo"));45+		const repo = openBrowserRepo(ctx, c, c.req.param("repo"));4646 		if (!repo) return notFound(c, ctx);4747 		// `?at=<id>` shows the Atlas at that save (§21.5); the rest of the page stays at HEAD.4848 		const at = c.req.query("at");@@ -55,27 +55,25 @@5555 			!repo.settings.description || !repo.settings.details ? readmeAtHead(repo.mirror) : null;5656 		const intro = repoIntro(repo, readme);5757 		cacheFor(c, false);58-		return c.html(59-			page(ctx, {60-				title: name,61-				description: intro?.text ?? "",62-				path: `/${name}`,63-				body: html`${header(ctx, repo, intro?.html ?? null)}58+		return browserPage(c, ctx, {59+			title: name,60+			description: intro?.text ?? "",61+			path: `/${name}`,62+			body: html`${header(ctx, repo, intro?.html ?? null)}6463 ${headId(repo.mirror) && sections(repo, pageNumber, atSave?.id ?? null)}6564 ${details(repoDetails(repo, readme))}`,66-			}),67-		);65+		});6866 	});6967 	// The timeline's saves, fetched by kepr.js once the page has drawn (§21.4).7068 	app.get("/:repo/timeline", (c) => {71-		const repo = openPublicRepo(ctx, c.req.param("repo"));69+		const repo = openBrowserRepo(ctx, c, c.req.param("repo"));7270 		if (!repo) return notFound(c, ctx);7371 		cacheFor(c, false);7472 		return c.json(timelineSaves(timeline(repo.mirror)));7573 	});7674 	// The Atlas picker's rows, fetched by kepr.js when it first opens (§21.5).7775 	app.get("/:repo/atlas/saves", (c) => {78-		const repo = openPublicRepo(ctx, c.req.param("repo"));76+		const repo = openBrowserRepo(ctx, c, c.req.param("repo"));7977 		const at = c.req.query("at");8078 		const save = repo && at !== undefined ? saveByPrefix(repo.mirror, at) : null;8179 		if (!repo || (at !== undefined && !save)) return notFound(c, ctx);@@ -85,7 +83,7 @@8583 	});8684 	// One Atlas row's detail panel, fetched by kepr.js on hover or select (§21.5).8785 	app.get("/:repo/atlas/panel", (c) => {88-		const repo = openPublicRepo(ctx, c.req.param("repo"));86+		const repo = openBrowserRepo(ctx, c, c.req.param("repo"));8987 		const at = c.req.query("at");9088 		const path = c.req.query("path") ?? "";9189 		const save = repo && (at === undefined ? null : saveByPrefix(repo.mirror, at));@@ -147,6 +145,7 @@147145 		visibleReleases(ctx.kepr, repo.mirror, name)[0]?.version ||148146 		mirrorState(repo.mirror, "declared_version");149147 	const meta = [148+		repo.private && "private",150149 		version && html`<span class="repo-version">v${version}</span>`,151150 		plural(stats.saves, "save"),152151 		stats.lines > 0 && plural(stats.lines, "line"),@@ -167,7 +166,9 @@167166 	)}</div>`168167 }169168 <p class="repo-meta">${meta.flatMap((part, i) => (i === 0 ? [part] : [" · ", part]))}</p>170-<div class="repo-tabbar">169+${170+	!repo.private &&171+	html`<div class="repo-tabbar">171172 <nav class="repo-tabs" aria-label="Repository panels">${PANELS.map(172173 		([label, path]) =>173174 			html`<a class="repo-tab" href="/${name}/${path}" data-panel="${path}">${label}${@@ -183,7 +184,8 @@183184 <button type="button" class="repo-steal-btn" data-copy="${steal}">${steal}</button>184185 </div>185186 </div>186-<div class="repo-panel" hidden></div>187+<div class="repo-panel" hidden></div>`188+}187189 </header>`;188190 }189191 

view file

src/pages/save.ts+14 −16
@@ -14,12 +14,12 @@1414 import { highlightLines } from "./highlight.ts";1515 import { type Html, html } from "./html.ts";1616 import {17+	browserPage,1718 	cacheFor,1819 	formatDate,1920 	notFound,20-	openPublicRepo,21+	openBrowserRepo,2122 	type PageContext,22-	page,2323 	pathUrl,2424 	plural,2525 	relativeTime,@@ -53,7 +53,7 @@5353 5454 export function registerSavePage(app: Hono, ctx: PageContext): void {5555 	app.get("/:repo/saves/:id", async (c) => {56-		const repo = openPublicRepo(ctx, c.req.param("repo"));56+		const repo = openBrowserRepo(ctx, c, c.req.param("repo"));5757 		const id = c.req.param("id");5858 		const save = repo && saveByPrefix(repo.mirror, id);5959 		// Checkpoints never appear (§21.4), so a link to one finds nothing, like an unknown ID.@@ -73,21 +73,20 @@7373 		// Not a year like other per-save content: a flag or a strip can arrive for this save later.7474 		cacheFor(c, false);7575 		const [title = "", ...rest] = save.message.split("\n");76-		return c.html(77-			page(ctx, {78-				title: `${title} · ${name}`,79-				description: `${save.id} · ${plural(diffs.length, "file")} changed`,80-				path: `/${name}/saves/${save.id}`,81-				body: html`<p class="breadcrumb mono"><a href="/${82-					name83-				}">${name}</a> / <a href="/${name}#history">history</a></p>76+		return browserPage(c, ctx, {77+			title: `${title} · ${name}`,78+			description: `${save.id} · ${plural(diffs.length, "file")} changed`,79+			path: `/${name}/saves/${save.id}`,80+			body: html`<p class="breadcrumb mono"><a href="/${81+				name82+			}">${name}</a> / <a href="/${name}#history">history</a></p>8483 ${saveHeader(repo.mirror, name, save, parent, title, rest.join("\n").trim())}8584 <section class="repo-section">8685 <details class="repo-section-toggle" open>8786 <summary class="section-head"><span class="section-label">files changed</span><span class="section-count">${plural(88-					diffs.length,89-					"file",90-				)}</span></summary>87+				diffs.length,88+				"file",89+			)}</span></summary>9190 ${9291 	diffs.length === 09392 		? html`<p class="muted mono save-empty">no files changed</p>`@@ -96,8 +95,7 @@9695 </details>9796 </section>9897 <section class="repo-section">${await diffSections(name, save, parent, diffs)}</section>`,99-			}),100-		);98+		});10199 	});102100 }103101 

view file

src/server/app.ts+2 −2
@@ -34,7 +34,7 @@3434 import { registerTarballRoutes } from "../tarball/archive.ts";3535 import { CONFIG_FILE, type Config } from "./config.ts";3636 import { connectKeys, noCode, registerConnect } from "./connect.ts";37-import { renamedTo, setting } from "./db.ts";37+import { publicRepo, renamedTo, setting } from "./db.ts";3838 import { registerLogin } from "./login.ts";3939 4040 const MAX_BODY_BYTES = 64 * 1024;@@ -122,7 +122,7 @@122122 		if (c.req.method !== "GET" || c.res.status !== 404) return;123123 		const [, first = "", second, ...rest] = c.req.path.split("/");124124 		const to = second !== "koh" && renamedTo(kepr, first);125-		if (!to) return;125+		if (!to || !publicRepo(kepr, to)) return;126126 		const query = new URL(c.req.url).search;127127 		const path = ["", to, ...(second === undefined ? [] : [second, ...rest])].join("/");128128 		c.res = c.redirect(`${path}${query}`, 301);

view file

src/server/db.ts+9 −8
@@ -364,22 +364,22 @@364364 	);365365 }366366 367-export function publicRepoNames(db: Database): string[] {367+export function repoNames(db: Database, visibility: 0 | 1 = 1): string[] {368368 	return db369-		.query<{ name: string }, []>("SELECT name FROM repos WHERE public = 1 ORDER BY name")370-		.all()369+		.query<{ name: string }, [number]>("SELECT name FROM repos WHERE public = ? ORDER BY name")370+		.all(visibility)371371 		.map((row) => row.name);372372 }373373 374-/** The settings of a public repo, or null when it is private or unknown: both must look missing. */375-export function publicRepo(db: Database, name: string): RepoSettings | null {374+/** Callers must verify the operator session before requesting private settings. */375+export function findRepo(db: Database, name: string, visibility: 0 | 1 = 1): RepoSettings | null {376376 	const row = db377-		.query<RepoRow, [string]>(377+		.query<RepoRow, [string, number]>(378378 			`SELECT name, category, homepage, languages, issues_paused, description, details379379 			FROM repos LEFT JOIN repo_text ON repo_text.repo = repos.name380-			WHERE name = ? AND public = 1`,380+			WHERE name = ? AND public = ?`,381381 		)382-		.get(name);382+		.get(name, visibility);383383 	if (!row) return null;384384 	return {385385 		name: row.name,@@ -391,6 +391,7 @@391391 		details: row.details ?? "",392392 	};393393 }394+export const publicRepo = (db: Database, name: string) => findRepo(db, name);394395 395396 /**396397  * What a sync removes from a repo: the paths the operator hid from it (June, 2026-09-30) and the

view file

src/server/login.ts+1 −2
@@ -11,8 +11,7 @@1111 const SESSION_SECONDS = 30 * 86400;1212 const SESSION_COOKIE = "kepr_session";1313 const SIGN_IN_COOKIE = "kepr_sign_in";14-// Readable by kepr.js, and saying only that someone signed in here: public pages stay the same15-// cacheable HTML for everyone, and the script asks the admin routes for the editing controls.14+// A hint for kepr.js to ask the admin routes for editing controls; it does not authorize requests.1615 const EDITOR_COOKIE = "kepr_editor";1716 const COOKIE = { httpOnly: true, secure: true, sameSite: "Strict", path: "/" } as const;1817 const HEX64 = /^[0-9a-f]{64}$/;

view file

tests/front.test.ts+68 −1
@@ -9,6 +9,7 @@99 import { openMirror } from "../src/mirror/store.ts";1010 import { createApp } from "../src/server/app.ts";1111 import { openKeprDb } from "../src/server/db.ts";12+import { Browser, PASSWORD } from "./browser.ts";1213 import { makeRepos } from "./fixture.ts";1314 1415 let app: Hono;@@ -73,7 +74,7 @@7374 		{7475 			domain: "kepr.example",7576 			dataDir,76-			adminPasswordHash: "$argon2id$x",77+			adminPasswordHash: await Bun.password.hash(PASSWORD, "argon2id"),7778 			bucket: { kind: "folder", path: repos.bucketDir },7879 		},7980 		kepr,@@ -82,6 +83,72 @@8283 8384 const checkpoints = () => alphaSaves.filter((save) => save.is_checkpoint).map((save) => save.id);8485 const realSaves = () => alphaSaves.filter((save) => !save.is_checkpoint);86+87+test("only a live operator session can see and open private repo cards", async () => {88+	const operator = new Browser(app);89+	const visitor = new Browser(app);90+	const listings = ["/", "/browse", "/@ada"];91+	const card = 'class="repo-card" href="/vault"';92+	visitor.cookies.set("kepr_editor", "1");93+	kepr.run(94+		"INSERT INTO settings (key, value) VALUES ('umami_src', 'https://stats.example/s.js'), ('umami_id', 'test')",95+	);96+	kepr.run("INSERT INTO renamed (old, new) VALUES ('oldvault', 'vault')");97+	try {98+		for (const path of listings) {99+			const response = await visitor.get(path);100+			expect(response.headers.get("vary")).toContain("Cookie");101+			const markup = await response.text();102+			expect(markup).not.toContain(card);103+			expect(markup).toContain("https://stats.example/s.js");104+		}105+		expect((await operator.signIn()).status).toBe(303);106+		for (const path of listings) {107+			const response = await operator.get(path);108+			expect(response.headers.get("cache-control")).toBe("no-store");109+			const markup = await response.text();110+			expect(markup).toContain(card);111+			expect(markup).not.toContain("https://stats.example/s.js");112+			expect(await (await visitor.get(path)).text()).not.toContain(card);113+		}114+		for (const path of [115+			"/vault",116+			"/vault/timeline",117+			"/vault/atlas/saves",118+			"/vault/atlas/panel?path=main.zig",119+			`/vault/saves/${vaultSave}`,120+			"/vault/files/main.zig",121+			`/vault/raw/main.zig?at=${vaultSave}`,122+		]) {123+			const response = await operator.get(path);124+			expect([path, response.status]).toEqual([path, 200]);125+			expect(response.headers.get("cache-control")).toBe("no-store");126+			expect(await response.text()).not.toContain("https://stats.example/s.js");127+			expect((await visitor.get(path)).status).toBe(404);128+		}129+		for (const path of [130+			"/oldvault",131+			"/vault/issues",132+			"/vault/releases/latest.json",133+			"/vault/koh/head",134+		]) {135+			expect((await visitor.get(path)).status).toBe(404);136+			expect((await operator.get(path)).status).toBe(404);137+		}138+		const prefix = await operator.get(`/vault/saves/${vaultSave.slice(0, 7)}`);139+		expect(prefix.status).toBe(302);140+		expect(prefix.headers.get("cache-control")).toBe("no-store");141+		const token = operator.cookies.get("kepr_session") ?? "";142+		expect((await operator.post("/admin/sign-out", {})).status).toBe(303);143+		operator.cookies.set("kepr_session", token);144+		for (const path of listings)145+			expect(await (await operator.get(path)).text()).not.toContain(card);146+		expect((await operator.get("/vault")).status).toBe(404);147+	} finally {148+		kepr.run("DELETE FROM settings WHERE key IN ('umami_src', 'umami_id')");149+		kepr.run("DELETE FROM renamed WHERE old = 'oldvault'");150+	}151+});85152 86153 describe("front page", () => {87154 	test("counts distinct objects of public repos' real saves only", async () => {

view file