fastapi-sessions icon indicating copy to clipboard operation
fastapi-sessions copied to clipboard

fix samesite enum bug

Open mahmednabil109 opened this issue 2 years ago • 2 comments

  • add __str__ to override the __str__ of the enum class; fixes #16

the issue:

the sameSiteEnum is getting serialized wrongly in the set-cookie header. that is because Enum class is overriding the __str__ of the string class. https://github.com/python/cpython/blob/ca3e611b1f620eabb657ef08a95d5f5f554ea773/Lib/enum.py#L1173-L1175

And despite that response.set_cookie is doing a great work to check the validity of the cookie parameter but calling the .lower() will get the original str but using the variable directly in line#135 is calling the __str__ method of the enum class hence it bypasses this check. https://github.com/encode/starlette/blob/master/starlette/responses.py#L129-L136.

solution:

I added the a __str__ to get the original string value as described here in the docs.

before the fix:

image

after the fix:

image

Signed-off-by: mahmednabil109 [email protected]

mahmednabil109 avatar Nov 28 '22 18:11 mahmednabil109

@jordanisaacs can you pls review?

mahmednabil109 avatar Feb 16 '23 17:02 mahmednabil109

Same issue here, any chance to merge this?

ooliver1 avatar Jul 07 '23 19:07 ooliver1