Skip to content

Commit

Permalink
[SECURITY] Avoid remote execution
Browse files Browse the repository at this point in the history
Avoid an unexpected function to be run by using a non existent HTTP
verb.
  • Loading branch information
Mateu Aguiló Bosch committed Dec 2, 2015
1 parent f40337c commit a12e801
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions restful.module
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ function restful_menu_process_callback($resource_name, $version = NULL) {
$request = restful_parse_request();

try {
if (!\RestfulBase::isValidMethod($method, FALSE)) {
throw new RestfulBadRequestException(format_string('Unsupported method @method.', array(
'@method' => $method,
)));
}
return $handler->{$method}($path, $request);
}
catch (RestfulException $e) {
Expand Down
8 changes: 8 additions & 0 deletions tests/RestfulHookMenuTestCase.test
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ class RestfulHookMenuTestCase extends RestfulCurlBaseTestCase {

$node1 = node_load($node1->nid);
$this->assertEqual($node1->title, 'new title', 'HTTP method was overriden.');

// Try to override with an invalid method.
$headers = array('X-HTTP-Method-Override' => 'MALICIOUS');
$body = array(
'label' => 'new title',
);
$result = $this->httpRequest('api/v1.0/articles/' . $node1->nid, \RestfulInterface::POST, $body, $headers);
$this->assertTrue($result['code'] > 399, 'Bad overridden method is caught.');
}

/**
Expand Down

0 comments on commit a12e801

Please sign in to comment.