Search code examples
webflaskportforwarding

Does port forwarding pose any security issues?


Ok so i'm pretty newbie to port forwarding and web development in general. I want to set up a flask website that only a few friends and I access occasionally and I understand that to host it on my own computer and for them to access it I must port forward, however does port forwarding pose and security issues for the rest of my computer, and if so how can I get around this?


Solution

  • There's nothing inherently dangerous about directly exposing your computer to the internet via a port; we open and close ports all the time with firewalls. The danger lies in the application which the port forwards to, in your case, your local Flask application. If there is a flaw in your application which opens an attack surface (choose literally any of rogue file upload, SQL injection, remote code execution, etc.) then a theoretical attacker can potentially "walk right in the front door" and do whatever they like on your local machine. The weak link in the chain is not the open port, it is an exploitable flaw in your application.

    While it is possible to host an application on your local machine which is available to the internet (many of us do this all the time for testing purposes using tools like ngrok, etc.), this is not recommended. Find a cloud provider and host your application on a virtual server for $5/month or less. Using modern deployment and hosting methods do not automatically prevent any sort of attack or breach, but they certainly make it easier to mitigate an incident - destroy the container and boot a new one. If you dislike the idea of wiping your local machine and starting over every time you suspect a breach, then hosting online is well worth the money paid.