Skip to content

Is there a way to not encrypt the cookie set by SessionMiddleware? #2846

Closed Answered by jhominal
RafayAK asked this question in Q&A
Discussion options

You must be logged in to vote

By setting secret_key to None, what ended up happening is that the SessionMiddleware casts secret_key to a str, meaning that you end up with using the "None" string as the secret key.

However, note that session data is available both on the ASGI scope object (under the "session" key) and as a session property on Request objects.

That is, it would be pretty easy for you to add a (debug) endpoint that returns content of the session cookie:

async def view_decrypted_session(request: starlette.requests.Request) -> starlette.responses.Response:
    return starlette.responses.JSONResponse(request.session)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@RafayAK
Comment options

Answer selected by RafayAK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants