在列表上下文中调用 CGI::param 和未定义子例程 &CGI::Plus::randword 调用错误

Ahm*_*dar 2 perl cgi

我正在尝试对 Perl 中的 Web 应用程序进行 dockerize,最后它通过 Apache 与 MariaDB 连接。我已经有一个数据库设置。我的容器正在运行,但问题出在 perl 脚本上;他们没有跑步。另外,一个名为 CGI PLUS 的模块在安装时出现问题。有人可以看看下面的文字,让我知道这里可能存在什么问题,并分享解决方案来纠正它吗?

################################################################
#Perl modules
Install the required Perl modules.

cpan CGI
cpan CGI::Plus
cpan CGI::Session
cpan DBI
cpan Crypt::Eksblowfish::Bcrypt
cpan File::Basename
cpan Auth::Yubikey_WebClient
cpan Tie::IxHash
cpan Apache::Solr
cpan HTML::Entities
cpan WWW::CSRF
cpan Crypt::Random
cpan LWP::Simple
cpan Text::NSP::Measures::2D::Fisher::twotailed
cpan XML::Simple
cpan Statistics::R
cpan Cache::FileCache
cpan Digest::MD5
cpan Date::Calc
cpan Data::Dumper
cpan Text::ParseWords
cpan Cwd
cpan Log::Log4perl
#Tests of the module XML:DOM::XPath fail because they use a deprecated syntax but the module is OK
# Install with the following command
perl -MCPAN -e "CPAN::Shell->notest('install', 'XML::DOM::XPath')";
cpan Bio::DB::Fasta
cpan Log::Dispatch::File

################################################################
# Apache

Set up an Apache server with ssl enabled.
Enable the following modules
enable session
session_cookie
rewrite
RewriteEngine
ssl

Generate a dummy certificate only for a test server.
Call the script /usr/bin/gensslcert.

Add the following lines to vhost-ssl.conf
Header always set X-Content-Type-Options "nosniff"
Header always set X-Xss-Protection "1; mode=block"
Header always set X-Frame-Options "SAMEORIGIN"
Header set Content-Security-Policy "default-src https: 'unsafe-eval' 'u
Run Code Online (Sandbox Code Playgroud)

以下是尝试安装 CGI PLUS 后生成的错误日志。

5.066 CGI::param called in list context from t/test.t line 96, this can lead to vulnerabilities. See the warning in "Fetching the value or values of a single named parameter" at /usr/local/lib/perl5/site_perl/5.38.0/CGI.pm line 415. 
5.066 Undefined subroutine &CGI::Plus::randword called at /root/.cpan/build/CGI-Plus-0.15-0/blib/lib/CGI/Plus.pm line 644. 
5.066 # Looks like your test exited with 255 just after 4. 5.068 t/test.t ..
5.068 Dubious, test returned 255 (wstat 65280, 0xff00) 5.068 Failed
33/37 subtests
Run Code Online (Sandbox Code Playgroud)

如果您需要任何进一步的信息来了解完整的场景,也请告诉我。以下是我的 docker 文件,显示我如何尝试运行 perl 脚本。你能发现其中有什么问题或问题吗?

# Use the latest Perl image as the base
FROM perl:latest

# Install system dependencies
RUN apt-get update && apt-get install -y \
    apache2 \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*


#Install the required Perl modules
RUN cpan CGI
RUN cpan App::cpanminus
RUN cpan CPAN::DistnameInfo

#Install libcgi-pm-perl using apt-get
RUN apt-get update && apt-get install -y libcgi-pm-perl


#Install the required Perl modules
RUN cpan CGI::Safe
RUN cpan String::Util

#RUN cpan CGI::Plus
RUN cpan -T CGI::Plus


RUN cpan CGI::Session
RUN cpan DBI
RUN cpan Crypt::Eksblowfish::Bcrypt
RUN cpan File::Basename
RUN cpan Auth::Yubikey_WebClient
RUN cpan Tie::IxHash
RUN cpan Apache::Solr
RUN cpan HTML::Entities
RUN cpan WWW::CSRF
RUN cpan Crypt::Random
RUN cpan LWP::Simple
RUN cpan Text::NSP::Measures::2D::Fisher::twotailed
RUN cpan XML::Simple
RUN apt-get update && apt-get install -y r-base
RUN cpan Statistics::R
RUN cpan Cache::FileCache
RUN cpan Digest::MD5
RUN cpan Date::Calc
RUN cpan Data::Dumper
RUN cpan Text::ParseWords
RUN cpan Cwd
RUN cpan Log::Log4perl

