#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.
#1127 added support for calling
ValidatePayloadwith anilor emptysecretTokenslice. The justification for this change is explained in the current docs:I think this leaves
ValidatePayloadwith dangerous default behaviour. Because now every caller of this function has to check that they have a non-niland non-emptysecretTokenslice if they want to validate a payload. If they don't, it's possible to accidentally call the function with anilor empty slice (bad configuration, etc) and never know about it. This is not a safe default. Better would be to have the functionpanicor return an error in casesecretTokenisnilor 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
ValidatePayloadwhen they detect they are in such a mode.