Skip to content

Commit a12e801

Browse files
author
Mateu Aguiló Bosch
committed
[SECURITY] Avoid remote execution
Avoid an unexpected function to be run by using a non existent HTTP verb.
1 parent f40337c commit a12e801

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

restful.module

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,11 @@ function restful_menu_process_callback($resource_name, $version = NULL) {
505505
$request = restful_parse_request();
506506

507507
try {
508+
if (!\RestfulBase::isValidMethod($method, FALSE)) {
509+
throw new RestfulBadRequestException(format_string('Unsupported method @method.', array(
510+
'@method' => $method,
511+
)));
512+
}
508513
return $handler->{$method}($path, $request);
509514
}
510515
catch (RestfulException $e) {

tests/RestfulHookMenuTestCase.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ class RestfulHookMenuTestCase extends RestfulCurlBaseTestCase {
6767

6868
$node1 = node_load($node1->nid);
6969
$this->assertEqual($node1->title, 'new title', 'HTTP method was overriden.');
70+
71+
// Try to override with an invalid method.
72+
$headers = array('X-HTTP-Method-Override' => 'MALICIOUS');
73+
$body = array(
74+
'label' => 'new title',
75+
);
76+
$result = $this->httpRequest('api/v1.0/articles/' . $node1->nid, \RestfulInterface::POST, $body, $headers);
77+
$this->assertTrue($result['code'] > 399, 'Bad overridden method is caught.');
7078
}
7179

7280
/**

0 commit comments

Comments
 (0)