Skip to content
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

save_session from the SessionInterface class crash with Werkzeug 3.0.1 #18

Open
urucoder opened this issue Nov 1, 2023 · 2 comments
Open

Comments

@urucoder
Copy link

urucoder commented Nov 1, 2023

The Werkzeugh package was affected by the following bug CVE-2023-46136.
The version 3.0.1 fixes it, but also adds this code to the dump_cookie method, which is used by the set_cookie method, this now requires the session_id to be a str instead of bytes type, when the session interface uses the default signer it crashes due it returns a bytes type.

It can be fixed by anyone creating a custom signer class that decodes the bytes and then passing it to the session interface

from itsdangerous import Signer
from quart_session.sessions import SessionInterface

class CustomSigner(Signer):
    def sign(self, value: str) -> str:
        return super().sign(value).decode('utf-8')

class CustomInterface(SessionInterface):
    def _get_signer(self, app) -> Optional[Signer]:
        if not app.secret_key:
            return None
        return CustomSigner(app.secret_key, salt='session-salt', 
                            key_derivation='hmac', digest_method=hashlib.sha384)
@kroketio
Copy link
Owner

kroketio commented Nov 1, 2023

Yeah. Lots of breaking changes to Werkzeug and Flask as of late.

@mmreza79
Copy link

mmreza79 commented Nov 14, 2023

Ja, I am having the same problem updating Werkzeug 3.0.1. Thanks a lot @urucoder for your suggestion :)

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

No branches or pull requests

3 participants