marceloverdijk / restfbmessenger

RestFB Messenger
Apache License 2.0
22 stars 15 forks source link

Invalid expected signature generated for payload which contains percentage % #11

Closed reyjexter closed 6 years ago

reyjexter commented 6 years ago

There seems to be a bug which when server receives a message with payload that contains % character, the expected signature doesn't match with header signature.

This happens for example on:

When replying with "I got it" without the percentange, this works correctly and signature generated matches with the one on header.

Any help is appreciated. Thanks

reyjexter commented 6 years ago

Sorry, this isn't really a bug with restfbmessenger after all but more like MVC framework related which sometimes the response body is being parsed automatically. The correct fix is to parse the response body as UTF-8 which should include \u characters.

In our case, we were using Play Framework 2.3 which the framework provides an automatic way to parse content based on given type so using .asJson() didn't work but parsing the raw content and converting to UTF-8 manually fixed the problem.

Example solution

@BodyParser.Of(BodyParser.Raw.class)
public Result webhookPost() {
     final String body= new String(request().body().asRaw().asBytes(), "UTF-8");
}
marceloverdijk commented 6 years ago

Would you be able to provide a stacktrace?

Thanks for further feedback!