mirror of
https://github.com/ZTatman/myst.git
synced 2026-11-22 21:07:57 +00:00
Compare commits
1 commit
7301609cd7
...
7c40aad4dc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c40aad4dc |
5 changed files with 34 additions and 64 deletions
|
|
@ -121,9 +121,3 @@ 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.
|
**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.
|
**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.
|
**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.
|
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,36 @@ import * as c from "yoctocolors";
|
||||||
import * as p from "@clack/prompts";
|
import * as p from "@clack/prompts";
|
||||||
|
|
||||||
import { generateEnvFile, SECRET_ENV_KEYS } from "../../utils/config.js";
|
import { generateEnvFile, SECRET_ENV_KEYS } from "../../utils/config.js";
|
||||||
import { validateForgejoBaseUrl } from "../../utils/forgejo-checks.js";
|
|
||||||
import { CommandConfig } from "../../cli-router.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 }) {
|
async function init(opts: { output?: string }) {
|
||||||
p.intro(c.bold("firebreak config init"));
|
p.intro(c.bold("firebreak config init"));
|
||||||
p.note(
|
p.note(
|
||||||
|
|
@ -91,7 +118,7 @@ async function init(opts: { output?: string }) {
|
||||||
message:
|
message:
|
||||||
"Forgejo API URL (how Firebreak reaches Forgejo, not your browser URL)?",
|
"Forgejo API URL (how Firebreak reaches Forgejo, not your browser URL)?",
|
||||||
placeholder: "http://forgejo:3000",
|
placeholder: "http://forgejo:3000",
|
||||||
validate: (v) => validateForgejoBaseUrl(v),
|
validate: (v) => validateHttpUrlOrHost(v, "Forgejo base URL"),
|
||||||
}),
|
}),
|
||||||
forgejoPat: () =>
|
forgejoPat: () =>
|
||||||
p.password({
|
p.password({
|
||||||
|
|
@ -151,7 +178,7 @@ async function init(opts: { output?: string }) {
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
);
|
);
|
||||||
p.log.success(
|
p.log.success(
|
||||||
"Done. Verify Firebreak's connection using 'firebreak config verify'.\nOnce verified, deploy!",
|
"Done. Verify firebreak's connection using the 'verify' command.\nOnce verified, deploy!",
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
s.stop();
|
s.stop();
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,7 @@ async function runForgejoChecks(
|
||||||
|
|
||||||
async function verifyCommand(opts: VerifyOptions): Promise<void> {
|
async function verifyCommand(opts: VerifyOptions): Promise<void> {
|
||||||
const isDiagnostic = opts.diagnostic ?? false;
|
const isDiagnostic = opts.diagnostic ?? false;
|
||||||
p.intro(c.bold("firebreak config verify"));
|
p.intro(c.bold("firebreak verify"));
|
||||||
|
|
||||||
const config = loadConfig();
|
const config = loadConfig();
|
||||||
if (!config) {
|
if (!config) {
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,5 @@
|
||||||
const TIMEOUT = 5000;
|
const TIMEOUT = 5000;
|
||||||
|
|
||||||
const LOCAL_HTTP_HOSTS = new Set([
|
|
||||||
"forgejo",
|
|
||||||
"localhost",
|
|
||||||
"127.0.0.1",
|
|
||||||
"::1",
|
|
||||||
"[::1]",
|
|
||||||
]);
|
|
||||||
|
|
||||||
export type CheckResult = {
|
export type CheckResult = {
|
||||||
name: string;
|
name: string;
|
||||||
success: boolean;
|
success: boolean;
|
||||||
|
|
@ -26,42 +18,6 @@ export function createCheckResult(
|
||||||
return result;
|
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(
|
async function fetchWithTimeout(
|
||||||
url: string,
|
url: string,
|
||||||
init: RequestInit,
|
init: RequestInit,
|
||||||
|
|
@ -91,11 +47,6 @@ function getErrorMessage(error: unknown, context: string): string {
|
||||||
export async function checkForgejoReachability(
|
export async function checkForgejoReachability(
|
||||||
baseUrl: string,
|
baseUrl: string,
|
||||||
): Promise<CheckResult> {
|
): Promise<CheckResult> {
|
||||||
const validationError = validateForgejoBaseUrl(baseUrl);
|
|
||||||
if (validationError) {
|
|
||||||
return createCheckResult("Forgejo", false, validationError);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetchWithTimeout(baseUrl, { method: "GET" });
|
const response = await fetchWithTimeout(baseUrl, { method: "GET" });
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
|
@ -119,11 +70,6 @@ export async function checkRepoAccess(
|
||||||
baseUrl: string,
|
baseUrl: string,
|
||||||
pat: string,
|
pat: string,
|
||||||
): Promise<CheckResult> {
|
): Promise<CheckResult> {
|
||||||
const validationError = validateForgejoBaseUrl(baseUrl);
|
|
||||||
if (validationError) {
|
|
||||||
return createCheckResult("Forgejo", false, validationError);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const responses = await Promise.all([
|
const responses = await Promise.all([
|
||||||
fetchWithTimeout(`${baseUrl}/api/v1/user`, {
|
fetchWithTimeout(`${baseUrl}/api/v1/user`, {
|
||||||
|
|
|
||||||
3
examples/firebreak.config.example.json
Normal file
3
examples/firebreak.config.example.json
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"forgejoBaseUrl": "http://forgejo:3000"
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue