mirror of
https://github.com/ansible/awx.git
synced 2026-02-28 16:28:43 -03:30
slightly refactor origin validity checks
This commit is contained in:
@@ -27,7 +27,8 @@ def origin_is_valid(message, trusted_values):
|
|||||||
client = urlparse(origin)
|
client = urlparse(origin)
|
||||||
trusted = urlparse(trusted)
|
trusted = urlparse(trusted)
|
||||||
except (AttributeError, ValueError):
|
except (AttributeError, ValueError):
|
||||||
# if we can't parse the origin header, fall back to the else block
|
# if we can't parse a hostname, consider it invalid and try the
|
||||||
|
# next one
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
# if we _can_ parse the origin header, verify that it's trusted
|
# if we _can_ parse the origin header, verify that it's trusted
|
||||||
@@ -36,15 +37,13 @@ def origin_is_valid(message, trusted_values):
|
|||||||
is_same_domain(client.netloc, trusted.netloc)
|
is_same_domain(client.netloc, trusted.netloc)
|
||||||
):
|
):
|
||||||
# the provided Origin matches at least _one_ whitelisted host,
|
# the provided Origin matches at least _one_ whitelisted host,
|
||||||
# break out and accept the connection
|
# return True
|
||||||
break
|
return True
|
||||||
else:
|
logger.error((
|
||||||
logger.error((
|
"ws:// origin header mismatch {} not in {}; consider adding {} to "
|
||||||
"ws:// origin header mismatch {} not in {}; consider adding {} to "
|
"settings.WEBSOCKET_ORIGIN_WHITELIST if it's a trusted host."
|
||||||
"settings.WEBSOCKET_ORIGIN_WHITELIST if it's a trusted host."
|
).format(origin, trusted_values, origin))
|
||||||
).format(origin, trusted_values, origin))
|
return False
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user