Thread Häufige Weiterleitung bei Logout und CGI::Session (11 answers)
Opened by Max_Perlbeginner at 2016-10-21 20:34

Max_Perlbeginner
 2016-10-21 20:34
#185518 #185518
User since
2016-04-04
107 Artikel
BenutzerIn
[default_avatar]
Liebe Perlgemeinde,
Ich habe ein Problem mit dem Logout bei CGI::Session im tainted Modus. Der Browser (Chromium) zeigt mir folgenden Error an:
Quote
Die Seite localhost funktioniert nicht
localhost hat Sie zu oft weitergeleitet.
Löschen Sie Ihre Cookies.
ERR_TOO_MANY_REDIRECTS


Komischerweise funktioniert der Logout problemlos, wenn ich das Tainting deaktiviert habe. Wenn in der Shebang Zeile jedoch wie empfohlen #! /usr/bin/perl -wT steht, klappt ein erneuter Login erst wieder nach Löschen der Cookies.

Hier die relevanten Code Teile:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
######################
# SESSION MANAGEMENT
# create the session or if avaible load the session
#######################
my $q = CGI->new();
my $session = CGI::Session->new("driver:File", $q, {Directory => "$tmp_dir"});
$session->expire('15m');

if ($session->is_new ) {
my $cookie = $q->cookie(CGISESSID => $session->id);
print $q->redirect( -url => 'admin.cgi', -cookie => $cookie);
}
#########################
# DISPATCH PART - GET THE ACTIONS
# if action is login, do the login
#########################
my $action = '';
$action = $q->url_param('action') if ($q->url_param('action'));

if ($action eq 'login') {
login($q, $session);
}

# Check the Login Status and if the user is logged in, start the chosen action
my $login = $session->param("login");

###############
# secret pages (only visible if logged in)
###############
if ($login) {
[...]
#hier sind die verschiedenen möglichen Aktionen, die nur nach Login zugänglich sein sollen. Wichtig ist wohl nur:
elsif ($action eq 'logout') {
logout($q, $session);
}
[...]

# Die Login Funktion
sub login {
my ($q, $session) = @_;
my $username = $q->param('user');
my $password = $q->param('password');

open my $fh, "<:encoding(utf-8)", $conffile or die "Could not open $conffile: $!";
my $yaml ='';
while (my $line = <$fh>) {$yaml .= $line}
close $fh;
my $config = Load($yaml);
$password = sha256_hex($password, $config->{'secret'});
if ($username eq $config->{'user'} and $password eq $config->{'password'}) {
$session->param("login", "can_access");
print $q->redirect(-url => 'admin.cgi?action=show_pages');
}
}
[...]
# Und schließlich die Logout Funktion
sub logout {
my ($q, $session) = @_;
# Delete the current session
$session->delete();
$session->flush();

# Delete all expired Sessions
CGI::Session->find( undef, \&purge , {Directory=> "$tmp_dir"} );
sub purge {
my ($session) = @_;
if ( $session->is_expired ) {
$session->delete();
$session->flush(); # Recommended practice says use flush() after delete().
}
}


print_template('logout.tmpl');

}


Das Logout Template ist derzeit denkbar schlicht und zeigt lediglich einen kurzen Hinweis auf den erfolgreichen Logout an und einen Link zum Anfangsskript (admin.cgi)

Hat jemand eine Idee, wo der Fehler liegen könnte?

View full thread Häufige Weiterleitung bei Logout und CGI::Session