diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2019-07-24 16:57:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-24 16:57:04 +0200 |
commit | 3a9aa28558313acdf917b07abceffcd3622c3059 (patch) | |
tree | 9ceebc0956bdd03aa58e8267149cfbb585b04f8b | |
parent | 3a08e81969e9deafdb4d1aa890c03d67adcc4897 (diff) | |
parent | 51d7f62b316abfc14e770b3108edb0e3f48e38dd (diff) | |
download | wallabag-3a9aa28558313acdf917b07abceffcd3622c3059.tar.gz wallabag-3a9aa28558313acdf917b07abceffcd3622c3059.tar.zst wallabag-3a9aa28558313acdf917b07abceffcd3622c3059.zip |
Merge pull request #4063 from wallabag/fix/cookiejar
Use a custom cookiejar to avoid error when the cookie is badly saved
-rw-r--r-- | composer.lock | 67 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/FileCookieJar.php | 91 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Resources/config/services.yml | 6 |
3 files changed, 129 insertions, 35 deletions
diff --git a/composer.lock b/composer.lock index 2bce514a..e72ea474 100644 --- a/composer.lock +++ b/composer.lock | |||
@@ -1470,16 +1470,16 @@ | |||
1470 | }, | 1470 | }, |
1471 | { | 1471 | { |
1472 | "name": "egulias/email-validator", | 1472 | "name": "egulias/email-validator", |
1473 | "version": "2.1.9", | 1473 | "version": "2.1.10", |
1474 | "source": { | 1474 | "source": { |
1475 | "type": "git", | 1475 | "type": "git", |
1476 | "url": "https://github.com/egulias/EmailValidator.git", | 1476 | "url": "https://github.com/egulias/EmailValidator.git", |
1477 | "reference": "128cc721d771ec2c46ce59698f4ca42b73f71b25" | 1477 | "reference": "a6c8d7101b19a451c1707b1b79bbbc56e4bdb7ec" |
1478 | }, | 1478 | }, |
1479 | "dist": { | 1479 | "dist": { |
1480 | "type": "zip", | 1480 | "type": "zip", |
1481 | "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/128cc721d771ec2c46ce59698f4ca42b73f71b25", | 1481 | "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/a6c8d7101b19a451c1707b1b79bbbc56e4bdb7ec", |
1482 | "reference": "128cc721d771ec2c46ce59698f4ca42b73f71b25", | 1482 | "reference": "a6c8d7101b19a451c1707b1b79bbbc56e4bdb7ec", |
1483 | "shasum": "" | 1483 | "shasum": "" |
1484 | }, | 1484 | }, |
1485 | "require": { | 1485 | "require": { |
@@ -1489,7 +1489,8 @@ | |||
1489 | "require-dev": { | 1489 | "require-dev": { |
1490 | "dominicsayers/isemail": "dev-master", | 1490 | "dominicsayers/isemail": "dev-master", |
1491 | "phpunit/phpunit": "^4.8.35||^5.7||^6.0", | 1491 | "phpunit/phpunit": "^4.8.35||^5.7||^6.0", |
1492 | "satooshi/php-coveralls": "^1.0.1" | 1492 | "satooshi/php-coveralls": "^1.0.1", |
1493 | "symfony/phpunit-bridge": "^4.4@dev" | ||
1493 | }, | 1494 | }, |
1494 | "suggest": { | 1495 | "suggest": { |
1495 | "ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation" | 1496 | "ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation" |
@@ -1523,7 +1524,7 @@ | |||
1523 | "validation", | 1524 | "validation", |
1524 | "validator" | 1525 | "validator" |
1525 | ], | 1526 | ], |
1526 | "time": "2019-06-23T10:14:27+00:00" | 1527 | "time": "2019-07-19T20:52:08+00:00" |
1527 | }, | 1528 | }, |
1528 | { | 1529 | { |
1529 | "name": "electrolinux/php-html5lib", | 1530 | "name": "electrolinux/php-html5lib", |
@@ -3673,16 +3674,16 @@ | |||
3673 | }, | 3674 | }, |
3674 | { | 3675 | { |
3675 | "name": "j0k3r/graby-site-config", | 3676 | "name": "j0k3r/graby-site-config", |
3676 | "version": "1.0.86", | 3677 | "version": "1.0.88", |
3677 | "source": { | 3678 | "source": { |
3678 | "type": "git", | 3679 | "type": "git", |
3679 | "url": "https://github.com/j0k3r/graby-site-config.git", | 3680 | "url": "https://github.com/j0k3r/graby-site-config.git", |
3680 | "reference": "9c0ae4ee74e737c6ccf913da9bcb169850d38a30" | 3681 | "reference": "b485a36c31736b8834ebf62f42bd97fb333eefa7" |
3681 | }, | 3682 | }, |
3682 | "dist": { | 3683 | "dist": { |
3683 | "type": "zip", | 3684 | "type": "zip", |
3684 | "url": "https://api.github.com/repos/j0k3r/graby-site-config/zipball/9c0ae4ee74e737c6ccf913da9bcb169850d38a30", | 3685 | "url": "https://api.github.com/repos/j0k3r/graby-site-config/zipball/b485a36c31736b8834ebf62f42bd97fb333eefa7", |
3685 | "reference": "9c0ae4ee74e737c6ccf913da9bcb169850d38a30", | 3686 | "reference": "b485a36c31736b8834ebf62f42bd97fb333eefa7", |
3686 | "shasum": "" | 3687 | "shasum": "" |
3687 | }, | 3688 | }, |
3688 | "require": { | 3689 | "require": { |
@@ -3709,7 +3710,7 @@ | |||
3709 | } | 3710 | } |
3710 | ], | 3711 | ], |
3711 | "description": "Graby site config files", | 3712 | "description": "Graby site config files", |
3712 | "time": "2019-06-25T10:46:50+00:00" | 3713 | "time": "2019-07-23T15:40:40+00:00" |
3713 | }, | 3714 | }, |
3714 | { | 3715 | { |
3715 | "name": "j0k3r/httplug-ssrf-plugin", | 3716 | "name": "j0k3r/httplug-ssrf-plugin", |
@@ -5162,16 +5163,16 @@ | |||
5162 | }, | 5163 | }, |
5163 | { | 5164 | { |
5164 | "name": "pagerfanta/pagerfanta", | 5165 | "name": "pagerfanta/pagerfanta", |
5165 | "version": "v2.1.2", | 5166 | "version": "v2.1.3", |
5166 | "source": { | 5167 | "source": { |
5167 | "type": "git", | 5168 | "type": "git", |
5168 | "url": "https://github.com/whiteoctober/Pagerfanta.git", | 5169 | "url": "https://github.com/whiteoctober/Pagerfanta.git", |
5169 | "reference": "45a85ad426316ae37f2d007022e5b4c95bc3aef4" | 5170 | "reference": "a53ff01d521648d9dbca19b93ac6bc75a59b0972" |
5170 | }, | 5171 | }, |
5171 | "dist": { | 5172 | "dist": { |
5172 | "type": "zip", | 5173 | "type": "zip", |
5173 | "url": "https://api.github.com/repos/whiteoctober/Pagerfanta/zipball/45a85ad426316ae37f2d007022e5b4c95bc3aef4", | 5174 | "url": "https://api.github.com/repos/whiteoctober/Pagerfanta/zipball/a53ff01d521648d9dbca19b93ac6bc75a59b0972", |
5174 | "reference": "45a85ad426316ae37f2d007022e5b4c95bc3aef4", | 5175 | "reference": "a53ff01d521648d9dbca19b93ac6bc75a59b0972", |
5175 | "shasum": "" | 5176 | "shasum": "" |
5176 | }, | 5177 | }, |
5177 | "require": { | 5178 | "require": { |
@@ -5227,7 +5228,7 @@ | |||
5227 | "paginator", | 5228 | "paginator", |
5228 | "paging" | 5229 | "paging" |
5229 | ], | 5230 | ], |
5230 | "time": "2019-04-02T08:50:39+00:00" | 5231 | "time": "2019-07-17T20:56:16+00:00" |
5231 | }, | 5232 | }, |
5232 | { | 5233 | { |
5233 | "name": "paragonie/random_compat", | 5234 | "name": "paragonie/random_compat", |
@@ -7016,16 +7017,16 @@ | |||
7016 | }, | 7017 | }, |
7017 | { | 7018 | { |
7018 | "name": "scheb/two-factor-bundle", | 7019 | "name": "scheb/two-factor-bundle", |
7019 | "version": "v3.19.1", | 7020 | "version": "v3.21.0", |
7020 | "source": { | 7021 | "source": { |
7021 | "type": "git", | 7022 | "type": "git", |
7022 | "url": "https://github.com/scheb/two-factor-bundle.git", | 7023 | "url": "https://github.com/scheb/two-factor-bundle.git", |
7023 | "reference": "634b9b40ea0b6769f274ac994067f08012d96c44" | 7024 | "reference": "94cc6f2e0fd8a7b683246d95fcad9b15ca828fc6" |
7024 | }, | 7025 | }, |
7025 | "dist": { | 7026 | "dist": { |
7026 | "type": "zip", | 7027 | "type": "zip", |
7027 | "url": "https://api.github.com/repos/scheb/two-factor-bundle/zipball/634b9b40ea0b6769f274ac994067f08012d96c44", | 7028 | "url": "https://api.github.com/repos/scheb/two-factor-bundle/zipball/94cc6f2e0fd8a7b683246d95fcad9b15ca828fc6", |
7028 | "reference": "634b9b40ea0b6769f274ac994067f08012d96c44", | 7029 | "reference": "94cc6f2e0fd8a7b683246d95fcad9b15ca828fc6", |
7029 | "shasum": "" | 7030 | "shasum": "" |
7030 | }, | 7031 | }, |
7031 | "require": { | 7032 | "require": { |
@@ -7074,7 +7075,7 @@ | |||
7074 | "two-factor", | 7075 | "two-factor", |
7075 | "two-step" | 7076 | "two-step" |
7076 | ], | 7077 | ], |
7077 | "time": "2019-07-01T19:12:43+00:00" | 7078 | "time": "2019-07-12T16:11:05+00:00" |
7078 | }, | 7079 | }, |
7079 | { | 7080 | { |
7080 | "name": "sensio/distribution-bundle", | 7081 | "name": "sensio/distribution-bundle", |
@@ -7203,7 +7204,7 @@ | |||
7203 | }, | 7204 | }, |
7204 | { | 7205 | { |
7205 | "name": "sensiolabs/security-checker", | 7206 | "name": "sensiolabs/security-checker", |
7206 | "version": "v6.0.1", | 7207 | "version": "v6.0.2", |
7207 | "source": { | 7208 | "source": { |
7208 | "type": "git", | 7209 | "type": "git", |
7209 | "url": "https://github.com/sensiolabs/security-checker.git", | 7210 | "url": "https://github.com/sensiolabs/security-checker.git", |
@@ -8076,7 +8077,7 @@ | |||
8076 | }, | 8077 | }, |
8077 | { | 8078 | { |
8078 | "name": "Gert de Pagter", | 8079 | "name": "Gert de Pagter", |
8079 | "email": "BackEndTea@gmail.com" | 8080 | "email": "backendtea@gmail.com" |
8080 | } | 8081 | } |
8081 | ], | 8082 | ], |
8082 | "description": "Symfony polyfill for ctype functions", | 8083 | "description": "Symfony polyfill for ctype functions", |
@@ -9436,16 +9437,16 @@ | |||
9436 | }, | 9437 | }, |
9437 | { | 9438 | { |
9438 | "name": "zendframework/zend-diactoros", | 9439 | "name": "zendframework/zend-diactoros", |
9439 | "version": "2.1.2", | 9440 | "version": "2.1.3", |
9440 | "source": { | 9441 | "source": { |
9441 | "type": "git", | 9442 | "type": "git", |
9442 | "url": "https://github.com/zendframework/zend-diactoros.git", | 9443 | "url": "https://github.com/zendframework/zend-diactoros.git", |
9443 | "reference": "37bf68b428850ee26ed7c3be6c26236dd95a95f1" | 9444 | "reference": "279723778c40164bcf984a2df12ff2c6ec5e61c1" |
9444 | }, | 9445 | }, |
9445 | "dist": { | 9446 | "dist": { |
9446 | "type": "zip", | 9447 | "type": "zip", |
9447 | "url": "https://api.github.com/repos/zendframework/zend-diactoros/zipball/37bf68b428850ee26ed7c3be6c26236dd95a95f1", | 9448 | "url": "https://api.github.com/repos/zendframework/zend-diactoros/zipball/279723778c40164bcf984a2df12ff2c6ec5e61c1", |
9448 | "reference": "37bf68b428850ee26ed7c3be6c26236dd95a95f1", | 9449 | "reference": "279723778c40164bcf984a2df12ff2c6ec5e61c1", |
9449 | "shasum": "" | 9450 | "shasum": "" |
9450 | }, | 9451 | }, |
9451 | "require": { | 9452 | "require": { |
@@ -9498,7 +9499,7 @@ | |||
9498 | "psr", | 9499 | "psr", |
9499 | "psr-7" | 9500 | "psr-7" |
9500 | ], | 9501 | ], |
9501 | "time": "2019-04-29T21:11:00+00:00" | 9502 | "time": "2019-07-10T16:13:25+00:00" |
9502 | }, | 9503 | }, |
9503 | { | 9504 | { |
9504 | "name": "zendframework/zend-eventmanager", | 9505 | "name": "zendframework/zend-eventmanager", |
@@ -9723,16 +9724,16 @@ | |||
9723 | }, | 9724 | }, |
9724 | { | 9725 | { |
9725 | "name": "doctrine/data-fixtures", | 9726 | "name": "doctrine/data-fixtures", |
9726 | "version": "v1.3.1", | 9727 | "version": "v1.3.2", |
9727 | "source": { | 9728 | "source": { |
9728 | "type": "git", | 9729 | "type": "git", |
9729 | "url": "https://github.com/doctrine/data-fixtures.git", | 9730 | "url": "https://github.com/doctrine/data-fixtures.git", |
9730 | "reference": "3a1e2c3c600e615a2dffe56d4ca0875cc5233e0a" | 9731 | "reference": "09b16943b27f3d80d63988d100ff256148c2f78b" |
9731 | }, | 9732 | }, |
9732 | "dist": { | 9733 | "dist": { |
9733 | "type": "zip", | 9734 | "type": "zip", |
9734 | "url": "https://api.github.com/repos/doctrine/data-fixtures/zipball/3a1e2c3c600e615a2dffe56d4ca0875cc5233e0a", | 9735 | "url": "https://api.github.com/repos/doctrine/data-fixtures/zipball/09b16943b27f3d80d63988d100ff256148c2f78b", |
9735 | "reference": "3a1e2c3c600e615a2dffe56d4ca0875cc5233e0a", | 9736 | "reference": "09b16943b27f3d80d63988d100ff256148c2f78b", |
9736 | "shasum": "" | 9737 | "shasum": "" |
9737 | }, | 9738 | }, |
9738 | "require": { | 9739 | "require": { |
@@ -9779,7 +9780,7 @@ | |||
9779 | "keywords": [ | 9780 | "keywords": [ |
9780 | "database" | 9781 | "database" |
9781 | ], | 9782 | ], |
9782 | "time": "2018-03-20T09:06:36+00:00" | 9783 | "time": "2019-07-10T18:30:35+00:00" |
9783 | }, | 9784 | }, |
9784 | { | 9785 | { |
9785 | "name": "doctrine/doctrine-fixtures-bundle", | 9786 | "name": "doctrine/doctrine-fixtures-bundle", |
diff --git a/src/Wallabag/CoreBundle/Helper/FileCookieJar.php b/src/Wallabag/CoreBundle/Helper/FileCookieJar.php new file mode 100644 index 00000000..9a63e949 --- /dev/null +++ b/src/Wallabag/CoreBundle/Helper/FileCookieJar.php | |||
@@ -0,0 +1,91 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Helper; | ||
4 | |||
5 | use GuzzleHttp\Cookie\FileCookieJar as BaseFileCookieJar; | ||
6 | use GuzzleHttp\Cookie\SetCookie; | ||
7 | use GuzzleHttp\Utils; | ||
8 | use Psr\Log\LoggerInterface; | ||
9 | |||
10 | /** | ||
11 | * Overidden Cookie behavior to: | ||
12 | * - fix multiple concurrent writes (see https://github.com/guzzle/guzzle/pull/1884) | ||
13 | * - ignore error when the cookie file is malformatted (resulting in clearing it). | ||
14 | */ | ||
15 | class FileCookieJar extends BaseFileCookieJar | ||
16 | { | ||
17 | private $logger; | ||
18 | |||
19 | /** | ||
20 | * @param LoggerInterface $logger Only used to log info when something goes wrong | ||
21 | * @param string $cookieFile File to store the cookie data | ||
22 | */ | ||
23 | public function __construct(LoggerInterface $logger, $cookieFile) | ||
24 | { | ||
25 | parent::__construct($cookieFile); | ||
26 | |||
27 | $this->logger = $logger; | ||
28 | } | ||
29 | |||
30 | /** | ||
31 | * Saves the cookies to a file. | ||
32 | * | ||
33 | * @param string $filename File to save | ||
34 | * | ||
35 | * @throws \RuntimeException if the file cannot be found or created | ||
36 | */ | ||
37 | public function save($filename) | ||
38 | { | ||
39 | $json = []; | ||
40 | foreach ($this as $cookie) { | ||
41 | if ($cookie->getExpires() && !$cookie->getDiscard()) { | ||
42 | $json[] = $cookie->toArray(); | ||
43 | } | ||
44 | } | ||
45 | |||
46 | if (false === file_put_contents($filename, json_encode($json), LOCK_EX)) { | ||
47 | // @codeCoverageIgnoreStart | ||
48 | throw new \RuntimeException("Unable to save file {$filename}"); | ||
49 | // @codeCoverageIgnoreEnd | ||
50 | } | ||
51 | } | ||
52 | |||
53 | /** | ||
54 | * Load cookies from a JSON formatted file. | ||
55 | * | ||
56 | * Old cookies are kept unless overwritten by newly loaded ones. | ||
57 | * | ||
58 | * @param string $filename cookie file to load | ||
59 | * | ||
60 | * @throws \RuntimeException if the file cannot be loaded | ||
61 | */ | ||
62 | public function load($filename) | ||
63 | { | ||
64 | $json = file_get_contents($filename); | ||
65 | if (false === $json) { | ||
66 | // @codeCoverageIgnoreStart | ||
67 | throw new \RuntimeException("Unable to load file {$filename}"); | ||
68 | // @codeCoverageIgnoreEnd | ||
69 | } | ||
70 | |||
71 | try { | ||
72 | $data = Utils::jsonDecode($json, true); | ||
73 | } catch (\InvalidArgumentException $e) { | ||
74 | $this->logger->error('JSON inside the cookie is broken', [ | ||
75 | 'json' => $json, | ||
76 | 'error_msg' => $e->getMessage(), | ||
77 | ]); | ||
78 | |||
79 | // cookie file is invalid, just ignore the exception and it'll reset the whole cookie file | ||
80 | $data = ''; | ||
81 | } | ||
82 | |||
83 | if (\is_array($data)) { | ||
84 | foreach (Utils::jsonDecode($json, true) as $cookie) { | ||
85 | $this->setCookie(new SetCookie($cookie)); | ||
86 | } | ||
87 | } elseif (\strlen($data)) { | ||
88 | throw new \RuntimeException("Invalid cookie file: {$filename}"); | ||
89 | } | ||
90 | } | ||
91 | } | ||
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 31986951..3f3d4de7 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml | |||
@@ -82,8 +82,10 @@ services: | |||
82 | - ["addSubscriber", ["@bd_guzzle_site_authenticator.authenticator_subscriber"]] | 82 | - ["addSubscriber", ["@bd_guzzle_site_authenticator.authenticator_subscriber"]] |
83 | 83 | ||
84 | wallabag_core.guzzle.cookie_jar: | 84 | wallabag_core.guzzle.cookie_jar: |
85 | class: GuzzleHttp\Cookie\FileCookieJar | 85 | class: Wallabag\CoreBundle\Helper\FileCookieJar |
86 | arguments: ["%kernel.cache_dir%/cookiejar.json"] | 86 | arguments: |
87 | - "@logger" | ||
88 | - "%kernel.cache_dir%/cookiejar.json" | ||
87 | 89 | ||
88 | wallabag_core.content_proxy: | 90 | wallabag_core.content_proxy: |
89 | class: Wallabag\CoreBundle\Helper\ContentProxy | 91 | class: Wallabag\CoreBundle\Helper\ContentProxy |