-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
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
Warn when cookie domain is set to an IP #2105
Conversation
@@ -958,3 +958,33 @@ def total_seconds(td): | |||
:rtype: int | |||
""" | |||
return td.days * 60 * 60 * 24 + td.seconds | |||
|
|||
def is_IP(string, var_name): |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
@@ -332,6 +332,7 @@ def open_session(self, app, request): | |||
|
|||
def save_session(self, app, session, response): | |||
domain = self.get_cookie_domain(app) | |||
is_IP(domain, "SESSION_COOKIE_DOMAIN") |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
I think instead of string operations the proper way to check whether it's an IP is using Something like this: for family in (socket.AF_INET, socket.AF_INET6):
try:
socket.inet_pton(family, ip)
except socket.error:
pass
else:
return True
return False |
@ThiefMaster What should be the category of the warning message? |
maybe RuntimeWarning... I'd check if Flask uses any other warnings (that are not deprecation-related) and possibly use the same type Also, tests are failing since you don't handle the case where the domain is unset, i.e. |
@ThiefMaster How can I get the socket of the session when I call the function is_ip() in the save_session() function? |
It's a function from python's |
@@ -332,7 +332,8 @@ def open_session(self, app, request): | |||
|
|||
def save_session(self, app, session, response): | |||
domain = self.get_cookie_domain(app) | |||
is_IP(domain, "SESSION_COOKIE_DOMAIN") | |||
if domain != None: |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
@@ -332,6 +332,8 @@ def open_session(self, app, request): | |||
|
|||
def save_session(self, app, session, response): | |||
domain = self.get_cookie_domain(app) | |||
if domain != None: | |||
is_ip(domain, "SESSION_COOKIE_DOMAIN", self) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
@ThiefMaster Sorry for that, in my last commit all the unit tests are passing. I also did the changes you asked for. |
@@ -332,6 +333,9 @@ def open_session(self, app, request): | |||
|
|||
def save_session(self, app, session, response): | |||
domain = self.get_cookie_domain(app) | |||
if domain is not None: |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
@@ -332,6 +333,9 @@ def open_session(self, app, request): | |||
|
|||
def save_session(self, app, session, response): | |||
domain = self.get_cookie_domain(app) | |||
if domain is not None: | |||
if is_ip(domain): | |||
warnings.warn("IP introduced in SESSION_COOKIE_DOMAIN", RuntimeWarning) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
@untitaker can you make a decision on this? |
I think the code is fine except for my review comments.
…On Thu, May 11, 2017 at 10:35:23PM -0700, David Lord wrote:
@untitaker can you make a decision on this?
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#2105 (comment)
|
Setting |
I don't like running |
Continued in #2282. |
Possible solution for issue #2007, it gives a warning message when an IP is set as SESSION_COOKIE_DOMAIN as user untitaker asked us to do, SERVER_DOMAIN isn't checked because he didn't remembered why it was needed, but the function is_IP in /flask/helpers is prepared to it. If you have any doubt feel free to ask.