Nginx UI: MCP nginx_config_add skips config directive validation → authenticated nginx directive injection (RCE on the official image)
Summary
internal/config/validation.go (ValidateConfigFile) is a security control that blocks dangerous
nginx directives — js_*, perl_*, load_module of the njs/perl modules, and user root. It is
enforced on three of the four config-write paths: api/config/add.go, api/config/modify.go, and
mcp/config/config_modify.go. The fourth path — the MCP tool nginx_config_add
(mcp/config/config_add.go) — does NOT call it: it writes the caller-supplied content straight to
disk and reloads nginx. An authenticated MCP caller (or an MCP agent induced via prompt injection)
can therefore inject exactly the directives the control is meant to block, leading to nginx code
execution on deployments where the njs/perl module is available (e.g. the official Docker image).
Root cause — an incomplete hardening patch
Commit 3e411d38 ("Harden config write paths", 2026-04-21) introduced ValidateConfigFile and
wired it into the config-write paths — but its changeset touched only:
api/config/add.go (+6), api/config/modify.go (+8), internal/config/validation.go (+199),
mcp/config/config_modify.go (+5)
It did NOT touch mcp/config/config_add.go. So the MCP add path was left without the validation
that all of its sibling paths received. config_add.go has never called ValidateConfigFile
(verified via git history); this is an oversight in the hardening, not a regression.
Affected code (mcp/config/config_add.go, handleNginxConfigAdd)
content := mcp.GetString(args, "content") // caller-controlled
...
path, err := config.ResolveConfPath(baseDir, name) // path is sandboxed to the conf dir (OK)
...
err = os.WriteFile(path, []byte(content), 0644) //