Harden private media and backup recovery; add V2 deployment and migration guides

This commit is contained in:
Elijah 2026-11-11 19:31:32 -07:00
parent c549c34f60
commit ffaa1f6afa
19 changed files with 623 additions and 14 deletions

View file

@ -137,9 +137,17 @@ export function createApp(app: AppContext): Hono {
if (!webDir) {
return c.text('The web app has not been built. Run "npm run build", or use "npm run dev" and open the Vite dev server.', 404);
}
const urlPath = decodeURIComponent(new URL(c.req.url).pathname);
let urlPath: string;
try {
urlPath = decodeURIComponent(new URL(c.req.url).pathname);
} catch {
return c.text('Invalid URL', 400);
}
const candidate = path.normalize(path.join(webDir, urlPath));
if (candidate.startsWith(webDir) && urlPath !== '/' && fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
const relative = path.relative(webDir, candidate);
const inside = relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
if (!inside) return c.text('Not found', 404);
if (urlPath !== '/' && fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
// Hashed build assets never change; everything else is revalidated.
const immutable = urlPath.startsWith('/assets/');
return sendFile(candidate, immutable ? 'public, max-age=31536000, immutable' : 'no-cache');