+
Skip to content

Support websites redirecting to the same page when AllowURLRevisit is disabled #763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2023

Conversation

WGH-
Copy link
Collaborator

@WGH- WGH- commented Apr 10, 2023

Some websites set a session cookie, and return a redirect to the same page instead of returning a response.

To illustrate this problem, this is how HTTP session might look like:

GET / HTTP/1.1
Host: 127.0.0.1:34931
User-Agent: colly - https://github.com/gocolly/colly/v2
Accept: */*
Accept-Encoding: gzip

HTTP/1.1 302 Found
Content-Type: text/html; charset=utf-8
Location: /
Set-Cookie: session_id=1
Date: Mon, 10 Apr 2023 23:29:29 GMT
Content-Length: 24

<a href="/">Found</a>.

GET / HTTP/1.1
Host: 127.0.0.1:34931
User-Agent: colly - https://github.com/gocolly/colly/v2
Accept: */*
Cookie: session_id=1
Referer: http://127.0.0.1:34931/
Accept-Encoding: gzip

HTTP/1.1 200 OK
Date: Mon, 10 Apr 2023 23:29:29 GMT
Content-Length: 12
Content-Type: text/plain; charset=utf-8

hello world

This fixes regression introduced in 0be3b71 by specifically bypassing revisit check if current redirect destination equals to the original one.

@WGH- WGH- requested a review from asciimoo April 10, 2023 23:35
Some websites set a session cookie, and return a redirect to
the same page instead of returning a response.

To illustrate this problem, this is how HTTP session
might look like:

    GET / HTTP/1.1
    Host: 127.0.0.1:34931
    User-Agent: colly - https://github.com/gocolly/colly/v2
    Accept: */*
    Accept-Encoding: gzip

    HTTP/1.1 302 Found
    Content-Type: text/html; charset=utf-8
    Location: /
    Set-Cookie: session_id=1
    Date: Mon, 10 Apr 2023 23:29:29 GMT
    Content-Length: 24

    <a href="/">Found</a>.

    GET / HTTP/1.1
    Host: 127.0.0.1:34931
    User-Agent: colly - https://github.com/gocolly/colly/v2
    Accept: */*
    Cookie: session_id=1
    Referer: http://127.0.0.1:34931/
    Accept-Encoding: gzip

    HTTP/1.1 200 OK
    Date: Mon, 10 Apr 2023 23:29:29 GMT
    Content-Length: 12
    Content-Type: text/plain; charset=utf-8

    hello world

This fixes regression introduced in 0be3b71 by specifically
bypassing revisit check if current redirect destination equals to
the original one.
@WGH- WGH- force-pushed the fix-setcookie-self-redirect branch from 55ef790 to b4ca6a7 Compare April 10, 2023 23:37
Copy link
Member

@asciimoo asciimoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks <3

@asciimoo asciimoo merged commit 70168cf into gocolly:master Apr 17, 2023
WGH- added a commit to WGH-/colly that referenced this pull request Mar 29, 2024
This was "fixed" in b4ca6a7 (gocolly#763), but the fix turned out to be incomplete.

That fix only allowed redirects leading to the same URL as the original
destination, and didn't take into account more complicated cases. Such
as, for example:

 * www.example.com
 * example.com
 * (set cookie)
 * example.com
WGH- added a commit to WGH-/colly that referenced this pull request Mar 29, 2024
This was "fixed" in b4ca6a7 (gocolly#763), but the fix turned out to be incomplete.

That fix only allowed redirects leading to the same URL as the original
destination, and didn't take into account more complicated cases. Such
as, for example:

 * www.example.com
 * example.com
 * (set cookie)
 * example.com
WGH- added a commit to WGH-/colly that referenced this pull request Mar 29, 2024
This was "fixed" in b4ca6a7 (gocolly#763), but the fix turned out to be incomplete.

That fix only allowed redirects leading to the same URL as the original
destination, and didn't take into account more complicated cases. Such
as, for example:

 * www.example.com
 * example.com
 * (set cookie)
 * example.com

(cherry picked from commit 02570f1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载