-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
510 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* Plugin Name: BC Security | ||
* Plugin URI: https://github.com/chesio/bc-security | ||
* Description: Helps keeping WordPress websites secure. | ||
* Version: 0.10.0 | ||
* Version: 0.11.0 | ||
* Author: Česlav Przywara <[email protected]> | ||
* Author URI: https://www.chesio.com | ||
* Requires PHP: 7.1 | ||
|
@@ -16,14 +16,22 @@ | |
if (version_compare(PHP_VERSION, '7.1', '<')) { | ||
// Warn user that his/her PHP version is too low for this plugin to function. | ||
add_action('admin_notices', function () { | ||
echo '<div class="error"><p>'; | ||
echo '<div class="notice notice-error"><p>'; | ||
echo esc_html( | ||
sprintf( | ||
__('BC Security plugin requires PHP 7.1 to function properly, but you have version %s installed. The plugin has been auto-deactivated.', 'bc-security'), | ||
PHP_VERSION | ||
) | ||
); | ||
echo '</p></div>'; | ||
// Warn user that his/her PHP version is no longer supported. | ||
echo '<div class="notice notice-warning"><p>'; | ||
echo sprintf( | ||
__('PHP version %1$s is <a href="%2$s">no longer supported</a>. You should consider upgrading PHP on your webhost.', 'bc-security'), | ||
PHP_VERSION, | ||
'https://secure.php.net/supported-versions.php' | ||
); | ||
echo '</p></div>'; | ||
// https://make.wordpress.org/plugins/2015/06/05/policy-on-php-versions/ | ||
if (isset($_GET['activate'])) { | ||
unset($_GET['activate']); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* @package BC_Security | ||
*/ | ||
namespace BlueChip\Security\Helpers; | ||
|
||
/** | ||
* @link https://haveibeenpwned.com/ | ||
*/ | ||
abstract class HaveIBeenPwned | ||
{ | ||
/** | ||
* @var string URL of Pwned Passwords home page | ||
*/ | ||
const PWNEDPASSWORDS_HOME_URL = 'https://haveibeenpwned.com/Passwords'; | ||
|
||
/** | ||
* @link https://haveibeenpwned.com/API/v2#SearchingPwnedPasswordsByRange | ||
* @var string URL of Pwned Passwords API range search end-point | ||
*/ | ||
const PWNEDPASSWORDS_API_RANGE_SEARCH_URL = 'https://api.pwnedpasswords.com/range/'; | ||
|
||
|
||
/** | ||
* @link https://haveibeenpwned.com/API/v2#PwnedPasswords | ||
* @param string $password Password to check. | ||
* @return bool True, if $password has been previously exposed in a data breach, false if not, null if check failed. | ||
*/ | ||
public static function hasPasswordBeenPwned(string $password): ?bool | ||
{ | ||
$sha1 = sha1($password); | ||
|
||
// Only first 5 characters of the hash are required. | ||
$sha1_prefix = substr($sha1, 0, 5); | ||
|
||
$response = wp_remote_get(esc_url(self::PWNEDPASSWORDS_API_RANGE_SEARCH_URL . $sha1_prefix)); | ||
|
||
if (wp_remote_retrieve_response_code($response) !== 200) { | ||
// Note: "there is no circumstance in which the API should return HTTP 404", | ||
// but of course remote request can always fail due network issues. | ||
return null; | ||
} | ||
|
||
$body = wp_remote_retrieve_body($response); | ||
if (empty($body)) { | ||
// Note: Should never happen, as there is a non-empty response for every prefix, | ||
// therefore return null (check failed) rather than false (check negative). | ||
return null; | ||
} | ||
|
||
// Every record has "hash_suffix:count" format. | ||
$records = explode(PHP_EOL, $body); | ||
foreach ($records as $record) { | ||
[$sha1_suffix, $count] = explode(':', $record); | ||
|
||
if ($sha1 === ($sha1_prefix . strtolower($sha1_suffix))) { | ||
return true; // Your password been pwned, my friend! | ||
} | ||
} | ||
|
||
return false; // Ok, you're fine. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.