-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The patch is one line in single-file.go\n\nManuel Zedel's commit [`484cc2a`](https://github.com/mendersoftware/mender-server/commit/484cc2a13ad44d93cdf0f3c2ea9155b9bac4a969) on March 7, 2026 closes CVE-2026-49009. In `backend/services/create-artifact-worker/cmd/single-file.go`:\n\n```diff\n-\tc.FileName = args.Filename\n+\t// Sanitize filename: strip directory components to prevent path traversal\n+\tc.FileName = filepath.Base(args.Filename)\n+\tif c.FileName == \".\" || c.FileName == \"..\" {\n+\t\treturn errors.New(\"invalid filename\")\n+\t}\n```\n\n`args.Filename` is the value the authenticated tenant put in the `filename` field of the `args` JSON they POST to `/api/management/v1/deployments/artifacts/generate`. Pre-patch, the worker read that string straight into `c.FileName` and joined it with its own temp directory thirty lines later:\n\n```go\n//gotcha: must download under the correct name (destination name on the device)\n//artifact generator will not allow renaming it\ndownloadFile := filepath.Join(downloadDir, c.FileName)\n\nmlog.Verbose(\"downloading temp artifact to %s\", downloadFile)\n\nerr = cs3.Download(ctx, c.GetArtifactUri, downloadFile)\n```\n\nGo's `filepath.Join` cleans `..` segments but does not prevent them from escaping the base directory. With `c.FileName = \"../../../../usr/bin/mender-artifact\"`, `downloadFile` resolves to `/usr/bin/mender-artifact`. The next call is `cs3.Download`, which writes the attacker's uploaded bytes to that path.\n\n## The deployments service validated everything in the form except args\n\nThe traversal lives inside the worker, but the JSON it consumed reached the worker through a service that already had a validator. In `backend/services/deployments/model/image.go`:\n\n```go\nfunc (msg MultipartGenerateImageMsg) Validate() error {\n\tif err := validation.ValidateStruct(&msg,\n\t\tvalidation.Field(&msg.Name, validation.Required, lengthIn1To256),\n\t\tvalidation.Field(\n\t\t\t&msg.DeviceTypesCompatible,\n\t\t\tvalidation.Required,\n\t\t\tvalidation.Each(lengthIn1To256),\n\t\t\tlengthIn1To256,\n\t\t),\n\t\tvalidation.Field(&msg.Type, validation.Required, lengthIn1To256),\n\t); err != nil {\n\t\treturn err\n\t}\n```\n\n`Name`, `DeviceTypesCompatible`, `Type`. Not `Args`. The deployments service treats the `args` field as an opaque blob to forward to the workflow. The workflow forwards it to the worker as `--args ''`. The worker parses the JSON. The fields inside the JSON are the worker's contract, not the deployments service's.\n\nTwo components on either side of the API boundary, each owning its half, each validating what its half cared about. The `filename` field belongs to neither's scope. The path traversal lives in that gap.\n\n## How the write reaches an executable path\n\nThe worker's temp directory is created inside `CREATE_ARTIFACT_WORKDIR`, which the Dockerfile sets to `/var/cache/create-artifact-worker`. `os.MkdirTemp(c.Workdir, \"single-file\")` returns something like `/var/cache/create-artifact-worker/single-file3729134192`. Four `..` components from there reach the filesystem root.\n\nThe PoC's `exploit.py` uses exactly that:\n\n```python\nargs_json = {\n \"filename\": \"../../../../usr/bin/mender-artifact\",\n \"dest_dir\": \"/opt/mender/app\",\n \"software_name\": \"demo\",\n \"software_version\": \"1\",\n}\n```\n\n`/usr/bin/mender-artifact` is chosen for a reason. The worker's `Run()` function, after writing the download, invokes:\n\n```go\ncmd := exec.Command(\"/usr/bin/single-file-artifact-gen\", args...)\nstd, err := cmd.CombinedOutput()\n```\n\n`single-file-artifact-gen` is a shell script that the Dockerfile installs from `github.com/mendersoftware/mender`. After its argument parsing, the script's actual command line is:\n\n```bash\nmender-artifact write module-image \\\n -T single-file \\\n \"${device_types[@]}\" \\\n -o \"$output_path\" \\\n -n \"$artifact_name\" \\\n -f \"$dest_dir_file\" \\\n -f \"$filename_file\" \\\n -f \"$permissions_file\" \\\n -f \"$file\" \\\n \"${passthrough_args[@]}\"\n```\n\n`mender-artifact` is resolved via `$PATH`. `/usr/bin` is on `$PATH`. The shell finds `/usr/bin/mender-artifact`. That is the file the attacker just overwrote.\n\nThe PoC writes a `/bin/sh` script that base64-decodes and executes whatever command the attacker supplied:\n\n```sh\n#!/bin/sh\nCMD_B64=\"\"\nCMD=\"$(printf '%s' \"$CMD_B64\" | base64 -d 2>/dev/null || printf '%s' \"$CMD_B64\")\"\n/bin/sh -c \"$CMD\"\nexec /bin/sh \"$@\"\n```\n\nThe worker invokes `single-file-artifact-gen`, which calls a binary named `mender-artifact` with whatever arguments the worker assembled. The script ignores those arguments and runs the attacker's command. The artifact-generation workflow then proceeds. From the deployments service's perspective the request completed.\n\n## The Dockerfile makes the binary writable by the runtime user\n\n`args.Filename` reaching `filepath.Join` is the bug the patch closes. The reason that bug is RCE rather than a wasted file write is six lines in the [`Dockerfile`](https://github.com/mendersoftware/mender-server/blob/v4.1.0/backend/services/create-artifact-worker/Dockerfile):\n\n```dockerfile\nFROM ${REGISTRY}/library/alpine:3.23.4\nARG USER=65534:65534\nRUN apk add libc6-compat xz bash\nUSER $USER\n\n# Install mender-artifact\nADD --chmod=0755 https://raw.githubusercontent.com/mendersoftware/mender/master/support/modules-artifact-gen/single-file-artifact-gen \\\n /usr/bin/single-file-artifact-gen\nCOPY --from=builder --chown=$USER \\\n /build/mender-artifact \\\n /usr/bin/mender-artifact\n```\n\n`USER 65534:65534`. The container runs as nobody.\n\n`COPY --from=builder --chown=$USER /build/mender-artifact /usr/bin/mender-artifact`. The binary in `/usr/bin/mender-artifact` is owned by nobody.\n\nWriting to `/usr/bin/mender-artifact` from inside the container is nobody overwriting a file nobody owns. The filesystem rules approve the write before the path traversal even matters.\n\nThree binaries in the same Dockerfile carry the same `--chown=$USER`:\n\n```dockerfile\nCOPY --from=builder --chown=$USER /build/workflows /usr/bin/workflows\nCOPY --from=builder --chown=$USER /build/create-artifact /usr/bin/create-artifact\nCOPY --from=builder --chown=$USER /build/mender-artifact /usr/bin/mender-artifact\n```\n\nThe PoC picked `mender-artifact` because it is the binary the worker invokes next in the current workflow. `single-file-artifact-gen` is the only executable in `/usr/bin` that the worker touches and does not own: the Dockerfile installs it via `ADD --chmod=0755` without `--chown`, so the runtime user can execute it and not modify it. The runtime user can overwrite the executable that is about to be invoked. It cannot overwrite the shell script that invokes it. The PoC reads the Dockerfile and picks accordingly.\n\n## The next tenant to build an artifact runs the attacker's payload\n\nHosted Mender runs the `create-artifact-worker` as a long-lived container that processes the `generate_artifact` workflow queue. The vendor's [own advisory](https://mender.io/blog/cve-2026-49009-cve-2026-33552-input-sanitization-and-access-control-issues-in-mender-server) acknowledges that \"compromis[ing] the container for other users\" is the practical outcome.\n\nThe named victim is a tenant of Hosted Mender who is not the attacker. They submit a normal single-file artifact request. The workflow runs on a worker whose `/usr/bin/mender-artifact` has already been replaced by another tenant's PoC several minutes earlier. The script the worker invokes is the attacker's, executed under the worker's identity, with access to the worker's environment variables, the workflow context, the tenant token the workflow was given, and any pre-signed S3 URLs the platform handed the worker for inbound and outbound artifact storage. The victim's artifact build appears to succeed. The persistence lasts until the container's next restart.\n\nThere is no race between the two requests. The attacker's overwrite persists on disk. The next tenant whose job lands on the same worker is the next victim. The worker pool size is what bounds the blast radius.\n\n## The patch also quietly fixes argument injection\n\nThe same commit adds a new helper:\n\n```go\nfunc validateSafeString(name, value string, maxLen int) error {\n\tif len(value) > maxLen {\n\t\treturn fmt.Errorf(\"%s exceeds maximum length of %d\", name, maxLen)\n\t}\n\tif strings.HasPrefix(value, \"-\") {\n\t\treturn fmt.Errorf(\"%s must not start with '-'\", name)\n\t}\n\tif strings.ContainsAny(value, \"\\n\\r\\x00\") {\n\t\treturn fmt.Errorf(\"%s must not contain control characters\", name)\n\t}\n\treturn nil\n}\n```\n\nThe function is called on `filename`, `artifact-name`, `device-type`, `software_filesystem`, `software_name`, `software_version`, and `description`. Every one of those fields is concatenated into the `exec.Command` invocation that runs `single-file-artifact-gen`:\n\n```go\nargs := []string{\n \"-n\", c.ArtifactName,\n \"-d\", c.DestDir,\n \"-o\", outfile,\n}\nif c.SoftwareFilesystem != \"\" {\n args = append(args, \"--software-filesystem\", c.SoftwareFilesystem)\n}\nif c.SoftwareName != \"\" {\n args = append(args, \"--software-name\", c.SoftwareName)\n}\nif c.SoftwareVersion != \"\" {\n args = append(args, \"--software-version\", c.SoftwareVersion)\n}\nfor _, deviceType := range c.DeviceTypes {\n args = append(args, \"-t\", deviceType)\n}\nargs = append(args, downloadFile)\ncmd := exec.Command(\"/usr/bin/single-file-artifact-gen\", args...)\n```\n\nThe `strings.HasPrefix(value, \"-\")` rejection is argument-injection defense. A pre-patch tenant who set, say, `software_name` to `--output-path` would inject an additional flag into the `single-file-artifact-gen` invocation. The CVE description names path traversal and improper input sanitization. The patch closes one path traversal and seven separate argument-injection footguns in the same commit. The CVE record names one of those.\n\n## CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:L/I:N/A:N\n\nThe CVE record's CVSS vector reads `AV:N/AC:H/PR:L/UI:N/S:U/C:L/I:N/A:N`. Confidentiality: Low. Integrity: None. Availability: None. Attack complexity: High. The base score is 3.1.\n\nThe PoC writes a shell script of the attacker's choice to a binary the worker is about to execute. Confidentiality, integrity, and availability of every other tenant whose job lands on the same worker are all High until the container restarts. The base score for a correctly-vectored CVSS would be 8.8.\n\nThe vendor's advisory describes the impact as \"severe in this case\" for hosted Mender, naming the shared build worker as what gets compromised. The CVE record describes the same bug. Both records are public. Both cannot be accurate.\n\n## This is unauth-write-to-execution-path with the auth knob inverted\n\nThis is the auth-required cousin of [unauth-write-to-execution-path](/patterns/unauth-write-to-execution-path), the same substrate the [Pix for WooCommerce](/posts/pix-woocommerce-nonce-is-not-auth), [Breeze Cache](/posts/breeze-cache-cve-2026-3844-gravatar-fetcher-fetched-anything), and [n8n Git](/posts/n8n-git-cve-2026-21877-helper-was-already-there) exhibits sit on. The execute path is not a webroot here; it is a binary in the runtime user's `$PATH`. The write trigger is not anonymous HTTP; it is an authenticated tenant POSTing to a documented management endpoint. The substrate is unchanged: the worker's write path overlaps the worker's execute path, the overlap is reachable by callers the system already trusts to do the writing, and the overlapping files are owned by the same Linux user that does the writing.\n\nThe patch closes the traversal. The chown that makes the traversal worth doing is still in the Dockerfile.\n\nPoC: [j0xh-sec/CVE-2026-49009](https://github.com/j0xh-sec/CVE-2026-49009)","closing_line":"`filepath.Base` is one line. `--chown=$USER` is one line. The patch ships one of them.","hook_md":"Mender ships `create-artifact-worker` as an Alpine container that runs as UID 65534. The same Dockerfile installs `/usr/bin/mender-artifact` with `COPY --from=builder --chown=$USER`. UID 65534 owns the binary the worker is about to invoke. CVE-2026-49009 is the path-traversal bug in the worker's filename handling that made an authenticated tenant the writer of that file.","post_id":519,"slug":"mender-cve-2026-49009-worker-owns-the-binary","title":"CVE-2026-49009: Mender's Create-Artifact-Worker Owns The Binary It Invokes","type":"initial","unreadable_sentence":"The runtime user that downloads attacker-supplied files into the worker is the user that owns the binary the worker invokes next."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaoyQRgAKCRDeZjl4jgkQ JiURAQDwkBqbQx4RQcdeXfZcOvgtUxwQs+GTRekoBxP44jw0GwEAig10S09OPfoe oNuALxAzr9Ua3/SAXDRf1amA5HtGtQQ= =7OF3 -----END PGP SIGNATURE-----