Skip to content

Commit 4b25caa

Browse files
committed
Changed: modified canBypass function, it now passes a $isMuCall variable which indicates if it's a mu-plugin call or not.
1 parent d760a31 commit 4b25caa

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/Extensions/ExtensionInterface.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ public function logRequest($ruleId, $bodyData, $blockType);
2020

2121
/**
2222
* Determine if the current visitor can bypass the firewall.
23+
* If $isMuCall is true, we MUST avoid any function calls that checks the current authorization of the user,
24+
* this includes current_user_can. Otherwise, a fatal error is thrown.
2325
*
26+
* @param bool $isMuCall
2427
* @return bool
2528
*/
26-
public function canBypass();
29+
public function canBypass($isMuCall);
2730

2831
/**
2932
* Determine if the visitor is blocked from the website.

src/Extensions/Test/Extension.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ public function logRequest($ruleId, $bodyData, $blockType)
2121

2222
/**
2323
* Determine if the current visitor can bypass the firewall.
24+
* If $isMuCall is true, we MUST avoid any function calls that checks the current authorization of the user,
25+
* this includes current_user_can. Otherwise, a fatal error is thrown.
2426
*
27+
* @param bool $isMuCall
2528
* @return bool
2629
*/
27-
public function canBypass()
30+
public function canBypass($isMuCall)
2831
{
2932
return false;
3033
}

src/Processor.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ public function launch($mustExit = true)
104104
{
105105
// Determine if the user is temporarily blocked from the site before we do anything else.
106106
if (
107-
$this->extension->isBlocked($this->autoblockMinutes, $this->autoblockTime, $this->autoblockAttempts) && (
108-
$this->mustUsePluginCall || (!$this->mustUsePluginCall && !$this->extension->canBypass())
109-
)
107+
$this->extension->isBlocked($this->autoblockMinutes, $this->autoblockTime, $this->autoblockAttempts) && !$this->extension->canBypass($this->mustUsePluginCall)
110108
) {
111109
$this->extension->forceExit(22);
112110
}
@@ -122,7 +120,7 @@ public function launch($mustExit = true)
122120
}
123121

124122
// Determine if the current request is whitelisted or not.
125-
$isWhitelisted = !$this->mustUsePluginCall && $this->extension->canBypass();
123+
$isWhitelisted = $this->extension->canBypass($this->mustUsePluginCall);
126124

127125
// Merge the rules together. First iterate through the whitelist rules because
128126
// we want to whitelist the request if there's a whitelist rule match.

0 commit comments

Comments
 (0)