简体   繁体   English

使用Perl CGI重定向时如何屏蔽url参数

[英]How to mask url parameters when using perl cgi redirect

I have authenticate.cgi script which receives username/password and validates them. 我有authenticate.cgi脚本,该脚本接收用户名/密码并对其进行验证。

If its a valid login, i redirect the page to myIndex.cgi by sending some parameters like start-date/username etc where a report is shown to the user. 如果它是有效的登录名,我可以通过发送一些参数(例如向用户显示报告的开始日期/用户名等)将页面重定向到myIndex.cgi。

If its a invalid login, i redirect to the previous page so username/password can be re-entered. 如果登录无效,我将重定向到上一页,以便可以重新输入用户名/密码。

when i redirect to myIndex.cgi, the url shows all the parameters in url bar. 当我重定向到myIndex.cgi时,URL在URL栏中显示所有参数。 Is there a way to mask them so the parameters and their values are not shown in the url. 有没有一种方法可以屏蔽它们,因此参数及其值不会显示在url中。

is there a way to do it? 有办法吗? Please let me know. 请告诉我。 thanks. 谢谢。

authenticate.cgi authenticate.cgi

#Redirect to login if invalid username/password or redirect to report page
if ( ( $username eq '' ) ||  ( $password eq '' ) )
{
        #print "not defined\n";
        $referrer = $ENV{HTTP_REFERER};
        print $query->redirect($referrer);
}
else
{
        $retStatus=verifyLogin($username,$password);
        my $myUser = $username;

        #Redirect to the caller
        if($retStatus eq "98")
        {

                $referrer = "http://projects.pjkeary.net/inspections_done_report/myIndex.cgi?start=2014-10-01&end=2014-10-31&exclude_dt=1&myUser=$myUser";
        }
        else
        {
                $referrer = $ENV{HTTP_REFERER};
        }
        print $query->redirect($referrer);
}
$referrer = $ENV{HTTP_REFERER};
print $query->redirect($referrer);

As already noted - you can't really do this with a POST at the same time as redirecting. 如前所述-您实际上无法在重定向的同时使用POST进行此操作。 But neither can you do it with a get, because that exposes auth credentials to anyone watching. 但是您也无法通过get来做到这一点,因为这会将auth凭据公开给任何观看者。 (As noted below - just because it's POSTed doesn't make it in any way hidden - it's still sent in the clear, and trivially easy to intercept. It just doesn't appear as obviously in history or proxy logs) (如下所述-只是因为它的POST并没有使其以任何方式被隐藏-它仍然以明文形式发送,并且容易被拦截。它只是在历史记录或代理日志中并不明显)

You could perhaps embed the credentials in a cookie, but especially cross-site cookie passing is potentially unpleasant. 您也许可以将凭据嵌入cookie中,但是特别是跨站点cookie传递可能会令人不快。

So what I would suggest is take a leaf from Kerberos' book. 因此,我建议您从Kerberos的书中学习。 What Kerberos does is enable trusted third party authentication, by passing around encrypted and time limited tokens. Kerberos所做的是通过传递加密的和时间有限的令牌来启用受信任的第三方身份验证。 http://en.wikipedia.org/wiki/Kerberos_%28protocol%29 http://en.wikipedia.org/wiki/Kerberos_%28protocol%29

So algorithmically you could: 因此,从算法上讲,您可以:

  • Create a public-private key pair. 创建一个公私钥对。
  • put the public key on the 'authenticator' server. 将公钥放在“身份验证器”服务器上。
  • put the private key on the 'destination' server. 将私钥放在“目标”服务器上。
  • When someone authenticates successfully, generate a token that includes: 当某人成功进行身份验证时,生成包含以下内容的令牌:
    • timestamp 时间戳
    • source ip 源IP
    • username 用户名
    • sequence number or serial number (if you want to avoid re-use) 序列号或序列号(如果要避免重复使用)
  • Encrypt the token using the public key. 使用公共密钥加密令牌。
  • Base 64 encode it, and pass it to the client as a parameter in the URL. Base 64对它进行编码,并将其作为URL中的参数传递给客户端。

The destination server can trust the token, because it can decrypt it, and it's got enough information (time and source IP) to make it non trivial to steal and reuse the encryption token. 目标服务器可以信任令牌,因为它可以解密令牌,并且它具有足够的信息(时间和源IP),因此窃取和重用加密令牌非常重要。 And it then 'knows' that the user accessing is valid, and authenticated. 然后,它“知道”用户访问是有效的,并且已通过身份验证。

You could extend the 'token' to include any sensitive parameters you want to pass, and leave any you're happy to send in the clear. 您可以扩展“令牌”以包括要传递的所有敏感参数,并保留所有您希望以明文形式发送的参数。

Perl modules probably exist to do this, but I'm not familiar enough with them so instead: Perl模块可能已经存在,但是我对它们还不够熟悉,所以:

openssl genrsa -out openssl_gen_rsa
openssl rsa -in openssl_gen_rsa -pubout -out openssl_gen_rsa.out 

Then take a 'plain text' file and encrypt it with the public key: 然后获取一个“纯文本”文件,并使用公共密钥对其进行加密:

openssl rsautl -inkey openssl_gen_rsa.out -pubin -in test_file.txt -encrypt -out test_file.openssl.pub.enc

Base 64 encode it. Base 64对其进行编码。 (There's a base64 command on Linux, but Perl does built in stuff). (在Linux上有一个base64命令,但是Perl确实内置了东西)。

Then you decrypt using the private key: 然后使用私钥解密:

openssl rsautl -inkey openssl_gen_rsa -in test_file.openssl.pub.enc -decrypt

Perl definitely has built in modules to do this though. Perl确实内置了模块来执行此操作。

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

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