Security fixes land on the latest minor release line. Older lines are not patched; upgrade instead.
| Version | Supported |
|---|---|
| 0.9.x | Yes |
| < 0.9 | No |
If you discover a security vulnerability in Forge, please do not open a public issue.
Instead, report it privately:
- Go to Security Advisories
- Or email: security@forge-lang.dev
Include:
- Description of the vulnerability
- Steps to reproduce
- Potential impact
- Suggested fix (if any)
We will acknowledge your report within 48 hours and provide a timeline for a fix.
Forge is a young language. These are the controls that exist today and their exact scope.
sh, shell, sh_lines, sh_json, sh_ok, run_command, and pipe_to return a permission error under forge run unless the --allow-run flag is passed:
forge --allow-run run deploy.fgThe REPL and forge -e enable shell execution automatically, since a person is typing the code. forge build --native --allow-run bakes the permission into a standalone binary; without it the binary denies shell execution.
Loading a native plugin (
import native "libfoo") runs arbitrary machine code inside the Forge process. Nothing Forge enforces — no capability,--sandbox,FORGE_FS_BASE, the SSRF guard,--max-timeor the MCP output capture — applies to code inside the library. It can read and write any file, open sockets, spawn processes, and corrupt or crash Forge. Grantingffiis equivalent to granting everything.
forge runandforge testrefuse to load native code unless--allow-ffi(any library) or--allow-ffi=PATHS(only libraries at or under those paths) is given, orallow-ffiis set inforge.toml[permissions]. It is opt-in like--allow-run, because a script could otherwise write a library to disk and load it to escape every other restriction.- The REPL and
forge -eallow it (a person is typing), unless--sandboxis given. --sandbox,forge mcpand the embeddingSandboxdeny it unless explicitly granted (--allow-ffi=PATHS/Sandbox::allow_ffi). Never grantffito code you would not run as a native binary yourself.- The check runs on the resolved, canonical library path before the library is opened (opening already runs its initializers), so
..and symlinks cannot widen a scoped grant. There is no library search path: Forge only loads the file the program names, relative to the importing file or the working directory. - Prefer path-scoped grants to a directory only you can write to (
--allow-ffi=./plugins). A writable plugin directory lets anyone who can write there run code as you. - Plugins are never unloaded, and they must be thread-safe. A plugin that violates the ABI (
crates/forge-plugin/include/forge_plugin.h) can cause undefined behaviour; Forge validates the descriptor and every returned value it can check (tags, UTF-8, NULL pointers, nesting depth), but cannot protect against a library that writes through bad pointers.
The HTTP client (http.*, fetch, download, crawl) refuses requests whose host is, or resolves to, a private, loopback, or link-local address. The resolved address is pinned for the connection, and every redirect target is re-checked. To call local services on purpose (for example in development), set:
FORGE_HTTP_ALLOW_PRIVATE=1 forge run client.fgWhen FORGE_FS_BASE is set to a directory, every fs.* operation is confined to paths under it, on both the VM and the interpreter. Paths are canonicalized with symlinks resolved, so .. traversal and symlinks pointing outside the base are both rejected. When the variable is unset or empty, fs.* can reach any path the process can.
Scope: confinement covers the fs module, csv.read/csv.write, toml.read, env.load, SQLite db.open files and http.download destinations. For new code prefer the capability flags below (--sandbox --allow-read=DIR --allow-write=DIR), which apply the same symlink-aware resolution and can be combined with FORGE_FS_BASE; both checks must pass.
db (SQLite), pg (PostgreSQL) and mysql accept a params array. Always pass untrusted input as a parameter, never by string concatenation:
db.query("SELECT * FROM users WHERE name = ?", [name])
Note: the interpreter binds these parameters correctly. Parameter binding on the default bytecode VM is still being brought to parity, so verify with --interp if a query that takes parameters returns unexpected null columns. See the roadmap's VM parity work.
@serverbinds to127.0.0.1unless you passhost:explicitly.- CORS is restrictive (same-origin) by default. Opt into permissive CORS with
@server(port: 8080, cors: "permissive"). - At most 512 requests run at once by default; further requests get
503withRetry-After. - Each request runs in a forked interpreter, so one request cannot mutate another request's state.
- Inbound
X-Request-Idheaders are capped at 64 characters.
The sandbox is designed for running Forge source you do not trust — code
written by an AI agent (forge mcp), by users of your application
(forge_lang::Sandbox, the Python package), or downloaded scripts
(forge --sandbox run). The attacker controls the script; the host
controls the policy. Within the granted capabilities the script must not
be able to: reach paths, hosts or capabilities it was not granted; run
processes; read the host's environment, stdin or command line; exit or
cd the host; crash the host (panic, abort, stack overflow) or keep
running after its time limit; corrupt the MCP protocol stream; or see
another sandbox's state. Not in scope: scripts granted run (a
subprocess can do anything the host user can), a malicious MCP client
(the server trusts its client), and other processes that modify files
inside a granted directory while a script runs. The latest audit, with
every finding and its regression test, is
docs/SECURITY_AUDIT.md.
Forge has a capability-based permission model shared by the VM and the interpreter. Every privileged operation asks one central check against the active policy and fails with the same message shape:
permission denied: fs.write (/etc/passwd) — run with --allow-write or grant it in the host policy
| Capability | Covers | CLI flag |
|---|---|---|
fs.read |
fs.read/list/exists/size/lines/read_json/is_dir/is_file, csv.read, toml.read, env.load, db.open files, import (see below), watch, path.resolve/path.relative |
--allow-read[=PATHS] |
fs.write |
fs.write/append/remove/mkdir/copy/rename/write_json, csv.write, db.open files, http.download destination |
--allow-write[=PATHS] |
net |
http.*, fetch, download, crawl, ws.connect, binding an @server port, the server of pg.connect/mysql.connect |
--allow-net[=HOSTS] |
env |
env.* |
--allow-env |
db |
db.*, pg.*, mysql.* (file databases also need fs.read + fs.write; network databases also need net) |
--allow-db |
run |
sh, shell, sh_lines, sh_json, sh_ok, run_command, pipe_to, which |
--allow-run |
ai |
ask |
--allow-ai |
process |
exit(), cd(), the host's stdin (input(), io.prompt, term.confirm, term.menu) and command line (io.args*) |
always granted by the CLI; host policy only |
ffi |
import native — loading a native plugin. Full trust: see "Native plugins are full trust" |
--allow-ffi[=PATHS] |
Defaults: forge run allows everything except run and ffi; -e and the REPL also allow run and ffi. --sandbox switches to default-deny, and each --allow-* flag grants one capability back:
forge run --sandbox agent.fg # nothing allowed
forge run --sandbox --allow-read=./data --allow-write=./out agent.fg
forge run --sandbox --allow-net=api.example.com,*.cdn.example.com agent.fg
forge run --allow-read=./data app.fg # scoped flag restricts just that capability
forge run --max-time 30 job.fg # wall-clock limit, exit code 124
forge run --max-fuel 50000000 job.fg # deterministic step budget
forge run --max-memory 256MB job.fg # memory limit- Under a restricted policy SQLite cannot open files by itself:
ATTACH DATABASE,VACUUM INTOandfile:URI names are refused unless bothfs.readandfs.writeare unrestricted. - Under a restricted policy (
fs.read,fs.writeornetnot fully granted),env.set/env.loadcannot change Forge's own configuration: theFORGE_*variables the runtime reads (FORGE_HTTP_ALLOW_PRIVATE,FORGE_FS_BASE,FORGE_AI_URL, ...),OPENAI_API_KEY,OTEL_*,HTTP_PROXY/HTTPS_PROXY/ALL_PROXY/NO_PROXYandRUST_LOG(list:RESERVED_KEYSinsrc/stdlib/env.rs). - Path scopes are resolved like the OS resolves them: made absolute, every existing component canonicalized (symlinks followed,
..applied to the real parent), the not-yet-existing tail normalized. A symlink or..that leads outside a granted directory is denied; a dangling symlink is always denied. Grants are resolved once, at startup. fs.exists,fs.is_dirandfs.is_filereturnfalseinstead of failing when the path is outside the grant, so they cannot probe for files.- Host scopes match
host,*.domain(subdomains and the domain itself) orhost:port, case-insensitively. Whennetis scoped, every redirect target must also be on the allowlist. The SSRF guard still applies on top: granting127.0.0.1does not bypass it (useFORGE_HTTP_ALLOW_PRIVATE=1). importof modules under the entry script's directory (or the test directory, orforge_modules/) is always allowed; any other module path needsfs.read.- The flags work before or after the subcommand (
forge --sandbox run x.fgorforge run --sandbox x.fg) and apply toforge testas well.
The same policy can live in forge.toml; CLI flags override it per capability. A malformed [permissions] table (including an unknown key) is an error, never silently ignored:
[permissions]
sandbox = true
allow-read = ["./data"] # or true
allow-write = ["./out"]
allow-net = ["api.example.com"]
allow-env = true
allow-ffi = ["./plugins"] # native plugins: full trust
max-time = 30Hosts that run untrusted Forge code (AI agents, automation) use forge_lang::Sandbox, which starts from deny-all — including process, so a script cannot call exit() on the host:
use forge_lang::{Capability, Sandbox};
use std::time::Duration;
let out = Sandbox::new()
.allow_read(["./data"])
.allow_net(["api.example.com"])
.allow(Capability::Ai)
.max_time(Duration::from_secs(5))
.run_source(script)?; // Result<Output { stdout }, SandboxError>- The policy is installed on the sandbox's worker thread, not process-wide, so concurrent sandboxes and the host itself are independent. Every thread the engines fork (
spawn,squad,timeout,schedule,watch) inherits the policy of the thread that forked it (permissions::spawn). say/println/printoutput is captured inOutput::stdout. Errors come back asSandboxError::{Syntax, PermissionDenied, Runtime, Timeout}.max_timereturns control to the host by the deadline: the program is cancelled cooperatively, and if it does not stop within a short grace period its worker thread is detached. Cancellation reaches everything the program started —spawned andsquadtasks,timeoutbodies, imported modules — and every blocking wait (receive,await,select,wait,time.sleep, iterating a channel).max_outputis charged on every write, so a print loop stops at the limit instead of growing the capture between checks.schedule,watchand@serverare never started inside a sandbox, including from imported modules and tasks.- A size that cannot be allocated (
repeat_str("x", 10**14),range(0, 10**14)) is a runtime error, never a process abort. - Resource limits (
max_fuel,max_memory, or a fullforge_lang::Limitsvia.limits(...)) come back asSandboxError::{FuelExhausted, MemoryLimit, ResourceLimit}; see "Resource limits" below.max_memoryneedsforge_lang::CountingAllocatoras the host's#[global_allocator](the run fails with a clear error otherwise). - Lower-level:
forge_lang::Capabilities(policy builder),forge_lang::permissions::{set_global, scope, require}.
Wall-clock time is not enough for multi-tenant use: it depends on machine load and does not bound memory. Every run can also carry a budget (src/runtime/limits.rs), set with CLI flags, forge_lang::Sandbox, or forge mcp (which applies defaults):
| Limit | Meaning | CLI / API | Error |
|---|---|---|---|
| Fuel | Execution steps. VM: one per bytecode instruction; interpreter: one per statement, call and loop iteration. Deterministic: a single-threaded program runs out at exactly the same step on every run and every machine (per engine — the engines count different units). | --max-fuel N, Sandbox::max_fuel |
fuel exhausted: ... (FuelExhausted) |
| Memory | VM: estimated live bytes of the GC heap (strings, arrays, objects, maps, sets, closures, boxed ints); crossing the limit forces a collection and the run fails only if the live heap is still too big. Interpreter: bytes held by the run's threads, measured by CountingAllocator and polled at every step. Under Sandbox (and forge mcp) the VM also polls that meter at its safe points, so the limit covers every task of the run (each spawned VM task has its own GC heap). |
--max-memory 256MB, Sandbox::max_memory |
memory limit exceeded: ... (MemoryLimit) |
| Value size | Longest string and largest collection a program may build, checked before allocating (repeat_str("x", 1e12), range(1e12), pad_start, doubling s = s + s). With a memory limit they default to what the limit could hold. |
Limits::{max_string_bytes, max_collection_len} |
resource limit exceeded: ... (ResourceLimit) |
| Handles | Concurrently open files (fs calls, SQLite connections), sockets (HTTP requests, WebSockets, PostgreSQL/MySQL connections), subprocesses and tasks (spawn, timeout blocks). |
Limits::{max_open_files, max_sockets, max_processes, max_tasks} |
resource limit exceeded: too many ... |
| Imports | Module files loaded per run. | Limits::max_imports |
resource limit exceeded: more than N imports |
- Fuel and memory are fatal.
try/catch,safeandretrydo not catch them, and the budget remembers the trip: if a builtin swallows the error (assert_throws, a failed task), every later step fails too and the host still reports the limit. The other limits are ordinary runtime errors a program may catch. - The host survives. A tripped run unwinds normally; a sandbox's memory is released with its worker thread, and the next run starts from a fresh budget. Budgets are per run and inherited by every thread the run forks, never shared between sandboxes.
- Overhead. With no limits set, engines pay one decrement and branch per safe point they already had (VM: per instruction, folded into the existing
timeoutpoll; interpreter: per statement/call/iteration), and the counting allocator pays one thread-local load per allocation. See CHANGELOG for measured numbers. - Servers. With
forge run --max-fuel/--max-memory app.fg, every HTTP request fork and every WebSocket connection gets a fresh budget with those limits (a request that trips one gets a 500; the server keeps serving). On the interpreter fallback only fuel is per request.schedule/watchblocks spend the run's own budget. - JIT. Native code has no fuel counter, so while a fuel limit is active the VM does not enter JIT code (hot functions keep running in the VM). The JIT never allocates on the GC heap, so memory accounting is unaffected.
- Approximations. VM object sizes are estimates; the interpreter's meter also counts transient copies and may undercount memory allocated before the run and freed during it. Either engine can overshoot the memory limit by what a single step allocates (bounded by the value-size caps), and the VM by up to 1/8 of the limit when the live heap sits just under it.
forge mcp exposes the embedding sandbox to AI agents over the Model Context Protocol (stdio). Its policy is built like the CLI's but always starts from deny-all, including process; only the --allow-* flags and forge.toml [permissions] grant capabilities (sandbox = false is ignored, and run needs an explicit --allow-run / allow-run = true). --max-time (default 30s) bounds each call rather than the server process.
- Every
run_forgecall gets a fresh engine instance (the VM by default;--engine interpfor the interpreter) on its own thread; nothing persists between calls unless the agent passes asession_id. A timed-out script is cancelled cooperatively and, if stuck in a native call, detached; at most 8 calls run at once. Tasks a callspawns and never awaits are stopped when the call ends. - Every call (and every session step and Forge tool call) also gets a fresh resource budget: by default 400,000,000 VM instructions of fuel (200,000,000 interpreter steps with
--engine interp), 256 MiB of memory, 32 open files, 16 sockets, 4 subprocesses, 16 tasks and 256 imports (forge_lang::mcp::default_limits).--max-fuel/--max-memorychange the server's limits; an agent'smax_fuelargument can only lower the fuel. Errors come back asfuel_exhausted,memory_limitorresource_limit. - Sessions (
run_forgewithsession_id) keep one interpreter's top-level state between calls (session steps always run on the interpreter, whatever--enginesays, and their fuel counts interpreter steps). Each step still runs on a fresh worker thread under the full policy, deadline, output cap and cancellation; only the environment carries over. Sessions are isolated from each other, limited in number (--max-sessions, default 16) and dropped after--session-idle(default 900s); a step whose worker had to be detached ends its session. Each step gets fresh fuel, while the memory limit covers everything the session holds: the bytes its interpreter retained after the previous step count from the start of the next one, so a session's state can never exceed the per-call memory limit (reset_sessionfrees it).--max-sessions 0disables sessions. - Forge-authored tools (
forge mcp serve tools.fg): the file is trusted operator code, but its top level and every tool call run inside the same sandbox asrun_forge(the server's policy, plus the file's directory andforge_modules/as import roots). Each call runs in a fresh fork of the top-level state, so calls cannot see each other. Arguments are validated against the generated schema in Rust before any Forge code runs. - MCP code (
run_forge, Forge tools) runs on the bytecode VM by default, or on the interpreter withforge mcp --engine interp. The containment is one wrapper around either engine (Sandbox::run_contained): worker thread, policy, fresh budget, output capture shared by every thread of the run (runtime::stdio, inherited with the policy), deadline and cancellation (including blocking waits andtime.sleep), no host runtime, and the run's token set when it ends. Programs the VM cannot run faithfully (unknown decorators) run on the interpreter inside the same sandbox. Session steps (session_id) always run on the interpreter: the VM cannot yet carry top-level bindings between separately compiled steps faithfully. - Script output is captured (including
spawned tasks,timeoutblocks, imports andio.print), capped at 64 KiB in the response, and a script that prints more than 1 MiB is stopped. - On Unix the protocol stream is moved to private close-on-exec descriptors before any script runs; fd 0 becomes
/dev/nulland fd 1 is redirected to stderr. A script (or a granted subprocess) can therefore neither read protocol input nor inject protocol output. On other platforms only the sandbox capture applies. - Untrusted source cannot crash the server with deep nesting: the parser rejects nesting beyond a fixed depth.
- The server trusts its client: anyone who can write to its stdin can run code with the granted capabilities. Grant the narrowest scopes (
--allow-net=api.example.com,--allow-read=./data).
- Memory accounting is approximate (see "Resource limits"); call depth is bounded separately by
--max-depth/FORGE_MAX_DEPTH. Builtins that run long without calling back into Forge code (sorting a huge array, a slow regex) are not charged fuel per element, andreplace/joindo not check the string cap before building their result. - Fuel limits disable the JIT tier for the run.
--max-timein the CLI ends the process from a watchdog thread; the embedding API cancels cooperatively. Neither interrupts a single blocking native call (an HTTP request, DNS lookup, WebSocket or database connect, or a granted subprocess): the host gets control back on time and the detached worker finishes when the call returns.- HTTP server handlers run on tokio's blocking pool and use the process-wide policy (the CLI's). The embedding
Sandboxdoes not start servers,scheduleorwatchblocks. - stderr output (
log.*,term.*drawing, download progress, warnings) is neither captured nor capped;forge mcpon Unix sends it to the server's stderr. os.*(hostname, home directory, pid, CPU count),cwd()andfs.temp_dirare not gated; they reveal host identity, not file contents.- The
envcapability is process-wide: one sandbox'senv.setis visible to the host and every other sandbox. Grant it only to trusted single-tenant hosts. - MySQL and WebSocket handles are unguessable bearer tokens in process-wide tables; a script that is given another sandbox's handle can use it.
- Path checks and the subsequent open are not atomic: a process outside the sandbox that swaps a directory for a symlink between the two can win the race. (Races inside the sandbox, such as another task calling
cd, are closed: operations use the resolved path that was checked.) - On the VM (CLI only), converting a value nested millions of levels deep (e.g.
json.stringify) can overflow the native stack and abort the process.
These are documented limitations, not vulnerabilities:
- Without
--sandbox(or a host policy), a Forge program keeps its historical defaults: it has the same OS permissions as the process running it, except for subprocesses. See "Sandboxing and permissions" for what the sandbox does and does not cover yet. unsafeRust is used in a few places: the C ABI entry points for native/AOT binaries (src/lib.rs), and the JIT's native-code calls and runtime helpers (src/vm/jit/,src/vm/machine.rs). Reports involving these are especially welcome.askandforge chatsend prompts to the configured LLM provider. Do not put secrets in prompts.
- Pass user input to SQL only as query parameters.
- Do not pass untrusted input to
sh()/run_command(), and only grant--allow-runto scripts you trust. - Only pass
--allow-ffifor plugins you built or trust as much as Forge itself; scope it to their directory. - Run scripts you did not write with
--sandboxand only the--allow-*grants they need; embed untrusted code withforge_lang::Sandbox. - Set
FORGE_FS_BASEwhen running scripts that should only touch one directory. - Leave
FORGE_HTTP_ALLOW_PRIVATEunset in production. - Keep secrets in environment variables (
env.get()), never hardcoded.