Skip to content

Commit

Permalink
Item528: more analysis of validation and tainting issues, with many f…
Browse files Browse the repository at this point in the history
…ixes

git-svn-id: http://svn.foswiki.org/trunk@1490 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Dec 21, 2008
1 parent bea86da commit 21a9c71
Show file tree
Hide file tree
Showing 33 changed files with 345 additions and 260 deletions.
4 changes: 2 additions & 2 deletions EditTablePlugin/lib/Foswiki/Plugins/EditTablePlugin.pm
Expand Up @@ -76,14 +76,14 @@ sub initPlugin {
}

sub beforeCommonTagsHandler {
return unless $_[0] =~ /%EDIT(TABLE|CELL){(.*)}%/os;
return unless $_[0] =~ /%EDIT(TABLE|CELL){.*}%/s;
require Foswiki::Plugins::EditTablePlugin::Core;
Foswiki::Plugins::EditTablePlugin::Core::protectVariables(
$_[0] );
}

sub commonTagsHandler {
return unless $_[0] =~ /%EDIT(TABLE|CELL){(.*)}%/os;
return unless $_[0] =~ /%EDIT(TABLE|CELL){.*}%/s;

addViewModeHeadersToHead();
require Foswiki::Plugins::EditTablePlugin::Core;
Expand Down
7 changes: 2 additions & 5 deletions InterwikiPlugin/lib/Foswiki/Plugins/InterwikiPlugin.pm
Expand Up @@ -50,10 +50,10 @@ use vars qw(
%interSiteTable
);

# This should always be $Rev: 14913 (17 Sep 2007) $ so that TWiki can determine the checked-in
# This should always be $Rev$ so that TWiki can determine the checked-in
# status of the plugin. It is used by the build automation tools, so
# you should leave it alone.
$VERSION = '$Rev: 14913 (17 Sep 2007) $';
$VERSION = '$Rev$';

# This is a free-form string you can use to "name" your own plugin version.
# It is *not* used by the build automation tools, but is reported as part
Expand Down Expand Up @@ -96,9 +96,6 @@ sub initPlugin {
|| 'InterWikis';
( $interWeb, $interTopic ) =
Foswiki::Func::normalizeWebTopicName( $interWeb, $interTopic );
if( $interTopic =~ s/^(.*)\.// ) {
$interWeb = $1;
}

my $text = Foswiki::Func::readTopicText( $interWeb, $interTopic, undef, 1 );

Expand Down
1 change: 1 addition & 0 deletions PreferencesPlugin/lib/Foswiki/Plugins/PreferencesPlugin.pm
Expand Up @@ -123,6 +123,7 @@ sub beforeCommonTagsHandler {
} elsif( $action eq 'save' ) {

my( $meta, $text ) = Foswiki::Func::readTopic( $web, $topic );
# SMELL: unchecked implicit untaint of value?
$text =~ s(^((?:\t| )+\*\s(Set|Local)\s)(\w+)\s\=\s(.*)$)
($1._saveSet($query, $web, $topic, $3, $4, $formDef))mgeo;
Foswiki::Func::saveTopic( $web, $topic, $meta, $text );
Expand Down
3 changes: 3 additions & 0 deletions TopicUserMappingContrib/lib/Foswiki/Users/TopicUserMapping.pm
Expand Up @@ -378,6 +378,8 @@ sub addUser {
$web = $1 || $Foswiki::cfg{UsersWebName};
$name = $2;
$odate = $3;
# Filter-in date format dd Mmm yyyy
$odate = '' unless $odate =~ /^\d+\s+[A-Za-z]+\s+\d+$/;
$insidelist = 1;
}
elsif ( $line =~ /^\s+\*\s([A-Z]) - / ) {
Expand Down Expand Up @@ -863,6 +865,7 @@ sub mapper_getEmails {
# Now try the topic text
foreach my $l ( split( /\r?\n/, $text ) ) {
if ( $l =~ /^\s+\*\s+E-?mail:\s*(.*)$/mi ) {
# SMELL: implicit unvalidated untaint
push @addresses, split( /;/, $1 );
}
}
Expand Down
10 changes: 9 additions & 1 deletion UnitTestContrib/test/unit/RcsTests.pm
Expand Up @@ -214,8 +214,16 @@ sub verify_simple9 {
$this->checkGetRevision([ "", "\n", "\n\n", "a", "a\n", "a\n\n", "\na","\n\na", "" ]);
}

sub verify_simple10 {
# coMustCopy should only affect RcsWrap, but test them both anyway
sub verify_simple10a {
my $this = shift;
$Fowiki::cfg{RCS}{coMustCopy} = 0;
$this->checkGetRevision([ "a", "b", "a\n", "b", "a", "b\n","a\nb\n", "a\nc\n" ]);
}

sub verify_simple10b {
my $this = shift;
$Fowiki::cfg{RCS}{coMustCopy} = 1;
$this->checkGetRevision([ "a", "b", "a\n", "b", "a", "b\n","a\nb\n", "a\nc\n" ]);
}

Expand Down
39 changes: 33 additions & 6 deletions WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin.pm
Expand Up @@ -39,7 +39,7 @@ use vars qw( %TWikiCompatibility @refs );

$SHORTDESCRIPTION = 'Translator framework for Wysiwyg editors';
$NO_PREFS_IN_TOPIC = 1;
$VERSION = '$Rev: 15843 $';
$VERSION = '$Rev$';

$RELEASE = '03 Aug 2008';

Expand Down Expand Up @@ -732,14 +732,29 @@ sub _restHTML2TML {
return undef; # to prevent further processing
}

# SMELL: foswiki supports proper REST usage of the upload script,
# so debatable if this is required any more
sub _restUpload {
my ($session, $plugin, $verb, $response) = @_;
my $query = Foswiki::Func::getCgiQuery();
my $topic = $query->param('topic');
$topic =~ /^(.*)\.([^.]*)$/;
my $web = $1;
$topic = $2;

my ($web, $topic) = Foswiki::Func::normalizeWebTopicName( undef,
$query->param('topic'));
$web = Foswiki::Sandbox::untaint(
$web,
sub {
return $web if Foswiki::Func::isValidWebName($web, 1);
return undef;
});
$topic = Foswiki::Sandbox::untaint(
$topic,
sub {
return $topic if Foswiki::Func::isValidTopicName($topic, 1);
return undef;
});
unless (defined $web && defined $topic) {
returnRESTResult($response, 401, "Access denied");
return undef; # to prevent further processing
}
my $hideFile = $query->param('hidefile') || '';
my $fileComment = $query->param('filecomment') || '';
my $createLink = $query->param('createlink') || '';
Expand Down Expand Up @@ -838,6 +853,18 @@ sub _restAttachments {
my ($session, $plugin, $verb, $response) = @_;
my ($web, $topic) = Foswiki::Func::normalizeWebTopicName(
undef, Foswiki::Func::getCgiQuery()->param('topic'));
$web = Foswiki::Sandbox::untaint(
$web,
sub {
return $web if Foswiki::Func::isValidWebName($web, 1);
return undef;
});
$topic = Foswiki::Sandbox::untaint(
$topic,
sub {
return $topic if Foswiki::Func::isValidTopicName($topic, 1);
return undef;
});
my ($meta, $text) = Foswiki::Func::readTopic($web, $topic);
unless (Foswiki::Func::checkAccessPermission(
'VIEW', Foswiki::Func::getWikiName(), $text, $topic, $web, $meta)) {
Expand Down
15 changes: 11 additions & 4 deletions core/lib/Assert.pm
Expand Up @@ -10,7 +10,7 @@ require 5.006;
# 1. ASSERT instead of assert
# 2. has to be _explicitly enabled_ using the $ENV{ASSERT}
# 3. should and shouldnt have been removed
# 4. Added UNTAINTED
# 4. Added UNTAINTED and TAINT
#
# Usage is as for Carp::Assert except that you have to explicitly
# enable asserts using the environment variable ENV{FOSWIKI_ASSERTS}
Expand All @@ -19,12 +19,13 @@ require 5.006;

use strict;

use vars qw(@ISA $VERSION %EXPORT_TAGS);
use vars qw(@ISA $VERSION %EXPORT_TAGS $DIRTY);

BEGIN {
$VERSION = '0.01';
$DIRTY = $ENV{PATH}; # Used in TAINT

$EXPORT_TAGS{NDEBUG} = [qw(ASSERT UNTAINTED DEBUG)];
$EXPORT_TAGS{NDEBUG} = [qw(ASSERT UNTAINTED TAINT DEBUG)];
$EXPORT_TAGS{DEBUG} = $EXPORT_TAGS{NDEBUG};
Exporter::export_tags(qw(NDEBUG DEBUG));
}
Expand All @@ -47,7 +48,7 @@ sub import {
else {
my $caller = caller;
*{ $caller . '::ASSERT' } = \&noop;
*{ $caller . '::UNTAINTED' } = \&ASSERTS_OFF;
*{ $caller . '::TAINT' } = sub { $_[0] };
*{ $caller . '::DEBUG' } = \&ASSERTS_OFF;
}
use strict 'refs';
Expand All @@ -65,10 +66,16 @@ sub ASSERT ($;$) {
return undef;
}

# Test if a value is untainted
sub UNTAINTED($) {
local ( @_, $@, $^W ) = @_;
my $x;
return eval { $x = $_[0], kill 0; 1 };
}

# Taint the datum passed and return the tainted value
sub TAINT($) {
return substr($_[0].$DIRTY, 0, length($_[0]));
}

1;

0 comments on commit 21a9c71

Please sign in to comment.