and here is auth.pl:#I've not posted use directives, HTML::Template variables declarations + and et ceterea, because it doesn't actually matter in this case. if (!$cookie{CGISESSID}{value}[0]) { #checkif there is a session cooki +e in user's browser. print "Content-Type: text/html\n\n"; print $auth->output; # render form which would require enter login + and password. } else { # render secret page
It actually works, but one issue is worrying me: the cookie named CGISESSID (which is session cookie) is checked just for is's existence, so theoretically one can open cookie file and write some random symbols to the CGISESSID's value - and script will actually render secret page! How to avoid this situation?#!/usr/bin/perl use CGI; use HTML::Template; use CGI::Cookie; use strict; use CGI::Session; use lib ('../'); use MySite; my $q = new CGI; my %params = MySite::get_params($q); my $login = "vu"; my $password = "Stella744"; my $t = HTML::Template->new(filename => '../templates/auth_success.tmp +l'); my $t_err = HTML::Template->new(filename => '../templates/Auth_error.t +mpl'); if ($ENV{REQUEST_METHOD} ne 'POST') { print "Content-type: text/html\n\n"; print "Sorry. Don't do this."; } else { if (($params{login} eq $login) and ($params{password} eq $pass +word)) { my $session = CGI::Session->new() or die CGI::Session->err +str; my $cookie = $q->cookie( -name => $session->name, -value = +> $session->id ); #print "Set-Cookie: $cookie\n"; print $session->header(-charset => 'utf-8'); print "Content-type: text/html\n\n", $t->output; } else { print "Content-type: text/html\n\n", $t_err->output; } }
In reply to CGI::Session and simple authentication by Kyshtynbai
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |