简体   繁体   English

Perl CGI从不同的请求获取参数到当前URL

[英]Perl CGI gets parameters from a different request to the current URL

This is a weird one. 这很奇怪。 :) :)

I have a script running under Apache 1.3, with Apache::PerlRun option of mod_perl. 我有一个在Apache 1.3下运行的脚本,其中包含mod_perl的Apache :: PerlRun选项。 It uses the standard CGI.pm module. 它使用标准的CGI.pm模块。 It's a regularly accessed script on a busy server, accessed over https. 它是繁忙服务器上的定期访问脚本,可通过https访问。

The URL is typically something like... URL通常类似于......

/script.pl?action=edit&id=47049 /script.pl?action=edit&id=47049

Which is then brought into Perl the usual way... 然后以通常的方式将其带入Perl ......

my $action = $cgi->param("action");
my $id = $cgi->param("id");

This has been working successfully for a couple of years. 这已成功运作了几年。 However we started getting support requests this week from our customers who were accessing this script and getting blank pages. 但是,我们本周开始从访问此脚本并获取空白页面的客户那里获得支持请求。 We already had a line like the following that put the current URL into a form we use for customers to report an issue about a page... 我们已经有了如下所示的行,将当前的URL放入我们用于客户报告页面问题的表单中...

$cgi->url(-query => 1);

And when we view source of the page, the result of that command is the same URL, but with an entirely different query string. 当我们查看页面的源时,该命令的结果是相同的URL,但具有完全不同的查询字符串。

/script.pl?action=login&user=foo&password=bar /script.pl?action=login&user=foo&password=bar

A query string that we recognise as being from a totally different script elsewhere on our system. 我们认为是来自我们系统其他地方完全不同的脚本的查询字符串。

However crazy it sounds, it seems that when users are accessing a URL with a query string, the query string that the script is seeing is one from a previous request on another script. 听起来很疯狂,似乎当用户使用查询字符串访问URL时,脚本看到的查询字符串是来自另一个脚本上的先前请求的字符串。 Of course the script can't handle that action and outputs nothing. 当然,脚本无法处理该操作并且不输出任何内容。

We have some automated test scripts running to see how often this happens, and it's not every time. 我们运行了一些自动化测试脚本,以查看这种情况发生的频率,而且并非每次都如此。 To throw some extra confusion into the mix, after an Apache restart, the problem seems to initially disappear completely only to come back later. 为了给混合增加一些额外的困惑,在Apache重新启动之后,问题似乎最初完全消失,但后来又回来了。 So whatever is causing it is somehow relieved by a restart, but we can't see how Apache can possibly take the request from one user and mix it up with another. 因此无论如何导致它都会因重启而以某种方式解除,但我们无法看到Apache如何从一个用户那里获取请求并将其与另一个用户混合。

This, it appears, is an interesting combination of Apache 1.3, mod_perl 1.31, CGI.pm and Apache::GTopLimit. 看起来,它是Apache 1.3,mod_perl 1.31,CGI.pm和Apache :: GTopLimit的有趣组合。

A bug was logged against CGI.pm in May last year: RT #57184 去年5月针对CGI.pm记录了一个错误: RT#57184

Which also references CGI.pm params not being cleared? 哪个也引用CGI.pm params没被清除?

CGI.pm registers a cleanup handler in order to cleanup all of it's cache.... (line 360) CGI.pm注册一个清理处理程序,以清理它的所有缓存....(第360行)

$r->register_cleanup(\&CGI::_reset_globals);

Apache::GTopLimit (like Apache::SizeLimit mentioned in the bug report) also has a handler like this: Apache::GTopLimit (如bug报告中提到的Apache::SizeLimit )也有一个这样的处理程序:

$r->post_connection(\&exit_if_too_big) if $r->is_main;

In pre mod_perl 1.31, post_connection and register_cleanup appears to push onto the stack, while in 1.31 it appears as if the GTopLimit one clobbers the CGI.pm entry. 在pre mod_perl 1.31中,post_connection和register_cleanup似乎会推入堆栈,而在1.31中,似乎GTopLimit破坏CGI.pm条目。 So if your GTopLimit function fires because the Apache process has got to large, then CGI.pm won't be cleaned up, leaving it open to returning the same parameters the next time you use it. 因此,如果您的GTopLimit函数因为Apache进程变大而触发,那么CGI.pm将不会被清除,而是在下次使用时返回相同的参数。

The solution seems to be to change line 360 of CGI.pm to; 解决方案似乎是将CGI.pm的第360行更改为;

$r->push_handlers( 'PerlCleanupHandler', \&CGI::_reset_globals);

Which explicitly pushes the handler onto the list. 其中明确地将处理程序推送到列表中。

Our restart of Apache temporarily resolved the problem because it reduced the size of all the processes and gave GTopLimit no reason to fire. 我们重新启动Apache暂时解决了这个问题,因为它减少了所有进程的大小,并且没有理由让GTopLimit解雇。

And we assume it has appeared over the past few weeks because we have increased the size of the Apache process either through new developments which included something that wasn't before. 我们假设它在过去几周出现了,因为我们通过新的开发增加了Apache进程的大小,其中包括以前没有的东西。

All tests so far point to this being the issue, so fingers crossed it is! 到目前为止,所有的测试都指出这是问题,所以手指越过它!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM