Cloudflare proxy support for flask application.
It gets client ip from cloudflare headers and can allow request from cloudflare ips only. If you are behind a proxy remember to use werkzeug.middleware.proxy_fix.ProxyFix
, alternative you can override CloudflareRemote.get_remote()
in order to fetch the correct client ip for example via HTTP_X_FORWARDED_FOR.
Install flask_cloudflare_remote
using pip
:
$ pip install Flask-CloudflareRemote
import flask
from flask_cloudflare_remote import CloudflareRemote
app = Flask(__name__)
cf = CloudflareRemote()
cf.init_app(app)
CF_DOMAIN
: (default: 'www.cloudflare.com')CF_REQ_TIMEOUT
: (default: 10)CF_IPs
: (default: None) list of allowed cloudflare ipsCF_IP4_URI
: (default: '/ips-v4') ipv4 list uriCF_IP6_URI
: (default: '/ips-v6') ipv6 list uriCF_IPv6_ENABLED
: (default: False) enable ipv6CF_STRICT_ACCESS
: (default: True) return forbidden if remote ip is not in allowed listCF_OVERRIDE_REMOTE
: (default: True) override flask REMOTE_ADDR from requestCF_HDR_CLIENT_IP
: (default: 'CF-Connecting-IP') header key used for client ip
License MIT