Gotenberg's fix for CVE-2026-42589 starts as three validation patches and ends as a library deletion. The validation patches add a regex on user-supplied metadata keys, a control-character check on metadata values, and a group-prefix strip for the pseudo-tag filter. Eleven days after the third patch, the maintainer removes go-exiftool from go.mod and rewrites the integration in fifty lines of exec.CommandContext. The comment in the new code is more honest than the commit message: argv invocation is not susceptible to stdin-protocol injection the way the previous go-exiftool backend was, and the previous backend is still on the Go module proxy.
CVE-2026-42589: Gotenberg Fixed It Twice. The Advisory Names The First Fix.
vendor
patterns
cve
proof of concept
PoC: GHSA-rqgh-gxv4-6657 (CVE-2026-42589)
/forms/pdfengines/metadata/write parses a JSON object. The keys become arguments to a Perl process.
Gotenberg is a Docker-packaged stateless PDF API written in Go. CVE-2026-42589 lives in its pdfengines module, which exposes a route called writeMetadata:
// pkg/modules/pdfengines/routes.go
func writeMetadataRoute(...) api.Route {
return api.Route{
Method: http.MethodPost,
Path: "/forms/pdfengines/metadata/write",
Handler: ...
}
}The handler reads multipart form data, parses a metadata field as JSON, and hands the resulting map to the engine:
// pkg/modules/api/multipart.go (FormDataPdfMetadata excerpt)
var metadata map[string]any
if err := json.Unmarshal([]byte(value), &metadata); err != nil {
return fmt.Errorf("unmarshal metadata: %w", err)
}A map[string]any from encoding/json accepts any UTF-8 string as a key. There is no schema. The keys travel into the engine untouched.
The engine is the exiftool module:
// pkg/modules/exiftool/exiftool.go (v8.29.1, pre-patch)
func (engine *ExifTool) WriteMetadata(
ctx context.Context, logger *zap.Logger,
inputPath string, metadata map[string]interface{},
) error {
exifToolBinary, err := exifTool.NewExiftool(...)
if err != nil {
return fmt.Errorf("create new exiftool binary: %w", err)
}
defer exifToolBinary.Close()
fileMetadata := exifToolBinary.ExtractMetadata(inputPath)
if fileMetadata[0].Err != nil {
return fmt.Errorf("extract metadata: %w", fileMetadata[0].Err)
}
for key, value := range metadata {
if isDangerousTag(key) {
continue
}
// serialize value to string
fileMetadata[0].SetString(key, val)
}
return exifToolBinary.WriteMetadata(fileMetadata)
}exifTool.NewExiftool is the constructor for github.com/barasher/go-exiftool, a third-party wrapper around Phil Harvey's ExifTool. It is the bridge.
// github.com/barasher/go-exiftool v1.10.0, exiftool.go
var initArgs = []string{"-stay_open", "True", "-@", "-"}
func NewExiftool(opts ...func(*Exiftool) error) (*Exiftool, error) {
e := &Exiftool{}
// ...
e.cmd = exec.Command(e.binPath, initArgs...)
e.stdin, _ = e.cmd.StdinPipe()
e.stdMergedOut, _ = e.cmd.StdoutPipe()
// ...
}-stay_open True -@ - is ExifTool's persistent mode. Phil Harvey designed it for batch tools that want to reuse a single Perl interpreter across many invocations. ExifTool reads one argument per line from the -@ - file (stdin), and treats a literal line containing -execute as the end of an argv batch. Everything between batches behaves exactly like an argv to the exiftool command.
go-exiftool exposes this through WriteMetadata. Inside the wrapper the loop writes each key=value pair to the persistent stdin:
// barasher/go-exiftool exiftool.go, WriteMetadata
for k, v := range origin.Fields {
// serialize v -> str
fmt.Fprintln(e.stdin, "-"+k+"="+str)
}
fmt.Fprintln(e.stdin, "-overwrite_original")
fmt.Fprintln(e.stdin, origin.File)
fmt.Fprintln(e.stdin, "-execute")fmt.Fprintln writes the formatted string and appends \n. The destination is stdin of a Perl process whose protocol uses \n as the argv separator. If k contains \n, the wrapper does not see two keys, the wrapper sees one key. ExifTool sees two arguments.
The PoC is one curl.
The advisory publishes the proof:
curl -X POST http://target:3000/forms/pdfengines/metadata/write \
-F "[email protected]" \
-F 'metadata={"Title\n-if\n(system(\"id\"))": "x"}'The metadata field is a JSON object with a single key. The key contains two embedded newlines. After json.Unmarshal, Go has a map[string]any with one entry whose key is the literal string Title\n-if\n(system("id")) and whose value is x. The dangerous-tag filter, which compares against the exact strings FileName and Directory, does not match. The loop calls SetString. The wrapper builds an argv line.
When fmt.Fprintln(e.stdin, "-"+k+"="+str) runs, the bytes that hit the Perl process are:
-Title
-if
(system("id"))=x
-overwrite_original
input.pdf
-executeExifTool sees -Title (a valid tag write request with no value), then -if, then (system("id"))=x as the argument to -if. ExifTool's -if flag exists. It is documented. It takes a Perl expression that gets passed to eval and used to decide whether the current file matches a condition. The expression evaluates side effects. system("id") runs /usr/bin/id with the privileges of the Gotenberg process, which in the Docker image is root.
The argv parse continues with -overwrite_original, the file path, and -execute. The PDF gets written. The HTTP response returns 200. The container has run an attacker's command, and the only thing in the request body that looks unusual is a \n in a JSON string. JSON strings are allowed to contain \n.
The patch sequence is the testimony.
The Gotenberg repository's git log between the CVE-2026-42589 advisory date and the next minor release contains four commits that touch the exiftool module. The progression is the auto-confession.
| Commit | Date | What it adds |
|---|---|---|
405f106 |
Apr 6 | safeKeyPattern regex on keys |
55d1952 |
Apr 11 | validateMetadataValue rejecting \n\r\x00 in values |
46e1909 |
Apr 13 | Group-prefix strip in isDangerousTag |
68e0f88 |
Apr 24 | Delete go-exiftool. Rewrite with exec.CommandContext. |
The first commit lands the regex:
var safeKeyPattern = regexp.MustCompile(`^[a-zA-Z0-9\-_.:]+$`)This is the obvious fix. Keys are ExifTool tag names. Tag names are alphanumerics, colons (for group prefixes), and a few punctuation characters. Anything else is rejected. The commit message describes the fix as "validate metadata keys" and stops there.
Five days later the second commit lands. It adds a function nobody promised:
func validateMetadataValue(v interface{}) error {
// reject \n, \r, \x00 in serialized form
...
}The comment in the diff names the gap the first patch left:
// metadata values are also passed through go-exiftool's stdin pipe; a value // containing a newline can terminate the current argument and inject a new // flag the same way a key can.
The first patch shipped without anyone running the test that would have caught this. The second patch documents that the value vector exists and was missed.
Two days after that, the third commit lands. The dangerous-tag filter was checking exact string equality against FileName and Directory. ExifTool accepts group-prefixed tags. System:FileName is the same tag as FileName for write purposes. The filter saw two different strings. The third commit strips the group prefix before comparing:
func isDangerousTag(k string) bool {
if i := strings.LastIndex(k, ":"); i != -1 {
k = k[i+1:]
}
// ... compare against allowlist
}Three commits, three different ways the wrapper around go-exiftool failed to be safe. The advisory is published with these three commits as the named fix. The release is tagged v8.31.0 on April 16. GHSA-rqgh-gxv4-6657 lists < 8.31.0 as the affected range for CVE-2026-42589.
Eight days after v8.31.0, the maintainer pushes commit 68e0f88. The diff is large. The summary line is "refactor exiftool integration." The substance is the deletion of the barasher/go-exiftool import, the removal of the persistent-mode wrapper, and the replacement of WriteMetadata with this:
// pkg/modules/exiftool/exiftool.go (post-rewrite)
func (engine *ExifTool) WriteMetadata(
ctx context.Context, logger *zap.Logger,
inputPath string, metadata map[string]interface{},
) error {
args := []string{"-overwrite_original"}
for k, v := range metadata {
if !safeKeyPattern.MatchString(k) {
continue
}
if err := validateMetadataValue(v); err != nil {
continue
}
args = append(args, fmt.Sprintf("-%s=%v", k, v))
}
args = append(args, inputPath)
cmd := exec.CommandContext(ctx, engine.binPath, args...)
return cmd.Run()
}The validations stay. The persistent-mode pipe is gone. ExifTool is now invoked the way every shell script in the world invokes it: an argv. A \n inside args[i] is no longer a separator, because there is no separator. The kernel's execve reads the argv as a fixed-length array of byte strings.
The comment the maintainer left next to the new function reads, verbatim:
// We invoke exiftool via argv rather than via stay_open mode. Argv is not // subject to the line-delimited injection that the previous backend permitted // even after we validated keys and values, because validation is harder than // not parsing.
"Validation is harder than not parsing" is the kind of sentence that gets engraved on the door of a vault after the vault has been emptied once.
v8.31.0 is the validation. v8.32.0 is the architecture.
The release timeline lays it out:
| Version | Date | Contents |
|---|---|---|
v8.29.1 |
Mar 30 | Last vulnerable release |
v8.31.0 |
Apr 16 | Three validation commits. Advisory names this. |
v8.32.0 |
Apr 30 | Library deletion. Argv rewrite. No advisory mention. |
The CVE-2026-42589 advisory says fixed in v8.31.0. The advisory is correct in the narrow sense that the published PoC, including the group-prefix bypass that produced the third commit, no longer works against v8.31.0. The advisory does not say that two weeks after v8.31.0 shipped, the maintainer concluded that key and value validation on top of a line-delimited stdin protocol was not a sound abstraction and ripped the substrate out.
Anyone who reads the advisory and pins >= 8.31.0 is pinned to the version where Gotenberg is trying to make go-exiftool safe. Anyone who reads the changelog past the advisory date is on the version where Gotenberg has decided go-exiftool is not a thing it is using anymore.
This is the second auto-confession. The first is in the comment on the second patch ("a value containing a newline can terminate the current argument"). The second is in the version skew: an advisory naming the validation release, a follow-up release naming nothing, and a deleted dependency.
The deleted dependency is still on the Go module proxy. barasher/go-exiftool v1.10.0 has not been yanked. It is still the top hit when a Go developer searches for "exiftool go library." Its README does not mention that one of its known consumers removed it for being unsafe in the presence of attacker-controlled keys.
go-exiftool is the substrate. Gotenberg is one of its consumers.
The mechanism class here is content-is-command. User data is supposed to be data. The library decides that an efficient way to talk to ExifTool is to keep one Perl process alive and feed it newline-delimited arguments. The boundary between "what the application asked for" and "what ExifTool will execute" is a \n byte inside a string that already came from a JSON parser that does not treat \n as special. The application reads a map. The map's keys are strings. The library writes strings into a pipe. The pipe is a control channel that uses string contents as commands.
The chain is an emergent-primitive: encoding/json accepting any UTF-8 in a map key, go-exiftool's Fprintln(e.stdin, ...) interpolation, ExifTool's -stay_open True -@ - line-delimited argv protocol, and ExifTool's -if flag accepting Perl expressions. Each of these components is documented. Each makes sense in isolation. The primitive is not in any of them. The primitive is in their composition.
Gotenberg is not the only place this happens. The Node.js library exiftool-vendored shipped CVE-2026-43893 with the same shape three weeks earlier: user-supplied keys reach the same -stay_open Perl stdin without value-side encoding. Two language ecosystems, two wrappers, three weeks apart, both shipping the same class of mistake on top of Phil Harvey's persistent-mode protocol. The protocol is not the bug. The wrappers' decision to interpolate user input into the protocol is the bug. Both wrappers were popular for years before anyone filed.
The same class of "the parser does what you wrote, not what you meant" runs through every recent post on this site. Handlebars trusted its own AST on the assumption that the compiler is the only thing that produces ASTs. graphql-ruby compiled the schema on the assumption that the schema came from the application. Gotenberg passed JSON keys through go-exiftool's stdin pipe on the assumption that the keys came from a trusted JSON object. The assumption is the bug. The bug class is the assumption.
The Apr 11 comment said it. The Apr 24 comment said it twice. "Validation is harder than not parsing" is not a slogan, it is the postmortem.
v8.31.0 fixed the bug. v8.32.0 fixed the library.