Skip to content

Commit

Permalink
fix security hole, instead white-listing allowed HTTP methods
Browse files Browse the repository at this point in the history
  • Loading branch information
karpet committed Aug 31, 2012
1 parent 468a6ae commit 69d53fd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions Changes
Expand Up @@ -60,3 +60,8 @@ Revision history for Search-OpenSearch-Server
those methods specific to a Plack::Component.
* fix some undefined object errors

0.17 xxx
* use Engine->get_allowed_rest_methods instead of hardcoded list
* fix security hole where arbitrary Perl methods could be called via HTTP
like RPC.

2 changes: 1 addition & 1 deletion Makefile.PL
Expand Up @@ -7,7 +7,7 @@ name 'Search-OpenSearch-Server';
perl_version '5.8.3';
all_from 'lib/Search/OpenSearch/Server.pm';
requires 'Test::More' => 0;
requires 'Search::OpenSearch' => 0.18;
requires 'Search::OpenSearch' => 0.20;
requires 'Plack' => 0;
requires 'JSON' => 0;

Expand Down
2 changes: 1 addition & 1 deletion lib/Search/OpenSearch/Result.pm
Expand Up @@ -8,7 +8,7 @@ use overload
'bool' => sub {1},
fallback => 1;

our $VERSION = '0.16';
our $VERSION = '0.16_01';

__PACKAGE__->mk_accessors(
qw(
Expand Down
15 changes: 11 additions & 4 deletions lib/Search/OpenSearch/Server.pm
Expand Up @@ -10,7 +10,7 @@ use Data::Dump qw( dump );
use JSON;
use Time::HiRes qw( time );

our $VERSION = '0.16';
our $VERSION = '0.16_01';

my %formats = (
'XML' => 1,
Expand Down Expand Up @@ -129,9 +129,13 @@ sub do_rest_api {
croak "engine() is undefined";
}

if ( !$engine->can($method) ) {
my @allowed_methods = $engine->get_allowed_rest_methods();

if ( !$engine->can($method)
or !grep { $_ eq $method } @allowed_methods )
{
$response->status(405);
$response->header( 'Allow' => 'GET, POST, PUT, DELETE' );
$response->header( 'Allow' => join( ', ', @allowed_methods ) );
$response->body(
Search::OpenSearch::Result->new(
{ success => 0,
Expand Down Expand Up @@ -170,7 +174,10 @@ sub do_rest_api {

#warn dump $doc;

if ( $doc->{url} eq '/' or $doc->{url} eq "" ) {
if ( ( $doc->{url} eq '/' or $doc->{url} eq "" )
and $method ne "COMMIT"
and $method ne "ROLLBACK" )
{

#warn "invalid url";
$response->status(400);
Expand Down
2 changes: 1 addition & 1 deletion lib/Search/OpenSearch/Server/Plack.pm
Expand Up @@ -12,7 +12,7 @@ use JSON;
use Scalar::Util qw( weaken );
use Time::HiRes qw( time );

our $VERSION = '0.16';
our $VERSION = '0.16_01';

sub prepare_app {
my $self = shift;
Expand Down

0 comments on commit 69d53fd

Please sign in to comment.