Skip to content

fix: code injection vulnerability in digest-bench#5

Draft
toddr-bot wants to merge 22 commits into
gisle:masterfrom
Dual-Life:koan.toddr.bot/fix-digest-bench-injection
Draft

fix: code injection vulnerability in digest-bench#5
toddr-bot wants to merge 22 commits into
gisle:masterfrom
Dual-Life:koan.toddr.bot/fix-digest-bench-injection

Conversation

@toddr-bot
Copy link
Copy Markdown

Summary

SECURITYdigest-bench uses eval "require $mod" which allows arbitrary Perl code execution when the module name argument is attacker-controlled. This may warrant a vulnerability report.

  • Replace eval "require $mod" with safe bare require (convert :: to /, same pattern as Digest.pm)
  • Declare my $a instead of clobbering the special $a sort variable

Why

Line 8 of digest-bench used eval "require $mod" where $mod comes directly from @ARGV. An attacker (or careless user) could pass "Digest::MD5; system('rm -rf /')" and the injected code would execute inside the eval. The safe pattern used in Digest.pm itself (lines 42-47) converts :: to / and uses bare require, which only loads files and cannot execute arbitrary code.

How

Two-commit approach per security flagging conventions:

  1. First commit adds a PoC test that creates a canary file via injection — proves the vulnerability is real
  2. Second commit applies the fix — the test then passes

Testing

  • PoC test confirms injection no longer works (canary file is not created)
  • digest-bench Digest::MD5 still produces correct benchmark output
  • Full test suite passes: 4 files, 24 tests, all green

🤖 Generated with Claude Code

toddr and others added 22 commits October 6, 2020 09:56
- meta-spec 2 resources format
- dependencies are static, set dynamic_config 0
- EUMM will set configure_requires on itself
- Test::More only used in tests
- boilerplate to clean out unsupported keys if installed with old EUMM
Makefile.PL - use meta-spec 2, fix prereqs, compatibility with old EUMM
base.t, file.t: unlink temporary files created during testing
eval "require $mod" allows arbitrary Perl execution when the module
name is attacker-controlled. This test proves it by injecting code
that creates a canary file after a valid require statement.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The eval-based require allowed arbitrary code execution when the module
name argument contained injected Perl code (e.g., "Digest::MD5; system(...)").

Replace with the same safe pattern used in Digest.pm: convert :: to /
in the module name and use bare require, which only loads files.

Also declare $a with my to avoid clobbering the special sort variable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants