//nefariousplan

CVE-2026-42593: Gotenberg Shipped the Gate and the Bypass in the Same Commit

vendor

pattern

cve

proof of concept

Julien Neuhart's commit 19db80b on 18 March 2026 at 04:46 added stamping and watermarking to Gotenberg. In pkg/modules/pdfengines/routes.go he wrote the security check twice. The dedicated /forms/pdfengines/stamp route rejected a request that declared stampSource=pdf with no uploaded file. Six other routes in the same commit, including /forms/pdfengines/merge two hundred lines higher in the same file, accepted the same combination and passed the caller's stampExpression value to pdfcpu, which opened the path and composited its pages onto the output PDF before returning the PDF to the caller. CVE-2026-42593 is the gap between those two shapes, shipped together, lived together for thirty-four days.

The dedicated route refused. The six other routes assigned.

Gotenberg's dedicated stamp endpoint, the route whose entire purpose is to apply a stamp to a PDF, wrote the security check as a gate. Pre-patch, in stampRoute:

if stamp.Source == gotenberg.StampSourceImage || stamp.Source == gotenberg.StampSourcePDF {
    if stampFile == "" {
        return api.WrapError(
            errors.New("no stamp file provided"),
            api.NewSentinelHttpError(
                http.StatusBadRequest,
                "Invalid form data: a stamp file is required for image or pdf source",
            ),
        )
    }
    stamp.Expression = stampFile
}

Read as English: when the caller declares a binary stamp source, a stamp file must be present; if it is not, return 400; otherwise replace stamp.Expression with the uploaded file's path. The outer conditional is the door. The inner conditional decides whether the door closes.

Two hundred lines higher in the same file, mergeRoute wrote the same precondition test as an assignment guard:

if (watermark.Source == gotenberg.StampSourceImage || watermark.Source == gotenberg.StampSourcePDF) && watermarkFile != "" {
    watermark.Expression = watermarkFile
}
if (stamp.Source == gotenberg.StampSourceImage || stamp.Source == gotenberg.StampSourcePDF) && stampFile != "" {
    stamp.Expression = stampFile
}

Read as English: replace the expression with the uploaded file's path only when the caller declares a binary source and uploads a file. When either side of the && is false, fall through with whatever stamp.Expression already contained.

What stamp.Expression already contained is whatever the caller submitted as the stampExpression form field. FormDataPdfStamp does no path validation, no extension check, no containment check; it byte-equality-tests the source value and copies the expression string straight from the form. When the source is text, the expression is what pdfcpu calls a page-position descriptor, a small DSL of layout instructions. When the source is image or pdf, the expression is a filesystem path. The pre-patch dedicated route enforced that the path had to be one Gotenberg created on the caller's behalf. The pre-patch combined route enforced no such thing. That is the gap CVE-2026-42593 names.

The same shape repeated in five more files. splitRoute in pkg/modules/pdfengines/routes.go. convertRoute in pkg/modules/libreoffice/routes.go. convertUrlRoute, convertHtmlRoute, and convertMarkdownRoute in pkg/modules/chromium/routes.go. Six routes. Twelve call sites once you count both the stamp and the watermark assignments on each. Every one of them was the assignment shape. None of them was the gate.

What pdfcpu does with the path you sent

stamp.Expression flows through WatermarkStub or StampStub into engine.Watermark or engine.Stamp, which on the default pdfcpu adapter builds this argv:

args := []string{command, "add", "--mode", mode}
if stamp.Pages != "" {
    args = append(args, "--pages", stamp.Pages)
}
args = append(args, "--", stamp.Expression, description, inputPath, inputPath)

