import path from "node:path"; import { writeFile } from "node:fs/promises"; import type { AppConfig } from "@devorajs/core"; import { loadProjectConfig } from "@devorajs/core/config-loader"; import { assignPorts } from "../build/portScheme.js"; // Real bug fixed here (Phase 4 security audit): app.domain used to be // interpolated straight into both templates below with no validation at // all. Verified: a domain value containing a newline + nginx directives // injected a whole extra `return`/`server_name` line into nginx.conf; for // Caddy, a value containing `{`/`}` injected an entire extra server block // routing a chosen hostname to an attacker-chosen backend. The // "devora.config.ts is already fully trusted, executable TypeScript" // caveat (this file is `jiti`-loaded, not sandboxed data — see // resolveSplitTarget.ts's own equivalent caveat) softens this, but // generate:proxy's whole purpose is producing a static config a human may // commit and deploy onto a real VPS without re-reading every character — // a real, persistent-artifact risk worth failing closed on regardless of // how the bad value got into devora.config.ts. const VALID_HOSTNAME = /^(?!-)[A-Za-z0-9-]{1,63}(? { const appPort = ports.get(app.name)!; return opts.target === "nginx" ? nginxBlock(app, appPort) : caddyBlock(app, appPort); }); const output = blocks.join("\n"); const outPath = opts.out ?? path.join(root, opts.target === "nginx" ? "nginx.conf" : "Caddyfile"); await writeFile(outPath, output); console.log(`[devora] generated ${opts.target} config for ${project.apps.length} app(s) → ${outPath}`); console.log(`[devora] no hand-editing needed — domains came straight from devora.config.ts`); }