I am making a Django app and I wish to enhance the security as well as limit users by making sure only clients only from one IP (say a shared VPN) can access it. I plan to host the app on a PaaS like Digital Ocean App Platform or Heroku.
How can I limit the client IP through:
- Django, to prevent other users from accessing the app, and
- The PaaS, so that potential attackers don't have access to the platform in the first place? (Hopefully some PaaS has this optiont)
I'm not sure about option 2, but for option 1 the best way would be to add middleware which will deny access if the IP is not recognized. Something like this should work:
Then the last step would be to add the middleware in the
settings.py