BlackSheep icon indicating copy to clipboard operation
BlackSheep copied to clipboard

Cookie parsing not RFC 6265 compliant (enough, at least.)

Open nnhanndakara opened this issue 6 years ago • 1 comments

SUMMARY

parse_cookie (at blacksheep/cookies.pyx) does not currently split cookie values correctly so parsing cookies with an equals sign in the value fails. I don't know what direction you intend to take cookie parsing in in the future, but limiting to one split should at least allow the unpack to complete for now.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

blacksheep/cookies.pyx

OS / ENVIRONMENT

N/A

STEPS TO REPRODUCE

Google seems to reliably give me a cookie with an equals sign in it:

import asyncio

import blacksheep.client

async def amain():
    async with blacksheep.client.ClientSession(follow_redirects=False) as session:
        response = await session.get("https://www.google.com/")
        for i in response.headers:
            print(i)
        print(await response.text())

if __name__ == "__main__":
    asyncio.run(amain())
EXPECTED RESULTS

Assuming I can index the headers collection (I was trying out blacksheep when I hit this), I should see a list of header names, and the body text of the response?

ACTUAL RESULTS

A ValueError is thrown as unpacking fails.

nnhanndakara avatar Jul 13 '20 22:07 nnhanndakara

Thank You, @kaorihinata! Sorry for replying so late: I had a long holiday from the second half of July, then I had some family issues that kept my head on other things.

Indeed, the bug is caused by my code not handling properly a Cookie name containing "=" character. Like: (b'Set-Cookie', b'NID=204=BLvB1.

I just pushed a fix, added tests, and verified that the code you shared in the description of this issue now works.

Today I'll make a PR for 0.2.3, and publish a new version to PyPi, including this fix.

RobertoPrevato avatar Aug 23 '20 11:08 RobertoPrevato