aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-01-21 16:35:41 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-01-21 16:35:41 +0100
commit7a0e6970b447b270c09e16fc7ee4098f736a7a12 (patch)
treeffc816de279e9f65fd280aa381c091d769b95d4c
parent9aa66d6244935fe86a5598fbdbe518cf6204af2e (diff)
downloadwallabag-7a0e6970b447b270c09e16fc7ee4098f736a7a12.tar.gz
wallabag-7a0e6970b447b270c09e16fc7ee4098f736a7a12.tar.zst
wallabag-7a0e6970b447b270c09e16fc7ee4098f736a7a12.zip
Use PHP7 random_bytes to generate RSS Token
random_bytes is a PHP 7 function wich has been ported to PHP 5 using paragonie/random_compat
-rw-r--r--composer.json3
-rw-r--r--src/Wallabag/CoreBundle/Tools/Utils.php15
2 files changed, 6 insertions, 12 deletions
diff --git a/composer.json b/composer.json
index 78b32307..d84e1f8b 100644
--- a/composer.json
+++ b/composer.json
@@ -62,7 +62,8 @@
62 "wallabag/php-mobi": "~1.0.0", 62 "wallabag/php-mobi": "~1.0.0",
63 "kphoen/rulerz-bundle": "~0.10", 63 "kphoen/rulerz-bundle": "~0.10",
64 "guzzlehttp/guzzle": "^5.2.0", 64 "guzzlehttp/guzzle": "^5.2.0",
65 "doctrine/doctrine-migrations-bundle": "^1.0" 65 "doctrine/doctrine-migrations-bundle": "^1.0",
66 "paragonie/random_compat": "~1.0"
66 }, 67 },
67 "require-dev": { 68 "require-dev": {
68 "doctrine/doctrine-fixtures-bundle": "~2.2", 69 "doctrine/doctrine-fixtures-bundle": "~2.2",
diff --git a/src/Wallabag/CoreBundle/Tools/Utils.php b/src/Wallabag/CoreBundle/Tools/Utils.php
index a16baca9..71cbc490 100644
--- a/src/Wallabag/CoreBundle/Tools/Utils.php
+++ b/src/Wallabag/CoreBundle/Tools/Utils.php
@@ -7,20 +7,13 @@ class Utils
7 /** 7 /**
8 * Generate a token used for RSS. 8 * Generate a token used for RSS.
9 * 9 *
10 * @param integer $length Length of the token
11 *
10 * @return string 12 * @return string
11 */ 13 */
12 public static function generateToken() 14 public static function generateToken($length = 15)
13 { 15 {
14 if (ini_get('open_basedir') === '') { 16 $token = substr(base64_encode(random_bytes($length)), 0, $length);
15 if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
16 // alternative to /dev/urandom for Windows
17 $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
18 } else {
19 $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15);
20 }
21 } else {
22 $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
23 }
24 17
25 // remove character which can broken the url 18 // remove character which can broken the url
26 return str_replace(array('+', '/'), '', $token); 19 return str_replace(array('+', '/'), '', $token);