Harden env parsing and writes (#814)

This commit is contained in:
ekko
2026-05-17 15:39:31 +08:00
committed by GitHub
parent 6516d86dfc
commit ce5a9bb012
3 changed files with 39 additions and 21 deletions
@@ -88,7 +88,14 @@ export async function updateConfigYaml<T = void>(
// --- .env helpers ---
function assertValidEnvKey(key: string): void {
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) {
throw new Error(`Invalid .env key: ${JSON.stringify(key)}`)
}
}
export async function saveEnvValue(key: string, value: string): Promise<void> {
assertValidEnvKey(key)
const envPath = getActiveEnvPath()
await safeFileStore.updateText(envPath, (raw) => {
const remove = !value