How to tell when a request is coming from a local https reverse proxy as opposed to directly to the http port

Viewed 23

I have a REST API flask, configured to listed on http at port 7001

I have also setup an apache as a reverse proxy to supply https

My flask is also using the ProxyFix to be able to correctly detect the incoming IP address in order to use flask.limiter

REST_API = Flask(__name__)
REST_API.wsgi_app = ProxyFix(REST_API.wsgi_app, x_for=1)

I want to reject all requests which are not coming from my reverse proxy, but rather directly to my 7001 port. Without the ProxyFix, I could do this method

@REST_API.before_request
def limit_remote_addr():
    logger.debug(request.remote_addr)
    if request.remote_addr != '127.0.0.1':
        error_msg = get_error(ServerErrors.NO_PROXY)
        abort(403, error_msg)

But now with the ProxyFix, I am always seeing the original IP.

If there a way to detect if the requestor is coming via my reverse proxy in this setup?

0 Answers
Related