Skip to content

Commit 02de3b2

Browse files
committed
[security] data hardening
1 parent bee23a8 commit 02de3b2

23 files changed

+56
-47
lines changed

src/lib/src/ActionRouter/Actions/MfaEmailAutoLogin.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ class MfaEmailAutoLogin extends BaseAction {
1919
protected function exec() {
2020
$con = self::con();
2121
$mfaCon = $con->comps->mfa;
22+
$userID = (int)$this->action_data[ 'user_id' ];
2223

23-
$user = Services::WpUsers()->getUserById( $this->action_data[ 'user_id' ] );
24+
$user = Services::WpUsers()->getUserById( $userID );
2425
if ( empty( $user ) ) {
2526
throw new ActionException( 'No such user' );
2627
}
@@ -43,19 +44,19 @@ protected function exec() {
4344
if ( $emailProvider->validateLoginIntent( $mfaCon->findHashedNonce( $user, $this->action_data[ 'login_nonce' ] ) ) ) {
4445
$success = true;
4546
$emailProvider->postSuccessActions();
46-
wp_set_auth_cookie( $this->action_data[ 'user_id' ], true );
47-
$con->fireEvent( '2fa_success' );
47+
wp_set_auth_cookie( $userID, true );
48+
$con->comps->events->fireEvent( '2fa_success' );
4849
}
4950
}
5051
catch ( \Exception $e ) {
5152
error_log( 'failed auto login:'.$e->getMessage() );
5253
}
5354
finally {
54-
$con->fireEvent(
55+
$con->comps->events->fireEvent(
5556
$success ? '2fa_verify_success' : '2fa_verify_fail',
5657
[
5758
'audit_params' => [
58-
'user_login' => $this->action_data[ 'user_id' ],
59+
'user_login' => $userID,
5960
'method' => $emailProvider->getProviderName(),
6061
]
6162
]

src/lib/src/ActionRouter/Actions/Render/Components/Email/MfaLoginCode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ protected function getBodyData() :array {
2121
],
2222
'hrefs' => [
2323
'login_link' => 'https://clk.shldscrty.com/96',
24-
'auto_login' => $this->action_data[ 'url_auto_login' ],
24+
'auto_login' => esc_url( $this->action_data[ 'url_auto_login' ] ), // Internally generated via noncedPluginAction(); template uses |raw
2525
],
2626
'strings' => [
2727
'someone' => __( 'Someone attempted to login into this WordPress site using your account.', 'wp-simple-firewall' ),
2828
'requires' => __( 'Login requires verification with the following code.', 'wp-simple-firewall' ),
2929
'verification' => __( 'Verification Code', 'wp-simple-firewall' ),
3030
'auto_login' => __( 'Autologin URL', 'wp-simple-firewall' ),
3131
'details_heading' => __( 'Login Details', 'wp-simple-firewall' ),
32-
'details_url' => sprintf( '%s: %s', __( 'URL', 'wp-simple-firewall' ), $this->action_data[ 'home_url' ] ),
32+
'details_url' => sprintf( '%s: %s', __( 'URL', 'wp-simple-firewall' ), $this->action_data[ 'home_url' ] ), // Internally generated via getHomeUrl()
3333
'details_username' => sprintf( '%s: %s', __( 'Username', 'wp-simple-firewall' ),
3434
Services::WpUsers()->getUserById( $this->action_data[ 'user_id' ] )->user_login ),
3535
'details_ip' => sprintf( '%s: %s', __( 'IP Address', 'wp-simple-firewall' ), $this->action_data[ 'ip' ] ),

src/lib/src/ActionRouter/Actions/Render/Components/Email/UnblockMagicLink.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ protected function getBodyData() :array {
1818
$con = self::con();
1919
$user = Services::WpUsers()->getUserById( $this->action_data[ 'user_id' ] )->user_login;
2020
$ip = $this->action_data[ 'ip' ];
21-
$homeURL = $this->action_data[ 'home_url' ];
21+
$homeURL = $this->action_data[ 'home_url' ]; // Internally generated via getHomeUrl()
2222

2323
return [
2424
'hrefs' => [
25+
// Internally generated - don't escape here as template auto-escapes
2526
'unblock' => $con->plugin_urls->noncedPluginAction(
2627
IpAutoUnblockShieldUserLinkVerify::class,
2728
$homeURL,

src/lib/src/ActionRouter/Actions/Render/Components/Email/UserLoginNotice.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class UserLoginNotice extends EmailBase {
99
public const SLUG = 'email_user_login_notice';
1010
public const TEMPLATE = '/email/user_login_notice.twig';
1111

12+
// URLs are internally generated via getHomeUrl() - don't escape here as template auto-escapes
1213
protected function getBodyData() :array {
1314
return [
1415
'hrefs' => [

src/lib/src/ActionRouter/Actions/Render/Components/IpAnalyse/Activity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Activity extends Base {
1212
public const TEMPLATE = '/wpadmin/components/ip_analyse/ip_audittrail.twig';
1313

1414
protected function getRenderData() :array {
15-
$logLoader = ( new LoadLogs() )->setIP( $this->action_data[ 'ip' ] );
15+
$logLoader = ( new LoadLogs() )->setIP( $this->getAnalyseIP() );
1616
$logLoader->limit = 100;
1717

1818
$logs = [];

src/lib/src/ActionRouter/Actions/Render/Components/IpAnalyse/Base.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace FernleafSystems\Wordpress\Plugin\Shield\ActionRouter\Actions\Render\Components\IpAnalyse;
44

55
use FernleafSystems\Wordpress\Plugin\Shield\ActionRouter\Actions\Render;
6+
use FernleafSystems\Wordpress\Plugin\Shield\ActionRouter\Exceptions\ActionException;
67
use FernleafSystems\Wordpress\Services\Services;
78

89
class Base extends Render\BaseRender {
@@ -19,4 +20,14 @@ protected function getTimeAgo( int $ts ) :string {
1920
->setTimestamp( $ts )
2021
->diffForHumans();
2122
}
23+
24+
/**
25+
* @throws ActionException
26+
*/
27+
protected function getAnalyseIP() :string {
28+
if ( !Services::IP()->isValidIp( $this->action_data[ 'ip' ] ) ) {
29+
throw new ActionException( __( "A valid IP address wasn't provided.", 'wp-simple-firewall' ) );
30+
}
31+
return $this->action_data[ 'ip' ];
32+
}
2233
}

src/lib/src/ActionRouter/Actions/Render/Components/IpAnalyse/BotSignals.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ class BotSignals extends Base {
1515
protected function getRenderData() :array {
1616
$signals = [];
1717
$scores = ( new CalculateVisitorBotScores() )
18-
->setIP( $this->action_data[ 'ip' ] )
18+
->setIP( $this->getAnalyseIP() )
1919
->scores();
2020
try {
2121
$record = ( new BotSignalsRecord() )
22-
->setIP( $this->action_data[ 'ip' ] )
22+
->setIP( $this->getAnalyseIP() )
2323
->retrieve();
2424
}
2525
catch ( \Exception $e ) {

src/lib/src/ActionRouter/Actions/Render/Components/IpAnalyse/Container.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ class Container extends Base {
1010
public const TEMPLATE = '/wpadmin/components/ip_analyse/container.twig';
1111

1212
protected function getRenderData() :array {
13-
$ip = $this->action_data[ 'ip' ];
14-
if ( !Services::IP()->isValidIp( $ip ) ) {
15-
throw new \Exception( "A valid IP address wasn't provided." );
16-
}
13+
$ip = $this->getAnalyseIP();
1714
$actionRouter = self::con()->action_router;
1815
return [
1916
'content' => [

src/lib/src/ActionRouter/Actions/Render/Components/IpAnalyse/General.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class General extends Base {
2020
public const TEMPLATE = '/wpadmin/components/ip_analyse/ip_general.twig';
2121

2222
protected function getRenderData() :array {
23-
$ip = $this->action_data[ 'ip' ];
23+
$ip = $this->getAnalyseIP();
2424

2525
$countryCode = ( new LookupMeta() )
2626
->setIP( $ip )

src/lib/src/ActionRouter/Actions/Render/Components/IpAnalyse/Sessions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protected function getRenderData() :array {
1414
$WP = Services::WpGeneral();
1515

1616
$allSessions = [];
17-
foreach ( ( new FindSessions() )->byIP( $this->action_data[ 'ip' ] ) as /* $userID => */ $sessions ) {
17+
foreach ( ( new FindSessions() )->byIP( $this->getAnalyseIP() ) as /* $userID => */ $sessions ) {
1818
foreach ( $sessions as $session ) {
1919
$loginAt = $session[ 'login' ];
2020
$activityAt = $session[ 'shield' ][ 'last_activity_at' ] ?? $loginAt;

0 commit comments

Comments
 (0)