Kyshtynbai has asked for the wisdom of the Perl Monks concerning the following question:
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; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI::Session and simple authentication
by thomas895 (Deacon) on Jun 03, 2014 at 04:50 UTC | |
by Kyshtynbai (Sexton) on Jun 03, 2014 at 08:32 UTC | |
|
Re: CGI::Session and simple authentication
by taint (Chaplain) on Jun 03, 2014 at 06:17 UTC | |
by Kyshtynbai (Sexton) on Jun 03, 2014 at 08:35 UTC | |
by taint (Chaplain) on Jun 03, 2014 at 09:08 UTC | |
by Kyshtynbai (Sexton) on Jun 03, 2014 at 10:15 UTC |