singularity-forge/src/security-overrides.ts
Mikael Hugo 02a4339a51 refactor: rename pi-* packages to forge-native names (Phase 1)
Rename all four packages/pi-* directories to forge-native names,
stripping the 'pi' identity and establishing forge's own:

- packages/pi-coding-agent → packages/coding-agent
- packages/pi-ai → packages/ai
- packages/pi-agent-core → packages/agent-core
- packages/pi-tui → packages/tui

Package names updated:
- @singularity-forge/pi-coding-agent → @singularity-forge/coding-agent
- @singularity-forge/pi-ai → @singularity-forge/ai
- @singularity-forge/pi-agent-core → @singularity-forge/agent-core
- @singularity-forge/pi-tui → @singularity-forge/tui

All import references, bare string references, path references,
internal variable names (_bundledPi*), and dist files updated.
@mariozechner/pi-* third-party compat aliases preserved.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 11:28:01 +02:00

51 lines
1.5 KiB
TypeScript

/**
* Apply user-configured security overrides from global settings.json and env vars.
*
* Both overrides are global-only (not project-level) because the threat model is
* malicious project-level config in cloned repos. Global settings and env vars
* represent the user's own authority on their machine.
*
* Precedence: env var > settings.json > built-in defaults
*/
import {
type SettingsManager,
setAllowedCommandPrefixes,
} from "@singularity-forge/coding-agent";
import { setFetchAllowedUrls } from "./resources/extensions/search-the-web/url-utils.js";
export function applySecurityOverrides(settingsManager: SettingsManager): void {
// --- Command prefix allowlist ---
const envPrefixes = process.env.SF_ALLOWED_COMMAND_PREFIXES;
if (envPrefixes) {
const prefixes = envPrefixes
.split(",")
.map((s) => s.trim())
.filter(Boolean);
if (prefixes.length > 0) {
setAllowedCommandPrefixes(prefixes);
}
} else {
const settingsPrefixes = settingsManager.getAllowedCommandPrefixes();
if (settingsPrefixes && settingsPrefixes.length > 0) {
setAllowedCommandPrefixes(settingsPrefixes);
}
}
// --- Fetch URL allowlist (SSRF exemptions) ---
const envUrls = process.env.SF_FETCH_ALLOWED_URLS;
if (envUrls) {
const urls = envUrls
.split(",")
.map((s) => s.trim())
.filter(Boolean);
if (urls.length > 0) {
setFetchAllowedUrls(urls);
}
} else {
const settingsUrls = settingsManager.getFetchAllowedUrls();
if (settingsUrls && settingsUrls.length > 0) {
setFetchAllowedUrls(settingsUrls);
}
}
}