diff --git a/agents.md b/agents.md index 10aafc8..e5ad20d 100644 --- a/agents.md +++ b/agents.md @@ -121,3 +121,9 @@ This file is the single source of truth for codebase obstacles, oddities, and th **Obstacle:** `checkRepoAccess` treated any parsed user object as success, even when Forgejo reported zero accessible repositories. **Solution/Workaround:** Require `totalRepos > 0` before returning the existing success result; preserve the existing zero-repository failure. **Preference:** A valid token alone is insufficient for repository-access verification. + +### Forgejo PAT could be sent over remote HTTP +**Area:** cli/src/utils/forgejo-checks.ts, cli/src/commands/config/init.ts +**Obstacle:** CLI setup and verification accepted remote `http://` Forgejo URLs, allowing the PAT to be sent without transport encryption. +**Solution/Workaround:** Centralize Forgejo URL validation, require HTTPS for non-local endpoints, and allow HTTP only for the documented `forgejo` service and loopback hosts. Validate again inside authenticated checks before constructing requests. +**Preference:** Reject insecure remote transport instead of adding an acknowledgement flag. diff --git a/cli/src/commands/config/init.ts b/cli/src/commands/config/init.ts index 03e5fd5..130fb9c 100644 --- a/cli/src/commands/config/init.ts +++ b/cli/src/commands/config/init.ts @@ -5,36 +5,9 @@ import * as c from "yoctocolors"; import * as p from "@clack/prompts"; import { generateEnvFile, SECRET_ENV_KEYS } from "../../utils/config.js"; +import { validateForgejoBaseUrl } from "../../utils/forgejo-checks.js"; import { CommandConfig } from "../../cli-router.js"; -function validateHttpUrlOrHost( - value: string | undefined, - label: string, -): string | undefined { - const trimmed = value?.trim(); - if (!trimmed) return `${label} is required`; - - const hasProtocol = /^[a-z]+:\/\//i.test(trimmed); - const isHttp = /^https?:\/\//i.test(trimmed); - - if (hasProtocol && !isHttp) { - return `${label} must use http:// or https://`; - } - - if (!hasProtocol) { - return `${label} must include a scheme — e.g. http://forgejo:3000 or https://git.example.com`; - } - - try { - const url = new URL(trimmed); - if (!url.hostname) return `${label} must include a domain or hostname`; - } catch { - return `${label} must be a valid URL`; - } - - return undefined; -} - async function init(opts: { output?: string }) { p.intro(c.bold("firebreak config init")); p.note( @@ -118,7 +91,7 @@ async function init(opts: { output?: string }) { message: "Forgejo API URL (how Firebreak reaches Forgejo, not your browser URL)?", placeholder: "http://forgejo:3000", - validate: (v) => validateHttpUrlOrHost(v, "Forgejo base URL"), + validate: (v) => validateForgejoBaseUrl(v), }), forgejoPat: () => p.password({ @@ -178,7 +151,7 @@ async function init(opts: { output?: string }) { ].join("\n"), ); p.log.success( - "Done. Verify firebreak's connection using the 'verify' command.\nOnce verified, deploy!", + "Done. Verify Firebreak's connection using 'firebreak config verify'.\nOnce verified, deploy!", ); } catch (error) { s.stop(); diff --git a/cli/src/commands/verify.ts b/cli/src/commands/verify.ts index 8da5c47..373ba88 100644 --- a/cli/src/commands/verify.ts +++ b/cli/src/commands/verify.ts @@ -162,7 +162,7 @@ async function runForgejoChecks( async function verifyCommand(opts: VerifyOptions): Promise { const isDiagnostic = opts.diagnostic ?? false; - p.intro(c.bold("firebreak verify")); + p.intro(c.bold("firebreak config verify")); const config = loadConfig(); if (!config) { diff --git a/cli/src/utils/forgejo-checks.ts b/cli/src/utils/forgejo-checks.ts index 11dd998..86d865d 100644 --- a/cli/src/utils/forgejo-checks.ts +++ b/cli/src/utils/forgejo-checks.ts @@ -1,5 +1,13 @@ const TIMEOUT = 5000; +const LOCAL_HTTP_HOSTS = new Set([ + "forgejo", + "localhost", + "127.0.0.1", + "::1", + "[::1]", +]); + export type CheckResult = { name: string; success: boolean; @@ -18,6 +26,42 @@ export function createCheckResult( return result; } +export function validateForgejoBaseUrl( + value: string | undefined, + label = "Forgejo base URL", +): string | undefined { + const trimmed = value?.trim(); + if (!trimmed) return `${label} is required`; + + const hasProtocol = /^[a-z]+:\/\//i.test(trimmed); + const isHttp = /^https?:\/\//i.test(trimmed); + + if (hasProtocol && !isHttp) { + return `${label} must use http:// or https://`; + } + + if (!hasProtocol) { + return `${label} must include a scheme — e.g. http://forgejo:3000 or https://git.example.com`; + } + + try { + const url = new URL(trimmed); + if (!url.hostname) return `${label} must include a domain or hostname`; + + const isLocalHttp = + url.protocol === "http:" && + (LOCAL_HTTP_HOSTS.has(url.hostname) || + url.hostname.endsWith(".localhost")); + if (url.protocol === "http:" && !isLocalHttp) { + return `${label} must use https:// unless it is a local Forgejo endpoint`; + } + } catch { + return `${label} must be a valid URL`; + } + + return undefined; +} + async function fetchWithTimeout( url: string, init: RequestInit, @@ -47,6 +91,11 @@ function getErrorMessage(error: unknown, context: string): string { export async function checkForgejoReachability( baseUrl: string, ): Promise { + const validationError = validateForgejoBaseUrl(baseUrl); + if (validationError) { + return createCheckResult("Forgejo", false, validationError); + } + try { const response = await fetchWithTimeout(baseUrl, { method: "GET" }); if (response.ok) { @@ -70,6 +119,11 @@ export async function checkRepoAccess( baseUrl: string, pat: string, ): Promise { + const validationError = validateForgejoBaseUrl(baseUrl); + if (validationError) { + return createCheckResult("Forgejo", false, validationError); + } + try { const responses = await Promise.all([ fetchWithTimeout(`${baseUrl}/api/v1/user`, { diff --git a/examples/firebreak.config.example.json b/examples/firebreak.config.example.json deleted file mode 100644 index d534c5e..0000000 --- a/examples/firebreak.config.example.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "forgejoBaseUrl": "http://forgejo:3000" -} diff --git a/web/app/static/css/input.css b/web/app/static/css/input.css index 12e1d5f..f334266 100644 --- a/web/app/static/css/input.css +++ b/web/app/static/css/input.css @@ -17,15 +17,11 @@ --color-accent-foreground: #17191c; --color-primary: #2a2d31; - --color-primary-foreground: #ffffff; - --color-primary-hover: #17191c; - --color-primary-muted: rgb(23 25 28 / 10%); --color-secondary: #eeeeea; --color-secondary-foreground: #17191c; --color-border: #d8d8d2; - --color-border-subtle: #e9e9e4; --color-input: #ffffff; --color-ring: #2a2d31; --color-ring-muted: rgb(23 25 28 / 12%); @@ -39,9 +35,10 @@ --color-warning-foreground: oklch(54.7% 0.13 65); --color-warning-muted: oklch(96.3% 0.052 85); - --color-danger: #c62030; - --color-danger-foreground: #c62030; - --color-danger-muted: rgb(198 32 48 / 10%); + --color-danger: #b01c2a; + --color-danger-foreground: #d94555; + --color-danger-hover: #9a1824; + --color-danger-muted: rgb(176 28 42 / 10%); --color-expired: #5c5c58; --color-expired-foreground: #4b4b47; @@ -70,15 +67,11 @@ --color-accent-foreground: #f7f2e8; --color-primary: #2a2d31; - --color-primary-foreground: #f7f2e8; - --color-primary-hover: #17191c; - --color-primary-muted: rgb(247 242 232 / 14%); --color-secondary: #282b30; --color-secondary-foreground: #f7f2e8; --color-border: #34373d; - --color-border-subtle: #282b30; --color-input: #1f2226; --color-ring: #f7f2e8; --color-ring-muted: rgb(247 242 232 / 18%); @@ -92,8 +85,9 @@ --color-warning-foreground: oklch(86% 0.13 75); --color-warning-muted: oklch(35% 0.075 75); - --color-danger: #f04a36; - --color-danger-foreground: #ff7a66; + --color-danger: #d93f2d; + --color-danger-foreground: #f06a58; + --color-danger-hover: #c23625; --color-danger-muted: rgb(240 74 54 / 18%); --color-expired: #bdb8ad; @@ -151,7 +145,7 @@ } .btn-primary { - @apply text-primary-foreground bg-primary-hover hover:bg-[#c62030]/90 hover:text-[#f7f2e8]; + @apply bg-danger text-white hover:bg-danger-hover; } .btn-secondary { @@ -159,7 +153,7 @@ } .btn-borderless { - @apply bg-transparent text-foreground hover:bg-accent hover:text-accent-foreground; + @apply bg-danger text-white hover:bg-danger-hover; } .app-header { @@ -173,8 +167,8 @@ .app-header a, .app-header button, .app-header nav svg { - color: #f7f2e8; - stroke: #f7f2e8; + color: var(--color-foreground); + stroke: var(--color-foreground); } .app-header .brand-link svg { @@ -182,28 +176,29 @@ } .app-header .brand-link svg path[fill="#17191C"] { - fill: #f7f2e8; + fill: var(--color-foreground); } .app-header .btn-borderless { - color: #f7f2e8; + background: transparent; + color: var(--color-foreground); } .app-header .btn-borderless:hover { background: rgb(247 242 232 / 10%); - color: #fffdf8; + color: var(--color-foreground); } .app-header .btn-secondary { background: rgb(247 242 232 / 8%); border-color: rgb(247 242 232 / 18%); - color: #f7f2e8; + color: var(--color-foreground); } .app-header .btn-secondary:hover { background: rgb(247 242 232 / 14%); border-color: rgb(247 242 232 / 28%); - color: #fffdf8; + color: var(--color-foreground); } .landing-page .app-header { @@ -211,7 +206,7 @@ } .landing-page { - background: #17191c; + background: var(--color-background); } .brand-link svg { diff --git a/web/app/templates/error.html b/web/app/templates/error.html index 0264a44..4e0cf3d 100644 --- a/web/app/templates/error.html +++ b/web/app/templates/error.html @@ -78,14 +78,14 @@ 90% { transform: translate(-2px, 2px); } } .btn-zapped { - background: #c62030 !important; - color: #f7f2e8 !important; - box-shadow: 0 0 12px 4px rgba(198, 32, 48, 0.5), 0 0 30px 8px rgba(198, 32, 48, 0.25); + background: var(--color-danger) !important; + color: var(--color-foreground) !important; + box-shadow: 0 0 12px 4px color-mix(in srgb, var(--color-danger) 50%, transparent), 0 0 30px 8px color-mix(in srgb, var(--color-danger) 25%, transparent); animation: rattle 0.15s linear infinite; } #go-home-btn:hover { - background: #c62030; - color: #f7f2e8; + background: var(--color-danger-hover); + color: var(--color-foreground); } {% endif %} @@ -185,7 +185,7 @@ const blur = 30 + t * 40; const opacity = 0.5 + t * 0.4; const scale = 1 + t * 0.06; - btn.style.boxShadow = `0 0 ${spread}px ${spread/3}px rgba(198,32,48,${opacity}), 0 0 ${blur}px ${blur/3}px rgba(198,32,48,${opacity * 0.5})`; + btn.style.boxShadow = `0 0 ${spread}px ${spread/3}px rgba(217,63,45,${opacity}), 0 0 ${blur}px ${blur/3}px rgba(217,63,45,${opacity * 0.5})`; btn.style.scale = scale; if (t < 1) requestAnimationFrame(intensify); }