# Install XML::DOM::XPath without testing
RUN perl -MCPAN -e "CPAN::Shell->notest('install', 'XML::DOM::XPath')"

# Install Bio::DB::Fasta
RUN cpan Bio::DB::Fasta

#Install Log::Dispatch::File
RUN cpan Log::Dispatch::File

# Copy your Perl web application files to the Apache document root
COPY ./cgi-bin /var/www/html/cgi-bin
COPY ./css_js /var/www/html/css_js

#COPY ./cgi-bin /srv/www/cgi-bin/mysql/.
#COPY  ./srv/www/htdocs/cal /srv/www/htdocs/cal
#COPY ./srv/www/htdocs/DataTables-1.10.22/ srv/www/htdocs/DataTables-1.10.22
#COPY ./cal/img  /srv/www/htdocs/gif

# Copy your custom virtual host configuration into the container
#COPY custom-vhost.conf /etc/apache2/sites-available/

# Set permissions for Apache user (www-data) to access the application files
#RUN chown -R www-data:www-data /var/www/html/

#Enable your custom virtual host:
#RUN a2ensite custom-vhost

# Enable CGI execution and set the handler for .cgi and .pl files
RUN sed -i 's/Options Indexes FollowSymLinks/Options Indexes FollowSymLinks ExecCGI/' /etc/apache2/apache2.conf
RUN echo 'AddHandler cgi-script .cgi .pl' >> /etc/apache2/apache2.conf

#Enable perl files 
#RUN a2enmod cgid

# Set the executable permission on Perl scripts
#RUN chmod +x /var/www/html/cgi-bin/*.pl

# Set the executable permission on Perl scripts in the cgi-bin directory and its subdirectories
RUN find /var/www/html/cgi-bin -type f -name "*.pl" -exec chmod +x {} \;

# Expose port 80 for Apache
EXPOSE 80

# Start Apache web server
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

# Make all .pl files executable in the cgi-bin directory and its subdirectories
#RUN find /srv/www/cgi-bin/mysql/. -type f -name "*.pl" -exec chmod +x {} \;
Run Code Online (Sandbox Code Playgroud)

当我运行 .pl 脚本时,它给出如下内容:

# perl admin.pl
Status: 500
Content-type: text/html

<h1>Software error:</h1>
<pre>Undefined subroutine &CGI::Plus::randword called at
/usr/local/lib/perl5/site_perl/5.38.0/CGI/Plus.pm line 644.
</pre>
<p>
For help, please send mail to this site's webmaster, giving this error message
and the time and date of the error.

</p>
[Wed Sep 13 16:14:24 2023] admin.pl: Undefined subroutine
&CGI::Plus::randword called at
/usr/local/lib/perl5/site_perl/5.38.0/CGI/Plus.pm line 644.
Run Code Online (Sandbox Code Playgroud)

Que*_*tin 6

查看源代码,您可以看到它确实尝试使用randword它自己未定义的子组件。

\n

向上滚动到顶部,它是一个子项,其名称听起来像是use String::Util \':all\';可能需要提供的东西。

\n

该模块的源代码randword中没有任何迹象,因此让我们看一下变更日志

\n
\n

1.33 2023-01-31

\n
    \n
  • 删除一堆旧的已弃用函数:crunch、cellfill、define、randword、fulchomp、randcrypt、equndef、neundef
  • \n
\n
\n

回到 CGI::Plus,查看它的安装程序

\n
\n
\'String::Util\' => \'1.24\'\n
Run Code Online (Sandbox Code Playgroud)\n
\n

因此它声明它需要 String::Util 1.24 或更高版本,但这是错误的,因为它需要低于1.33的版本。

\n
\n

你可以:

\n
    \n
  • 将 CGI::Plus 本地修补到以下任一位置:\n
      \n
    • 更正 Build.PL 中的错误
    • \n
    • 将调用替换randword为其他内容
    • \n
    \n
  • \n
  • 向作者提交一份错误报告并要求他们修复它(尽管我不会抱太大希望,因为该模块已经近十年没有更新了,而且这个错误已经存在了半年多了) \xe2\x80\xa6 哦等等,7 个月前有人这样做了,但已被忽略
  • \n
  • 将 CGI::Plus 替换为其他内容(考虑到缺乏持续支持,这可能是明智之举(看起来作者自 2016 年以来一直在 CPAN 上不活跃))。
  • \n
\n