Skip to content

Commit

Permalink
Item11410: Implement USERINFOisTooRestrictive fix
Browse files Browse the repository at this point in the history
USERINFO macro can reveal Wikiname,  and also whether or not the user is
a group.

git-svn-id: http://svn.foswiki.org/trunk@13561 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Jan 8, 2012
1 parent 2ea1c25 commit 8fac51b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
52 changes: 52 additions & 0 deletions UnitTestContrib/test/unit/Fn_USERINFO.pm
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,58 @@ HERE
return;
}

sub test_antispam {
my $this = shift;
my $testformat =
'W$wikiusernameU$wikinameN$usernameE$emailsG$groupsA$adminIA$isadminIG$isgroupE$bogustoken nop$nopnop $percent $quot $comma$n$n()ewline $lt $gt $amp $dollar';

$Foswiki::cfg{AntiSpam}{HideUserDetails} = 1;

# ScumBag should only see his own information
$this->createNewFoswikiSession( "ScumBag" );
my $ui = $this->{test_topicObject}->expandMacros(<<"HERE");
%USERINFO{"ScumBag" format="$testformat"}%
HERE
$this->assert_str_equals( <<"HERE", $ui );
W$Foswiki::cfg{UsersWebName}.ScumBagUScumBagNscumEscumbag\@example.comGFriendsOfFriendsOfGropeGroup, FriendsOfGropeGroup, GropeGroupAfalseIAfalseIGfalseE\$bogustoken nopnop % " ,
ewline < > & \$
HERE

my $guest_ui = $this->{test_topicObject}->expandMacros(<<"HERE");
%USERINFO{"WikiGuest" format="$testformat"}%
HERE

#'W$wikiusernameU$wikinameN$usernameE$emailsG$groupsA$adminIA$isadminIG$isgroupE$bogustoken nop$nopnop $percent $quot $comma$n$n()ewline $lt $gt $amp $dollar';
$this->assert_str_equals( <<"HERE", $guest_ui );
W$Foswiki::cfg{UsersWebName}.WikiGuestUWikiGuestNEGAIAIGfalseE\$bogustoken nopnop % " ,
ewline < > & \$
HERE

# Admin user should see everything
$this->createNewFoswikiSession( $Foswiki::cfg{AdminUserLogin} );
$ui = $this->{test_topicObject}->expandMacros(<<"HERE");
%USERINFO{"ScumBag" format="$testformat"}%
HERE
$this->assert_str_equals( <<"HERE", $ui );
W$Foswiki::cfg{UsersWebName}.ScumBagUScumBagNscumEscumbag\@example.comGFriendsOfFriendsOfGropeGroup, FriendsOfGropeGroup, GropeGroupAfalseIAfalseIGfalseE\$bogustoken nopnop % " ,
ewline < > & \$
HERE

$guest_ui = $this->{test_topicObject}->expandMacros(<<"HERE");
%USERINFO{"WikiGuest" format="$testformat"}%
HERE
$this->assert_str_equals( <<"HERE", $guest_ui );
W$Foswiki::cfg{UsersWebName}.WikiGuestUWikiGuestNguestEGBaseGroup, FriendsOfFriendsOfGropeGroup, FriendsOfGropeGroup, GropeGroupAfalseIAfalseIGfalseE\$bogustoken nopnop % " ,
ewline < > & \$
HERE

return;
}

sub test_isgroup {
my $this = shift;
my $testformat =
Expand Down
21 changes: 16 additions & 5 deletions core/lib/Foswiki/Macros/USERINFO.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ use strict;
use warnings;
use Assert;

# Set to true if user details should be cloaked. Selected tokens will return an empty string.
my $USERINFO_cloak = 0;

my %USERINFO_tokens = (
username => sub {
my ( $this, $user ) = @_;
my $username = $this->{users}->getLoginName($user);
return '' if ($USERINFO_cloak);

my $username = $this->{users}->getLoginName($user);
$username = 'unknown' unless defined $username;

return $username;
Expand All @@ -19,6 +23,7 @@ my %USERINFO_tokens = (
cUID => sub {
my ( $this, $user ) = @_;

return '' if ($USERINFO_cloak);
return $user;
},
wikiname => sub {
Expand All @@ -41,11 +46,14 @@ my %USERINFO_tokens = (
emails => sub {
my ( $this, $user ) = @_;

return '' if ($USERINFO_cloak);
return join( ', ', $this->{users}->getEmails($user) );
},
groups => sub {
my ( $this, $user ) = @_;
my @groupNames;
return '' if ($USERINFO_cloak);

my $it = $this->{users}->eachMembership($user);

while ( $it->hasNext() ) {
Expand All @@ -60,13 +68,15 @@ my %USERINFO_tokens = (
admin => sub {
my ( $this, $user ) = @_;

return '' if ($USERINFO_cloak);
return $this->{users}->isAdmin($user) ? 'true' : 'false';
},

# Item2466: $isadmin & $isgroup added November 2011
isadmin => sub {
my ( $this, $user ) = @_;

return '' if ($USERINFO_cloak);
return $this->{users}->isAdmin($user) ? 'true' : 'false';
},
isgroup => sub {
Expand Down Expand Up @@ -100,10 +110,11 @@ sub USERINFO {
$user = $cuid;
}
return '' unless $user;
return ''
if ( $Foswiki::cfg{AntiSpam}{HideUserDetails}
&& !$this->{users}->isAdmin( $this->{user} )
&& $user ne $this->{user} );

$USERINFO_cloak =
( $Foswiki::cfg{AntiSpam}{HideUserDetails}
&& !$this->{users}->isAdmin( $this->{user} )
&& $user ne $this->{user} );
}

return '' unless $user;
Expand Down

0 comments on commit 8fac51b

Please sign in to comment.