Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add application-level IP blocking #3625

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions webservices/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ def handle_error(error):


# api.data.gov
trusted_proxies = ('54.208.160.112', '54.208.160.151')
TRUSTED_PROXIES = ('54.208.160.112', '54.208.160.151')
BLOCKED_IPS = ('<IP ADDRESS>')
FEC_API_WHITELIST_IPS = env.get_credential('FEC_API_WHITELIST_IPS', False)


@app.before_request
def limit_remote_addr():
"""If `FEC_API_WHITELIST_IPS` is set, reject all requests that are not
Expand All @@ -145,11 +145,13 @@ def limit_remote_addr():
falses = (False, 'False', 'false', 'f')
if FEC_API_WHITELIST_IPS not in falses:
try:
*_, api_data_route, cf_route = request.access_route
*_, source_ip, api_data_route, cf_route = request.access_route
except ValueError: # Not enough routes
abort(403)
else:
if api_data_route not in trusted_proxies:
if api_data_route not in TRUSTED_PROXIES:
abort(403)
if source_ip in BLOCKED_IPS:
abort(403)


Expand Down