Skip to content

Commit 188f9c9

Browse files
committed
fix: sanitize issue
1 parent 8a9ef17 commit 188f9c9

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/Http/IpTool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private static function checkIP()
6060
} elseif (getenv('HTTP_FORWARDED')) {
6161
$ip = getenv('HTTP_FORWARDED');
6262
} else {
63-
$ip = $_SERVER['REMOTE_ADDR'];
63+
$ip = sanitize_text_field($_SERVER['REMOTE_ADDR']);
6464
}
6565

6666
return $ip;

src/Http/Request/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function body()
103103

104104
public function method()
105105
{
106-
return $_SERVER['REQUEST_METHOD'];
106+
return sanitize_text_field($_SERVER['REQUEST_METHOD']);
107107
}
108108

109109
public function contentType()

src/Http/Router/AjaxRouter.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,35 @@ public function registerRoutes()
2727

2828
public function addRoute(RouteRegister $route)
2929
{
30-
if (
31-
!isset($_REQUEST['action'])
32-
|| strpos($_REQUEST['action'], $this->_router->getAjaxPrefix()) === false
33-
|| !\in_array(strtoupper($_SERVER['REQUEST_METHOD']), $route->getMethods())
30+
31+
$requestMethod = isset($_SERVER['REQUEST_METHOD']) ? sanitize_text_field($_SERVER['REQUEST_METHOD']) : '';
32+
$action = isset($_REQUEST['action']) ? sanitize_text_field($_REQUEST['action']) : '';
33+
34+
if (strpos($action, $this->_router->getAjaxPrefix()) === false
35+
|| !\in_array(strtoupper($requestMethod), $route->getMethods())
3436
) {
3537
return;
3638
}
3739

38-
$requestPath = str_replace($this->_router->getAjaxPrefix(), '', $_REQUEST['action']);
40+
$requestPath = str_replace($this->_router->getAjaxPrefix(), '', $action);
3941
if (!$this->isRouteMatched($route, $requestPath)) {
4042
return;
4143
}
4244

43-
Hooks::addAction('wp_ajax_' . $_REQUEST['action'], [$route, 'handleRequest']);
45+
Hooks::addAction('wp_ajax_' . $action, [$route, 'handleRequest']);
4446
if ($route->isNoAuth()) {
45-
Hooks::addAction('wp_ajax_nopriv_' . $_REQUEST['action'], [$route, 'handleRequest']);
47+
Hooks::addAction('wp_ajax_nopriv_' . $action, [$route, 'handleRequest']);
4648
}
4749

4850
$this->_router->addRegisteredRoute($this->currentRouteName(), $route);
4951
}
5052

5153
public function currentRouteName()
5254
{
53-
return $_SERVER['REQUEST_METHOD'] . $_REQUEST['action'];
55+
$requestMethod = isset($_SERVER['REQUEST_METHOD']) ? sanitize_text_field($_SERVER['REQUEST_METHOD']) : '';
56+
$action = isset($_REQUEST['action']) ? sanitize_text_field($_REQUEST['action']) : '';
57+
58+
return $requestMethod. $action;
5459
}
5560

5661
/**

0 commit comments

Comments
 (0)