SimplePie: Fix HTTP 301 permanent redirection#3180
Merged
Alkarex merged 2 commits intoFreshRSS:masterfrom Sep 17, 2020
Merged
Conversation
When adding feeds it worked fine, but detecting permanent redirects for existing feeds was sometimes broken (only when PHP open_basedir was not set). Indeed, using the built-in CURLOPT_FOLLOWLOCATION instead of the manual method in SimplePie hides the list of HTTP redirects along the way, and prevents the distinction of e.g. 301 vs. 302 redirects. This patch disables CURLOPT_FOLLOWLOCATION in SimplePie, and fixes the manual method at the same time. The use of CURLOPT_FOLLOWLOCATION was nevertheless not systematic (only when open_basedir was not set), so now there is only one logic independent of open_basedir. I will send a PR upstream to SimplePie. How to test: pick a feed with 301 redirection such as HTTP to HTTPS, e.g. http://ing.dk/rss/term/341 Manually change back to previous address (to simulate a feed that is changing address) Refresh feed and observe whether the 301 redirect is obeyed.
Alkarex
commented
Sep 16, 2020
| curl_setopt($fp, CURLOPT_REFERER, SimplePie_Misc::url_remove_credentials($url)); | ||
| curl_setopt($fp, CURLOPT_USERAGENT, $useragent); | ||
| curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2); | ||
| if (!ini_get('open_basedir') && !ini_get('safe_mode') && version_compare(SimplePie_Misc::get_curl_version(), '7.15.2', '>=')) |
Member
Author
There was a problem hiding this comment.
This logic was used sometimes, in which case it was problematic. Removed.
Member
Author
|
Let's merge and continue testing in /master |
Comment on lines
+116
to
+120
| //if (!ini_get('open_basedir') && !ini_get('safe_mode') && version_compare(SimplePie_Misc::get_curl_version(), '7.15.2', '>=')) | ||
| //{ | ||
| // curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1); | ||
| // curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects); | ||
| //} |
Contributor
There was a problem hiding this comment.
In git leaving commented code is not a good practise. This should probably be removed.
Member
Author
There was a problem hiding this comment.
See simplepie/simplepie#660 (which I will merge back when accepted)
Alkarex
added a commit
to Alkarex/FreshRSS
that referenced
this pull request
Oct 3, 2020
Contributes to FreshRSS#3082 Includes FreshRSS#3180 Differences: simplepie/simplepie@aaad78e...692e8bc
Alkarex
added a commit
that referenced
this pull request
Oct 3, 2020
Contributes to #3082 Includes #3180 Differences: simplepie/simplepie@aaad78e...692e8bc
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When adding feeds it worked fine, but detecting permanent redirects for existing feeds was sometimes broken (only when PHP open_basedir was not set).
Indeed, using the built-in CURLOPT_FOLLOWLOCATION instead of the manual method in SimplePie hides the list of HTTP redirects along the way, and prevents the distinction of e.g. 301 vs. 302 redirects.
This patch disables CURLOPT_FOLLOWLOCATION in SimplePie, and fixes the manual method at the same time.
The use of CURLOPT_FOLLOWLOCATION was nevertheless not systematic (only when open_basedir was not set), so now there is only one logic independent of open_basedir.
I will send a PR upstream to SimplePie.
How to test: pick a feed with 301 redirection such as HTTP to HTTPS, e.g. http://ing.dk/rss/term/341
Manually change back to previous address (to simulate a feed that is changing address)
Refresh feed and observe whether the 301 redirect is obeyed.