Skip to content

Commit

Permalink
Merge branch 'main' into php-filters
Browse files Browse the repository at this point in the history
  • Loading branch information
tudor-timcu committed Dec 18, 2024
2 parents cdfb4db + b0eeee1 commit 7a397cc
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 7 deletions.
11 changes: 6 additions & 5 deletions docs/should_block_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ class AikidoMiddleware implements MiddlewareInterface

// Get the user ID / name (from session or other auth system)
$userId = $this->getAuthenticatedUserId();
$userName = $this->getAuthenticatedUserName();


// If the user is authenticated, set the user ID in Aikido Zen context
if ($userId && $userName) {
\aikido\set_user(strval($userId), $userName);
if ($userId) {
// Username is optional: \aikido\set_user can be called only with user ID
$userName = $this->getAuthenticatedUserName();
\aikido\set_user($userId, $userName);
}

// Check blocking decision from Aikido
Expand Down Expand Up @@ -120,7 +121,7 @@ class ZenBlockDecision
// If a user is authenticated, set the user in Aikido's firewall context
if ($userId) {
// If username is available, you can set it as the second parameter in the \aikido\set_user function call
\aikido\set_user(strval($userId));
\aikido\set_user($userId);
}

// Check blocking decision from Aikido
Expand Down
4 changes: 4 additions & 0 deletions lib/php-extension/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ unordered_map<std::string, PHP_HANDLERS> HOOKED_FUNCTIONS = {
AIKIDO_REGISTER_FUNCTION_HANDLER_EX(symlink, handle_pre_file_path_access_2),
AIKIDO_REGISTER_FUNCTION_HANDLER_EX(touch, handle_pre_file_path_access),
AIKIDO_REGISTER_FUNCTION_HANDLER_EX(unlink, handle_pre_file_path_access),
AIKIDO_REGISTER_FUNCTION_HANDLER_EX(require, handle_pre_file_path_access),
AIKIDO_REGISTER_FUNCTION_HANDLER_EX(require_once, handle_pre_file_path_access),
AIKIDO_REGISTER_FUNCTION_HANDLER_EX(include, handle_pre_file_path_access),
AIKIDO_REGISTER_FUNCTION_HANDLER_EX(include_once, handle_pre_file_path_access),
};

unordered_map<AIKIDO_METHOD_KEY, PHP_HANDLERS, AIKIDO_METHOD_KEY_HASH> HOOKED_METHODS = {
Expand Down
2 changes: 1 addition & 1 deletion lib/request-processor/handle_user_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func OnUserEvent() string {
username := context.GetUserName()
ip := context.GetIp()

log.Infof("[UEVENT] Got user event: \"%s\" \"%s\" \"%s\"", id, username, ip)
log.Infof("Got user event!")

if id == "" || ip == "" {
return ""
Expand Down
20 changes: 20 additions & 0 deletions tests/cli/path_traversal/test_path_traversal_include.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Test path traversal (include)

--ENV--
AIKIDO_LOG_LEVEL=INFO
AIKIDO_BLOCK=1

--FILE--
<?php

$_SERVER['HTTP_USER'] = '../file';

$file = '../file/test.txt';

include($file);

?>

--EXPECTREGEX--
.*Fatal error: Uncaught Exception: Aikido firewall has blocked a path traversal attack.*
20 changes: 20 additions & 0 deletions tests/cli/path_traversal/test_path_traversal_include_once.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Test path traversal (include_once)

--ENV--
AIKIDO_LOG_LEVEL=INFO
AIKIDO_BLOCK=1

--FILE--
<?php

$_SERVER['HTTP_USER'] = '../file';

$file = '../file/test.txt';

include_once($file);

?>

--EXPECTREGEX--
.*Fatal error: Uncaught Exception: Aikido firewall has blocked a path traversal attack.*
20 changes: 20 additions & 0 deletions tests/cli/path_traversal/test_path_traversal_require.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Test path traversal (require)

--ENV--
AIKIDO_LOG_LEVEL=INFO
AIKIDO_BLOCK=1

--FILE--
<?php

$_SERVER['HTTP_USER'] = '../file';

$file = '../file/test.txt';

require($file);

?>

--EXPECTREGEX--
.*Fatal error: Uncaught Exception: Aikido firewall has blocked a path traversal attack.*
20 changes: 20 additions & 0 deletions tests/cli/path_traversal/test_path_traversal_require_once.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Test path traversal (require_once)

--ENV--
AIKIDO_LOG_LEVEL=INFO
AIKIDO_BLOCK=1

--FILE--
<?php

$_SERVER['HTTP_USER'] = '../file';

$file = '../file/test.txt';

require_once($file);

?>

--EXPECTREGEX--
.*Fatal error: Uncaught Exception: Aikido firewall has blocked a path traversal attack.*
2 changes: 1 addition & 1 deletion tests/cli/user/set_user_test.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ if ($a == true) {
?>

--EXPECTF--
[AIKIDO][INFO] [UEVENT] Got user event: "122-sa-2" "username1" "::1"
[AIKIDO][INFO] Got user event!
User set successfully

0 comments on commit 7a397cc

Please sign in to comment.