Skip to content

Check webhook signature before constructing Event from the payload #577

@rfk

Description

@rfk

Hi!

I happened to be poking around in the details of your webhook signature-checking code, and I noticed that it does some processing on the event payload before checking the signature, in particular calling stripe.Event.construct_from on the not-yet-authenticated data:

data = json.loads(payload)
event = stripe.Event.construct_from(data, api_key)
WebhookSignature.verify_header(payload, sig_header, secret, tolerance)

I don't have any reason to believe that this can be used to trigger bad behaviour, but Event.construct_from seems to do quite a lot of dynamic work to hydrate the data into live objects. Calling WebhookSignature.verify_header before doing that work could be a nice defense-in-depth measure against bugs elsewhere in the codebase.

Just a small suggestion that I wanted to pass along; thanks for providing this nice library, and for an API that seems to strongly encourage the webhook-handling code down the right path security-wise!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions