mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
Check inbound sms IP address stage 1
IP address checked
This commit is contained in:
@@ -116,7 +116,7 @@ def register_blueprint(application):
|
|||||||
ses_callback_blueprint.before_request(requires_no_auth)
|
ses_callback_blueprint.before_request(requires_no_auth)
|
||||||
application.register_blueprint(ses_callback_blueprint)
|
application.register_blueprint(ses_callback_blueprint)
|
||||||
|
|
||||||
sms_callback_blueprint.before_request(requires_no_auth)
|
sms_callback_blueprint.before_request(restrict_ip_sms)
|
||||||
application.register_blueprint(sms_callback_blueprint)
|
application.register_blueprint(sms_callback_blueprint)
|
||||||
|
|
||||||
receive_notifications_blueprint.before_request(restrict_ip_sms)
|
receive_notifications_blueprint.before_request(restrict_ip_sms)
|
||||||
|
|||||||
@@ -45,16 +45,17 @@ def requires_no_auth():
|
|||||||
|
|
||||||
|
|
||||||
def restrict_ip_sms():
|
def restrict_ip_sms():
|
||||||
'''
|
ip = ''
|
||||||
ip_addr = jsonify({'remote_addr': request.remote_addr,
|
if request.headers.getlist("X-Forwarded-For"):
|
||||||
'X-Forwarded_FOR': request.headers.getlist('X-Forwarded-For'),
|
ip = request.headers.getlist("X-Forwarded-For")[0]
|
||||||
'X_Real-Ip': request.headers.getlist('X-Real-Ip')})
|
|
||||||
'''
|
|
||||||
current_app.logger.info("Inbound sms ip addresses remote_addr = {}, "
|
|
||||||
"X-Forwarded_FOR = {}".format(request.remote_addr,
|
|
||||||
request.headers.getlist('X-Forwarded-For')))
|
|
||||||
|
|
||||||
return
|
if ip in current_app.config.get('ALLOW_IP_INBOUND_SMS'):
|
||||||
|
current_app.logger.info("Inbound sms ip addresses {} passed ".format(ip))
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
current_app.logger.info("Inbound sms ip addresses {} blocked ".format(ip))
|
||||||
|
return
|
||||||
|
# raise AuthError('Unknown source IP address from the SMS provider', 403)
|
||||||
|
|
||||||
|
|
||||||
def requires_admin_auth():
|
def requires_admin_auth():
|
||||||
|
|||||||
@@ -262,6 +262,9 @@ class Config(object):
|
|||||||
|
|
||||||
FREE_SMS_TIER_FRAGMENT_COUNT = 250000
|
FREE_SMS_TIER_FRAGMENT_COUNT = 250000
|
||||||
|
|
||||||
|
ALLOW_IP_INBOUND_SMS = []
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
######################
|
######################
|
||||||
# Config overrides ###
|
# Config overrides ###
|
||||||
|
|||||||
Reference in New Issue
Block a user