skip to Main Content

I am currently implementing a Facebook Chat Extension which basically is just a web page displayed in a browser provided by the Facebook Messenger app. This web page communicates with a corporate backend over a REST API (implemented with Python/Flask). Communication is done via HTTPS.

My question: How to secure the communication the Web page and the backend in the sense that the backend cannot be accessed by any clients that we do not control?

I am new to the topic, and would like to avoid making beginners’ mistakes or add too complicated protocols to our tech stack.

2

Answers


  1. Short answer: You cant. Everything can be faked by i.e. curl and some scripting.

    Slightly longer:
    You can make it harder. Non browser clients have to implement everything you do to authenticate your app (like client side certificates and Signet requests) forcing them to reverse engineer every obfuscation you do.

    The low hanging fruit is to use CORS and set the Access Allow Origin Header to your domain. Browsers will respect your setting and wont allow requests to your api (they do an options request to determine that.)

    But then again a non official client could just use a proxy.

    Login or Signup to reply.
  2. You can’t be 100% sure that the given header data from the client is true. It’s more about honesty and less about security. (“It’s a feature – not a bug.”)

    Rather think about what could happen if someone uses your API in a malicious way (DDoS or data leak)? And how would he use it? There are probably patterns to recognize an attacker (like an unusual amount of requests).

    After you analyzed this situation, you can find more information here about the right approach to secure your API: https://www.incapsula.com/blog/best-practices-for-securing-your-api.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search