-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The pre-patch gate had two paths for oversized bodies. Both set `body` to nil.\n\nMoby's AuthZ middleware lives in `pkg/authorization/authz.go`. The function the Docker engine calls before forwarding any request to the daemon is `(*Ctx).AuthZRequest`. Pre-patch, it opened with this:\n\n```go\nconst maxBodySize = 1048576 // 1MB\n\nfunc (ctx *Ctx) AuthZRequest(w http.ResponseWriter, r *http.Request) error {\n var body []byte\n if sendBody(ctx.requestURI, r.Header) && (r.ContentLength > 0 || isChunked(r)) && r.ContentLength < maxBodySize {\n var err error\n body, r.Body, err = drainBody(r.Body)\n if err != nil {\n return err\n }\n }\n // ... assemble Request and call plugin with body\n}\n```\n\nThree conditions, ANDed. Look at the third: `r.ContentLength < maxBodySize`. When the caller sends `Content-Length: 1048577`, the third condition is false. The entire if-block is skipped. `body` keeps its zero value, which is `nil`.\n\nIf the caller uses chunked transfer encoding and omits Content-Length entirely, the third condition (`-1 < 1048576`) is true and the function reaches `drainBody`:\n\n```go\n// drainBody dump the body (if its length is less than 1MB) without modifying the request state\nfunc drainBody(body io.ReadCloser) ([]byte, io.ReadCloser, error) {\n bufReader := bufio.NewReaderSize(body, maxBodySize)\n newBody := ioutils.NewReadCloserWrapper(bufReader, func() error { return body.Close() })\n\n data, err := bufReader.Peek(maxBodySize)\n // Body size exceeds max body size\n if err == nil {\n log.G(context.TODO()).Warnf(\"Request body is larger than: '%d' skipping body\", maxBodySize)\n return nil, newBody, nil\n }\n // Body size is less than maximum size\n if err == io.EOF {\n return data, newBody, nil\n }\n return nil, newBody, err\n}\n```\n\n`bufio.Reader.Peek(n)` returns `err == nil` precisely when at least `n` bytes are buffered. For the AuthZ caller, that condition means the request body is at least one megabyte. The function logs the line, then returns `nil` for the data, `newBody` for the wrapped reader, and `nil` for the error.\n\nTwo paths into `AuthZRequest`, same outcome: `body` is `nil` before the function reaches the plugin call.\n\n## The daemon was reading `r.Body`, not `body`.\n\nThe AuthZ context's plugin call uses `body` for the `RequestBody` field it sends to the plugin:\n\n```go\nctx.authReq = &Request{\n User: ctx.user,\n UserAuthNMethod: ctx.userAuthNMethod,\n RequestMethod: ctx.requestMethod,\n RequestURI: ctx.requestURI,\n RequestBody: body,\n RequestHeaders: headers(r.Header),\n}\n```\n\n`body` is `nil`. The plugin receives a `Request` whose `RequestBody` is empty. From the plugin's perspective, the caller has POSTed to `/v1.51/containers/create` with no body. There is nothing in the body to refuse. The plugin reads what it has, method, URI, headers, and returns allow.\n\n`r.Body`, the original request stream, is on the other side of the function. In the early-skip branch it was never touched. In the `drainBody` branch it has been wrapped in `newBody`, which is itself a buffered reader around the same underlying stream, and reassigned to `r.Body`. In both cases the bytes are still on the wire. The daemon's `/containers/create` handler reads them and JSON-decodes them.\n\nWhat the daemon decodes is what the PoC sends:\n\n```json\n{\n \"Image\": \"alpine\",\n \"Cmd\": [\"sleep\", \"infinity\"],\n \"HostConfig\": {\n \"Privileged\": true,\n \"Binds\": [\"/:/host\"]\n },\n \"Labels\": {\n \"poc\": \"cve-2026-34040-full-lab\",\n \"lab_only\": \"true\",\n \"padding\": \"AAAAAAAA...AAAA\"\n }\n}\n```\n\n`Labels.padding` is one megabyte plus one byte of the letter A. The daemon discards it as an arbitrary user label; the field is harmless after JSON parsing. Its only job was to push the encoded request past `maxBodySize` so the AuthZ check would skip it. The fields the daemon actually acts on, `Privileged: true` and `Binds: [\"/:/host\"]`, are intact.\n\nThe plugin saw a POST to `/containers/create` with no body. The daemon saw a POST to `/containers/create` with `Privileged: true` and `Binds: [\"/:/host\"]`. The same TCP connection. The same JSON object. The two readers disagreed about how much of it to read.\n\n## The Docker API call a Docker AuthZ plugin exists to refuse.\n\nThe Moby maintainers ship the AuthZ plugin interface because there are container-create payloads a multi-tenant operator cannot allow from semi-trusted callers. A container with `Privileged: true` shares the host's device namespace and capability set. A container with `Binds: [\"/:/host\"]` mounts the host root filesystem inside the container. The two fields together, privileged plus host-root bind, are not a feature an administrator would expose to anyone they did not already trust with `sudo`.\n\nAfter the AuthZ bypass, the PoC creates exactly that combination and starts the container. The chain to a host root shell is one chroot:\n\n```bash\n$ sudo docker exec -it $cid /bin/sh\n/ # chroot /host /bin/bash\nhost# id\nuid=0(root) gid=0(root) groups=0(root)\nhost# hostname\ndocker-host-vm # the host's hostname, not the container's\n```\n\nThe PoC's `mode_rce_proof` does the equivalent non-interactively, writing `/tmp/cve_2026_34040_rce_proof` on the host and reading it back through `cat /host/tmp/cve_2026_34040_rce_proof`. The marker file is host-side because `/host` was the host's `/`. The container is the chroot; the host is the actual filesystem.\n\nThe PoC's README is explicit about what the CVE itself is: \"이 취약점 자체가 직접 `/etc/shadow`를 읽거나 RCE를 실행하는 것은 아닙니다.\" The vulnerability itself does not read `/etc/shadow` or execute RCE; it bypasses the gate that would have refused the request that does. The post-bypass steps are stock Docker primitives that the gate existed to refuse.\n\n## The patch fixed two ways to fail open and shipped the budget bump that fail-closed required.\n\nThe fix is two consecutive commits to `pkg/authorization/authz.go` by Paweł Gronowski of Docker, in a private security fork that landed on `main` in late March 2026 as a single \"Merge commit from fork.\" The first commit's full message:\n\n> pkg/authz: Reject requests exceeding body size limit\n>\n> Previously, the authorization system would silently skip body inspection when request bodies exceeded the maximum size limit (1MiB).\n>\n> The authorization plugins would receive an empty body for inspection while the actual large payload would still be processed by the Docker daemon, allowing malicious requests to circumvent plugin-based security controls.\n\nThe author's description of the bug is the description of the bug. The fix replaces both fail-open paths with a single inline rejection:\n\n```diff\n-func isChunked(r *http.Request) bool { ... }\n-\n func (ctx *Ctx) AuthZRequest(w http.ResponseWriter, r *http.Request) error {\n var body []byte\n- if sendBody(ctx.requestURI, r.Header) && (r.ContentLength > 0 || isChunked(r)) && r.ContentLength < maxBodySize {\n- var err error\n- body, r.Body, err = drainBody(r.Body)\n- if err != nil {\n+ if sendBody(ctx.requestURI, r.Header) {\n+ bufBody := bufio.NewReaderSize(r.Body, maxBodySize+1)\n+ r.Body = ioutils.NewReadCloserWrapper(bufBody, r.Body.Close)\n+\n+ peeked, err := bufBody.Peek(maxBodySize + 1)\n+ if err == nil {\n+ return fmt.Errorf(\"request body too large for authorization plugin: size exceeds %d bytes\", maxBodySize)\n+ } else if err != io.EOF {\n return err\n }\n+ body = peeked\n }\n```\n\nThe `Peek(maxBodySize + 1)` is the same buffered-reader idiom `drainBody` used. The change is what the function does with the peek result. Pre-patch: log and return `nil`. Post-patch: return an error. The error path back at the HTTP layer turns the request into HTTP 500 and the plugin never sees it. No fail-open path remains.\n\n`git log` puts the timestamp on that commit at `Mon Feb 16 14:15:24 2026 +0100`. The next commit, by the same author, is timestamped `Mon Feb 16 14:16:06 2026 +0100`. Forty-two seconds. The message:\n\n> pkg/authz: Increase body limit to 4 MiB\n>\n> Some endpoint could potentially use a body request than 1 MiB without malicious intent.\n\nOne-line diff: `const maxBodySize = 4 * 1024 * 1024`, up from `1048576`.\n\nThe two commits taken together are the architecture's confession. The first made the gate reject what it could not inspect. The second tripled the inspection budget because rejection at one megabyte would have broken legitimate clients sending fat container-create payloads. The original code, the code Gronowski was patching, had picked the same tradeoff the other direction: keep the legitimate clients working, accept the silent skip. The bug was not that an early Moby maintainer failed to imagine an attacker padding `Labels`. The bug was that the gate's designer treated body-too-large as an operational concern, and the gate's user treated body-too-large as a request to bypass the gate.\n\nThe author shipped the security fix and the budget bump that the security fix made necessary in the same forty-two seconds. The second commit is the first commit's apology to legitimate users.\n\n## The Warnf called it 'skipping body.' The daemon did not skip it.\n\nThis is the [fail-open-intercept](/patterns/fail-open-intercept) pattern in its purest dialect: a security gate that cannot enforce the property it was deployed to enforce, choosing to forward the request anyway with a log line for the operator. Prior exhibits include [Tomcat's `EncryptInterceptor`](/posts/tomcat-encryptinterceptor-fails-open), which catches `GeneralSecurityException` and calls `super.messageReceived(msg)` outside the try block; DataEase's `CommunityTokenFilter`, which writes a 401 inside a catch and calls `filterChain.doFilter()` after it; and gitsign, which catches a panic in a generic wrapper and exits zero on an unsigned commit.\n\nMoby's variant differs from those in one detail. In Tomcat, DataEase, gitsign, and Admidio, the fail-open lives in a catch block. The gate's designer added the catch to keep the pipeline running through an exception they thought was rare. The catch is the apology.\n\nIn Moby, the fail-open is not a catch block. It is a budget. The pre-patch gate's author wrote `Warnf(\"Request body is larger than: '%d' skipping body\", maxBodySize)` followed by `return nil, newBody, nil`. There is no exception. There is no catch. There is an `if err == nil` branch that explicitly handles the success case of `Peek(maxBodySize)`, meaning, the case where the body is at least that big, and chooses to log it and continue.\n\nThe gate's designer did not fail open by accident. They wrote the fail-open path explicitly and gave it a log line. The choice was operational: a gate that rejects every request whose body exceeds the inspection budget will reject some legitimate requests, and the original developer chose to let those requests through rather than break Docker clients with fat payloads. The decision was internally consistent and produced the CVE.\n\nTwo paths through `AuthZRequest`. Both set `body` to `nil` for oversized requests. Neither path also set `r.Body` to `nil`. The daemon was on the other side of `r.Body`, and the daemon was the one creating the container.\n\nPoC: [m0nk3ygod/CVE-2026-34040-PoC](https://github.com/m0nk3ygod/CVE-2026-34040-PoC)","closing_line":"The patch made the ceiling fail closed. The ceiling remains.","hook_md":"The Docker administrator who deploys an AuthZ plugin is solving a specific problem. They want the Docker API to refuse requests that ask for `HostConfig.Privileged: true` and `Binds: [\"/:/host\"]` in the same call, because those two fields together hand the caller a root shell on the host. The plugin is the refusal. Send the request, the plugin returns deny, the daemon returns HTTP 403, the container does not create. The administrator has tested this. It works.\n\nCVE-2026-34040 is the request shape the test did not cover. Add a 1,048,577-byte string to `Labels.padding` and send the same request. The plugin returns allow. The container creates. The bind mount works. `chroot /host /bin/bash` opens.\n\nThe bypass is one megabyte plus one byte.","post_id":580,"slug":"moby-cve-2026-34040-authz-skipped-bodies-daemon-read-them","title":"CVE-2026-34040: Moby's AuthZ Plugin Skipped Bodies Larger Than 1 MiB. The Daemon Read Them.","type":"initial","unreadable_sentence":"The author shipped the security fix and the budget bump that the security fix made necessary in the same forty-two seconds."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCarlrggAKCRDeZjl4jgkQ Jp9AAQDAzWsFaOQkJWPndLqbb/JtbKkPN7aT52pB+ltaYsTKsAD9H+q++Lkwtu5A 2D6Fmw/NXlwTMbSjUtBIXYcElV/m9gk= =C+S9 -----END PGP SIGNATURE-----