jnunemaker / jnunemaker/httparty

Cookies are not set properly after a redirect follow

Open
#696 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
5.9k
Forks
973
Avg merge
1h 59m
Merged PRs (30d)
1

Description

Test request:

curl --location --request POST 'https://www.sainsburys.co.uk/shop/ShoppingListDisplay' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'shoppingList=RICE' \
--data-urlencode 'action=findProducts' \
--data-urlencode 'langId=44' \
--data-urlencode 'storeId=10151' \
--data-urlencode 'catalogueId=10241'

Expected result: HTTP 200 after 1 redirect.
Actual result: HTTP 403 ERROR after 1 redirect.

After running the HTTParty requests through Fiddler I discovered it is sending maligned cookies. First call that responds with a redirect sets the following cookies:

image

HTTParty follows the redirect and issues a GET request with the following cookies though:

image

For comparison, the same request executed via Postman results in the following set of cookies:

image

Seems like something goes wrong when the cookies are parsed from the first response. There is another issue open that talks about cookie parsing, perhaps it is time to look at these. I would have submitted a PR but this is my third week learning Ruby and Rails so you really wouldn't want to see my code! :)

NB: Should you also drop the Content-Type header when you follow a redirect using GET after an initial POST request?

Great library otherwise, thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the POST and redirect with the supplied curl command, then inspect how HTTParty parses the redirect response cookies and builds the follow-up GET. Compare the cookies sent after the redirect with the response cookies and the Postman result; done means the request receives HTTP 200 after one redirect with correctly handled cookies.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.