-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"`File::GlobMapper::_getFiles` runs `eval \"\\$outFile = $self->{OutputPattern};\"`. `$self->{OutputPattern}` is the caller's output-glob string, wrapped in literal double quotes by `_parseOutputGlob`. A literal `\"` anywhere in the output glob closes the wrapper. Whatever follows is parsed by Perl. The eval was committed on August 22, 2005, in the initial CPAN import of IO::Compress 2.000_00. It was removed on May 16, 2026, in the patch the CPAN Security Group later filed as CVE-2026-48962.\n\nThe template language has two metacharacters. The template engine was the Perl interpreter.\n\n## The output glob is a filename template with two metacharacters\n\n`File::GlobMapper` is the dual-life module that turns calls like\n\n```perl\nuse IO::Compress::Gzip qw(gzip);\ngzip '' => '';\n```\n\ninto a list of `(input, output)` filename pairs that `gzip` walks. The first argument matches existing files. The second is a filename template. The template grammar is two characters. `#N` is replaced with the Nth captured group from the input glob, and `*` is replaced with the whole matched filename. There is no other syntax. The `IO::Compress::FAQ` POD says exactly this and shows exactly this example.\n\nA two-character grammar can be implemented two ways. Substitute the placeholders with the captured strings, or build a Perl expression that yields the substituted result and run it. `File::GlobMapper` chose the second.\n\n`_parseOutputGlob` is the build step. Given the user's output glob `\"$dir/#1.txt.gz\"`, it produces the Perl source `\"$dir/${1}.txt.gz\"` and stores it on the object:\n\n```perl\nsub _parseOutputGlob\n{\n my $self = shift ;\n my $string = $self->{OutputGlob} ;\n ...\n my $noPreBS = '(?{OutputPattern} = $string ;\n return 1 ;\n}\n```\n\n`_getFiles` is the run step. It walks the matched input files, binds `$1`, `$2`, ... and `$inFile`, and runs the stored expression:\n\n```perl\nsub _getFiles\n{\n ...\n if ( $inFile =~ m/$self->{InputPattern}/ )\n {\n no warnings 'uninitialized';\n eval \"\\$outFile = $self->{OutputPattern};\" ;\n ...\n }\n}\n```\n\nFor benign inputs the substitution produces benign Perl. The two `s///g` calls do no escaping. They presuppose that the user's bytes between the wrapping double quotes are inert to the Perl tokenizer. A caller who puts a literal `\"` in the output glob closes the wrapper after the user's string has been interpolated, and whatever follows is parsed by Perl as part of the same eval body.\n\n## The template engine was eval STRING\n\nThe exploit is the most direct possible reading of the code. The output glob is\n\n```\nout\"; system(\"id\"); \"\n```\n\n`_parseOutputGlob` finds no `#N` and no `*`, so it does no substitution. It wraps the string in double quotes and stores `\"\\\"out\\\"; system(\\\"id\\\"); \\\"\\\"\"`. `_getFiles` then runs\n\n```perl\neval \"\\$outFile = \\\"out\\\"; system(\\\"id\\\"); \\\"\\\";\"\n```\n\nPerl parses this as three statements. An assignment of `\"out\"` to `$outFile`, a `system(\"id\")` call, and a no-op string. The `id` command runs at the privilege of the calling process.\n\nA minimal reproducer using the public API:\n\n```perl\nuse IO::Compress::Gzip qw(gzip);\nmkdir 'src';\nopen my $f, '>', 'src/a.txt' or die $!;\nprint $f \"x\\n\";\nclose $f;\n\ngzip '' => '';\n```\n\nBoth arguments are angle-bracket fileglobs. That is the documented invocation. `IO::Compress::Base::Common::ckInOutParams` detects the angle brackets via\n\n```perl\nsub isaFileGlobString\n{\n return defined $_[0] && $_[0] =~ /^<.*>$/;\n}\n```\n\nsets `inType` and `outType` to `'fileglob'`, and instantiates `File::GlobMapper->new($_[0], $_[1])`. The output string reaches `_parseOutputGlob` and then the eval. `id` runs.\n\nThe attack surface is wherever an IO::Compress program accepts an attacker-influenced string into the output-glob slot. Every `IO::Compress::*` and `IO::Uncompress::*` entry point (`gzip`, `gunzip`, `zip`, `unzip`, `bzip2`, `bunzip2`, `inflate`, `deflate`, `anyinflate`, `anyuncompress`, `rawdeflate`, `rawinflate`) inherits the surface, because `ckInOutParams` is the single dispatcher Common.pm provides them all. The `IO::Compress::Gzip` POD documents the fileglob form as the convenience for batch-compressing files: `gzip '' => '<*.gz>'`. The dispatcher does not inspect the caller's argument for double quotes before it reaches the eval. The dispatcher has no reason to. The dispatcher is documenting a filename template.\n\nIO::Compress is a dual-life Perl module. It ships in core Perl. Every install of Perl has carried this eval in its core distribution since the IO::Compress modules were promoted in 2007. The dual-life packaging means Red Hat, Debian, Strawberry Perl, and the macOS system Perl all carried the same eval, on the same code path, reached through the same two-argument call convention. `File::GlobMapper`'s own module version is `1.001`. The line number of the eval did not change between the 2005 import and the 2026 fix.\n\n## The grammar fit in three regexes the whole time\n\nThe May 16, 2026 patch is 52 added lines in `GlobMapper.pm`. It introduces five byte constants:\n\n```perl\nour $BEGIN_DELIM = \"\\xFF\";\nour $END_DELIM = \"\\xFE\";\nour $BACKSLASH_ESC = \"\\xFD\";\nour $HASH_ESC = \"\\xFC\";\nour $STAR_ESC = \"\\xFB\";\n```\n\n`_parseOutputGlob` no longer wraps the output in double quotes and no longer constructs Perl source. It rewrites `#1` to `\\xFF1\\xFE` and `*` to `\\xFF\\xFE` (with `\\#` and `\\*` escaped to `\\xFC` and `\\xFB` first) and stores the result:\n\n```diff\n- $string =~ s/${noPreBS}#(\\d)/\\${$1}/g;\n- $string =~ s#${noPreBS}\\*#\\${inFile}#g;\n- $string = '\"' . $string . '\"';\n+ $string =~ s/\\\\#/${HASH_ESC}/g;\n+ $string =~ s/\\\\\\*/${STAR_ESC}/g;\n+ $string =~ s/${noPreESC}#(\\d)/${BEGIN_DELIM}${1}${END_DELIM}/g;\n+ $string =~ s#\\*#${BEGIN_DELIM}${END_DELIM}#g;\n $self->{OutputPattern} = $string ;\n```\n\n`_getFiles` reads the placeholders back and substitutes the captures and the matched filename. The eval is gone:\n\n```diff\n- no warnings 'uninitialized';\n- eval \"\\$outFile = $self->{OutputPattern};\" ;\n+ $outFile = $self->{OutputPattern};\n+ my $ix = 1;\n+ $outFile =~ s/${noPreESC}${BEGIN_DELIM}${END_DELIM}/$inFile/g;\n+ for my $pattern (@matches)\n+ {\n+ $outFile =~ s/${noPreESC}${BEGIN_DELIM}${ix}${END_DELIM}/$pattern/g;\n+ ++ $ix;\n+ }\n+ $outFile =~ s/${BEGIN_DELIM}${BEGIN_DELIM}/${BEGIN_DELIM}/g;\n+ $outFile =~ s/${END_DELIM}${END_DELIM}/${END_DELIM}/g;\n+ $outFile =~ s/${HASH_ESC}/#/g;\n+ $outFile =~ s/${STAR_ESC}/*/g;\n```\n\nThe replacement is a sequence of `s///g` calls. It runs no user-supplied bytes through any interpreter. It distinguishes content from command by reserving two byte values (`\\xFF`, `\\xFE`) as placeholder delimiters and rewriting any user-supplied occurrence of those bytes to a doubled form on the way in and back on the way out. The substitution is bounded, finite, and deterministic.\n\nThis is the structural reason. `eval STRING` was always the wrong primitive for this job. The template language is `#N` and `*`. The template engine needed three things. Find `#N`, find `*`, substitute. Perl's `s///g` does each of those in one line. The original implementation reached for `eval` because `eval` is the tool Perl developers think of first when they want string interpolation, and the developer was using interpolation (`${1}`, `${inFile}`) as the substitution mechanism. Picking the dynamic interpreter for a two-token grammar made every other byte in the template a potential Perl statement. The 2026 patch finally implements the grammar as a grammar.\n\nThis is the close cousin of [Flowise's `convertToValidJSONString`](/posts/flowise-converttovalidjsonstring-is-eval), where `Function('return ' + inputString)()` ran the entire JavaScript runtime to relax a JSON spec, and the fix replaced it with `JSON5.parse`. Same shape, different language. It is the same shape as [protobufjs's type-name codegen](/posts/protobufjs-cve-2026-41242-type-name-was-javascript), where the codegen library's only unescaped slot turned a descriptor name into a `Function(source)()` body, and the fix was a regex that stripped non-identifier characters. The shape is `content-is-command` narrowed to the specific subset where the developer reaches for the host language's `eval` (or `Function`, or `class_eval`, or `exec`) to implement a finite-grammar template. The eval is the engine. The engine accepts the full host language. The template never asked for that.\n\n## The patch added eight tests. None of them assert the eval cannot run.\n\n`t/globmapper.t` grew from 68 tests to 76 in the same commit. The two new test blocks are titled `\"check escaping\"` and `\"check backslash escaping\"`. They verify that the `\\xFF` and `\\xFE` delimiter bytes pass through the round trip without corruption, and that backslash-escaped `#` and `*` appear in the output as literal `#` and `*`. They are functional tests for the new substitution mechanism.\n\nNeither test asserts that an output glob containing a literal `\"` produces a literal `\"` in the output. Neither test asserts that an output glob containing `system(\"id\")` does not execute `system(\"id\")`. Neither test asserts anything about Perl source not being evaluated.\n\nThe commit message is `\"remove use of eval in globmapper. #73\"`. A future contributor reading the diff sees a refactor and two tests about a placeholder mechanism. The reason the commit removes the eval is not in the diff. CVE-2026-48962 is the only artifact that names what `eval STRING` was doing in `_getFiles` for twenty years and nine months.\n\nPoC: [Stig Palmquist, oss-security 2026/q2/709](https://seclists.org/oss-sec/2026/q2/709).","closing_line":"The eval ran for twenty years. The grammar it interpreted fits in three calls to `s///g`.","hook_md":"`File::GlobMapper::_getFiles` runs `eval \"\\$outFile = $self->{OutputPattern};\"`. `$self->{OutputPattern}` is the caller's output-glob string, wrapped in literal double quotes by `_parseOutputGlob`. A literal `\"` anywhere in the output glob closes the wrapper. Whatever follows is parsed by Perl. The eval was committed on August 22, 2005, in the initial CPAN import of IO::Compress 2.000_00. It was removed on May 16, 2026, in the patch the CPAN Security Group later filed as CVE-2026-48962.\n\nThe template language has two metacharacters. The template engine was the Perl interpreter.","post_id":508,"slug":"io-compress-cve-2026-48962-output-glob-was-eval-string","title":"CVE-2026-48962: IO::Compress's Filename Template Was eval STRING","type":"initial","unreadable_sentence":"The template language has two metacharacters. The template engine was the Perl interpreter."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaoSWVwAKCRDeZjl4jgkQ JrUkAP9dfPbYhoSSD86AvcSWBVPw4//SCfkb0JiTkI5nXb58wgD/ZyQvogG3pwJA oonUf/J1qKDjvSSUV31r7j7Clf4WAAw= =22W6 -----END PGP SIGNATURE-----