Skip to content

Commit 7bbd8ab

Browse files
committed
security: Request Method
This addresses a report submitted by Khaled M. Alshammri (@ik0z) in regards to method override handling for state-changing routes.
1 parent fd96bba commit 7bbd8ab

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

include/class.dispatcher.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ function __construct($file=false) {
2929
function resolve($url, $args=null) {
3030
if ($this->file) { $this->lazy_load(); }
3131
# Support HTTP method emulation with the _method GET argument
32-
if (isset($_GET['_method'])) {
33-
$_SERVER['REQUEST_METHOD'] = strtoupper($_GET['_method']);
34-
unset($_GET['_method']);
32+
if ($_SERVER['REQUEST_METHOD'] == 'POST'
33+
&& isset($_POST['_method'])
34+
&& in_array(strtoupper($_POST['_method']), array('PUT', 'PATCH', 'DELETE'))) {
35+
$_SERVER['REQUEST_METHOD'] = strtoupper($_POST['_method']);
36+
unset($_POST['_method']);
3537
}
3638
// Decode URL for accurate matching
3739
$url = urldecode($url);

0 commit comments

Comments
 (0)