Skip to content

ValidatePayload should not accept nil or empty secretToken slice #2731

@myitcv

Description

@myitcv

#1127 added support for calling ValidatePayload with a nil or empty secretToken slice. The justification for this change is explained in the current docs:

If your webhook does not contain a secret token, you can pass nil or an empty slice. This is intended for local development purposes only and all webhooks should ideally set up a secret token.

I think this leaves ValidatePayload with dangerous default behaviour. Because now every caller of this function has to check that they have a non-nil and non-empty secretToken slice if they want to validate a payload. If they don't, it's possible to accidentally call the function with a nil or empty slice (bad configuration, etc) and never know about it. This is not a safe default. Better would be to have the function panic or return an error in case secretToken is nil or empty - because such a value can never be used to validate a payload, which is obviously what the caller intended to do in calling the function.

The same applies to ValidatePayloadFromBody().

I haven't looked at other functions/methods.

Returning to the goal of #1126, I would instead have pushed back and suggested that developers who are in development mode change their calling code to simply not call ValidatePayload when they detect they are in such a mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions