IMHO , although you can easily achieve the expected result using the above solution, this problem should be handled at the Network level of the operating system .. p>
To block / allow traffic from any source to a specific port on your server, this task is for the operating system firewall. Packets and their sources (IP addresses) must be processed at the network level in your operating system in kernel land without sending your application. If your server does not have a firewall, you must configure it to protect your server, even if your server is not already in the Production section.
Here's an example of a thought: given that the packages that arrive on your server, firstly, go through the analysis of the kernel of your operating system (suppose you are using a Unix-like or GNU / Linux-compatible OS), you can reject / allow incoming connecting to the network layer with Kernel Land using packet filtering software such as Netfilter , which is typically managed using IPTABLES .
Here is the Netfiler rule that suits you:
/sbin/iptables -A INPUT -s ! your_ip_address
- All traffic arriving at port 80 will be deleted, EXCEPTION for connections originating from your_ip_address .
The principle of filtering / blocking incoming connections / packets at the network level of the operating system is somewhat applied to Microsoft OS, but I'm not sure. I have never studied how Windows Firewall works with packet filtering, but there are good chances that it works in a very similar way.
So here is the last thought:
Packages must be processed at the network level of your operating system. Do not let packages access your application: it is safer and distributes the work to the necessary sides of your system.
The Linux kernel and its modules (Netfilter) are much more reliable, competent, and effective in treating such problems than Flask.
Keep in mind this good practice;).
ivanleoncz
source share