stamp.Expression becomes the first positional argument to pdfcpu watermark add --mode pdf -- <expression> <description> <input> <input>. pdfcpu opens the file at that path, parses it as a PDF, and composites its pages onto each page of <input>, writing the result back to the same <input> path. The Gotenberg handler then returns the input PDF (which now carries the secret PDF's pages composited on top of its own) as the HTTP response body.

The deployment shape Gotenberg ships as: docker run gotenberg/gotenberg on port 3000, behind a load balancer the platform team treats as an internal PDF microservice. The accounts-payable team's "generate this PDF" service. The signed-document worker queue's "merge cover letter into contract" step. The browser-extension SaaS's "convert this HTML to PDF for the user" feature. An attacker against that deployment sends:

curl -F '[email protected]' \
     -F 'stampSource=pdf' \
     -F 'stampExpression=/var/secrets/invoice-template.pdf' \
     -o stolen.pdf \
     https://gotenberg.example.com/forms/pdfengines/merge

cover.pdf is a one-page PDF the attacker built locally; any input PDF works because the route's job is to merge inputs. The stampSource=pdf field tells FormDataPdfStamp to construct a Stamp with Source == StampSourcePDF and Expression == "/var/secrets/invoice-template.pdf". No file is uploaded as stampFile, so the && stampFile != "" half of the conditional is false, and the assignment block is skipped. stamp.Expression retains the caller's path.

Gotenberg merges the input PDFs into one output, then calls engine.Stamp on the merged file with the Stamp struct as the descriptor. pdfcpu opens /var/secrets/invoice-template.pdf from the Gotenberg container's filesystem and composites its pages onto the merged document. The merged document plus the composited secret is what the response body contains. The attacker downloads stolen.pdf, opens it locally, reads the pages of the file they were never authorized to see.

The GHSA advisory observes a second primitive: because pdfcpu's error response differs between "file does not exist" and "file exists but is not a valid PDF", a caller can probe the filesystem for the presence of any file by submitting a path and reading the response. The bug is an unauthenticated read primitive against the entire file descriptor space of the Gotenberg process.

gotenberg/gotenberg:8.31.0 was the published Docker image from 16 April 2026 until 30 April 2026. The Dockerfile runs the binary as the gotenberg user with read access to whatever the operator mounted into the container. Common mounts: shared template directories, signed-but-unsent invoices waiting on a worker queue, configuration files the orchestration team passes in at deploy time. Anything that lives at a path the operator named or guessed becomes the response body of the next merge request.

The same commit shipped both shapes

git blame -L 1268,1285 -- pkg/modules/pdfengines/routes.go on the pre-patch revision returns commit 19db80b. git blame -L 676,690 -- pkg/modules/pdfengines/routes.go on the same pre-patch revision returns commit 19db80b. Same commit. The feature commit message is feat(pdfengines): add watermark and stamp feature. The author is Julien Neuhart. The timestamp is 2026-03-18 04:46:12 +0100.

The dedicated route's gated shape and the six combined routes' assignment shape were authored together. There is no later refactor that broke a working check; there is no security commit that landed in one file and missed five others. There is one commit that contains both shapes, by one author, dated 04:46 local time on a Wednesday morning in March.

The hand the author wrote the dedicated route with held one model. Stamping is what the route does. The caller asked for stampSource=pdf; the resource the route needs is the PDF. If the caller did not supply it, the request is malformed, and the route's only correct answer is 400. The check reads as a gate because rejecting bad input is the route's entire job above the stamp.

The hand the author wrote the combined route with held a different model. The combined route's job is to merge, or split, or convert HTML. Stamping is a side feature, configured by optional form fields the caller can omit entirely. The author reached for the conditional that lets the caller opt in: when the caller declares a binary source and provides the file, use the file. When either is absent, the implicit answer was "do nothing further." But "do nothing further" did not mean "do not stamp." It meant "stamp with the expression already on the struct." The expression already on the struct was the attacker's path.

Security gates wrapped around optional features fail open by default. The optional-feature framing presumes the caller knows what they are asking for; the failure mode of a malformed optional request becomes "fall through with whatever the form contained" rather than "reject the request." Both preconditions of the original gate were present on the line. Only the rejection half was missing.

The combined routes shipped in v8.28.0 on 19 March 2026, the day after the feature commit. Every release through v8.31.0 on 16 April 2026 carried the same shape. The fix was committed on 21 April 2026 and tagged in v8.32.0 on 30 April 2026. The advisory was published the same day. The thirty-four days between the feature commit and the fix are the window the bypass shipped to every operator who pinned gotenberg/gotenberg:8 or gotenberg/gotenberg:latest.

The fix is the function the dedicated route already was

Commit c204cad does not invent a new check. It lifts the dedicated route's logic out of stampRoute and watermarkRoute, names it EnsureStampFile and EnsureWatermarkFile, places both helpers in the pdfengines package, and rewires all eight call sites (six divergent, two canonical) to call them:

func EnsureStampFile(stamp *gotenberg.Stamp, uploadedFile string) error {
    if stamp.Source != gotenberg.StampSourceImage && stamp.Source != gotenberg.StampSourcePDF {
        return nil
    }
    if uploadedFile == "" {
        return api.WrapError(
            errors.New("no stamp file provided for image or pdf source"),
            api.NewSentinelHttpError(
                http.StatusBadRequest,
                "Invalid form data: a stamp file is required for image or pdf source",
            ),
        )
    }
    stamp.Expression = uploadedFile
    return nil
}

This is the dedicated route's gated shape, hoisted into a function, with the predicate inverted (!= instead of ==, the text and empty cases short-circuit out) so it reads as a normal preconditions helper. The body is the same body. The 400 response string is the same string. The behaviour the eight routes converge on is the behaviour two of them already had.

This is the Parallel Implementation Gap pattern: a capability implemented by two or more parallel modules, where the canonical module gates a security-relevant operation and the divergent module does not, both exposing the same client-facing contract, both running in the same deployment. The catalog has Astro's two /_image endpoints, Vite's /@fs route and HMR WebSocket, Axios's buffered and streaming branches of one HTTP function, JeecgBoot's login and mLogin sibling methods on the same controller, and Next.js's maximumResponseBody wired to one branch of a ternary, among many others. Each of those bugs is the same shape across a different distance. Astro's gap was across two packages over twelve months. mcp-atlassian's was across upload-versus-download directions in one Python module. Axios's was across two branches of one function in one file. NocoBase's was across two exported keys of one object literal, sixteen months apart.

The Gotenberg case is the smallest-distance instance the catalog has yet recorded. The two parallel implementations are not in two files, not in two packages, not separated by months of commits, not authored by different people. They are in the same file. They are in the same commit. They are in the same author's working tree at the same minute. The pattern's punchline is normally about the gate not propagating across a structural boundary the codebase made invisible. Here, no boundary divided the two shapes at all. The author wrote both, in the order the file's line numbers preserve, and the second hand did not call the first.

Closing this CVE was a matter of running the existing function eight more times. EnsureStampFile and EnsureWatermarkFile did not exist in v8.31.0. The logic they would later contain did. The two routes that already had it have always served as the reference. The patch's only act of authorship was to read the reference and copy it to the six callers that had been written from the wrong template.

The fix already existed in 8.31.0. The six routes the CVE names just had not called it.