Harden module loading#57
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens Net::OpenSSH::ModuleLoader by preventing unsafe module loading patterns and aligning module version enforcement with standard Perl semantics, plus adds regression coverage to ensure these behaviors remain correct.
Changes:
- Validate module names before attempting to load them.
- Replace string
eval "require ..."with a non-stringrequireof the computed module path. - Use
$module->VERSION($version)for version requirements and add a new regression test (and manifest entry).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/Net/OpenSSH/ModuleLoader.pm | Adds module-name validation, switches to path-based require, and uses standard VERSION checking. |
| t/module-loader.t | Adds regression tests for unsafe module names and version requirement behavior. |
| MANIFEST | Adds the new test file to the distribution manifest. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| package Test::Net::OpenSSH::ModuleLoader::Versioned; | ||
| our $VERSION = '1.02'; | ||
| } |
There was a problem hiding this comment.
This concern does not hold for the test as written. The package Test::Net::OpenSSH::ModuleLoader::Versioned; declaration is inside a bare block, and the later unqualified ok/like calls continue to resolve correctly. The test passes after the new undef-name coverage:\n\nperl -Ilib t/module-loader.t\n\nResult: 1..6 and all assertions pass.
| my ($module, $version) = @_; | ||
| $module =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/ | ||
| or croak "bad Perl module name $module"; |
There was a problem hiding this comment.
Fixed in commit 4e504a6 by handling undefined module names before applying the regex, with a regression assertion in t/module-loader.t.
Summary
Harden
Net::OpenSSH::ModuleLoadermodule loading and version checks.Changes
eval "require ..."with non-stringrequireon a module path.$module->VERSION($version)semantics for version requirements.MANIFEST.Fixes #45.
Fixes #46.
Testing
perl -Ilib -c lib/Net/OpenSSH/ModuleLoader.pmperl -Ilib t/module-loader.t