Ticket #15797: cookie_domain_validation.diff
File cookie_domain_validation.diff, 5.0 KB (added by , 14 years ago) |
---|
-
docs/topics/http/sessions.txt
435 435 436 436 The domain to use for session cookies. Set this to a string such as 437 437 ``".lawrence.com"`` (note the leading dot!) for cross-domain cookies, or use 438 ``None`` for a standard domain cookie. 438 ``None`` for a standard domain cookie. It should also have sufficient dots 439 (``.``) to ensure it will be valid and sent to the server by browsers. So 440 ``".example.com"`` or ``"example.com"`` are good but avoid ``".localhost"`` or 441 ``"localhost"``. 439 442 440 443 SESSION_COOKIE_HTTPONLY 441 444 ----------------------- -
docs/ref/settings.txt
322 322 allowing cross-subdomain requests to be exluded from the normal cross site 323 323 request forgery protection. It should be set to a string such as 324 324 ``".lawrence.com"`` to allow a POST request from a form on one subdomain to be 325 accepted by accepted by a view served from another subdomain. 325 accepted by accepted by a view served from another subdomain. It should also 326 have sufficient dots (``.``) to ensure it will be valid and sent to the server 327 by browsers. So ``".example.com"`` or ``"example.com"`` are good but avoid 328 ``".localhost"`` or ``"localhost"``. 326 329 327 330 .. setting:: CSRF_COOKIE_NAME 328 331 … … 1480 1483 1481 1484 The domain to use for session cookies. Set this to a string such as 1482 1485 ``".lawrence.com"`` for cross-domain cookies, or use ``None`` for a standard 1483 domain cookie. See the :doc:`/topics/http/sessions`. 1486 domain cookie. It should also have sufficient dots (``.``) to ensure it will be 1487 valid and sent to the server by browsers. So ``".example.com"`` or 1488 ``"example.com"`` are good but avoid ``".localhost"`` or ``"localhost"``. See 1489 the :doc:`/topics/http/sessions`. 1484 1490 1485 1491 .. setting:: SESSION_COOKIE_HTTPONLY 1486 1492 -
django/conf/__init__.py
12 12 import warnings 13 13 14 14 from django.conf import global_settings 15 from django.core.exceptions import ImproperlyConfigured 15 16 from django.utils.functional import LazyObject 16 17 from django.utils import importlib 17 18 … … 70 71 if name in ("MEDIA_URL", "STATIC_URL") and value and not value.endswith('/'): 71 72 warnings.warn('If set, %s must end with a slash' % name, 72 73 DeprecationWarning) 74 if name in ("CSRF_COOKIE_DOMAIN", "SESSION_COOKIE_DOMAIN"): 75 if value is not None: 76 if (value.startswith('.') and value.count('.') < 2 or 77 '.' not in value): 78 raise ImproperlyConfigured('If set, %s should contain ' 79 'sufficient dots (.), e.g., ".example.com" or ' 80 '"example.com"' % name) 73 81 object.__setattr__(self, name, value) 74 82 75 83 -
tests/regressiontests/settings_tests/tests.py
1 1 from django.conf import settings 2 2 from django.utils import unittest 3 3 from django.conf import settings, UserSettingsHolder, global_settings 4 from django.core.exceptions import ImproperlyConfigured 4 5 5 6 6 7 class SettingsTests(unittest.TestCase): … … 76 77 self.settings_module.MEDIA_URL = 'http://media.foo.com/stupid//' 77 78 self.assertEqual('http://media.foo.com/stupid//', 78 79 self.settings_module.MEDIA_URL) 80 81 82 class CookieDomainTests(unittest.TestCase): 83 setting_names = ('CSRF_COOKIE_DOMAIN', 'SESSION_COOKIE_DOMAIN') 84 85 def test_none(self): 86 for setting_name in self.setting_names: 87 setattr(settings, setting_name, None) 88 89 def test_empty(self): 90 for setting_name in self.setting_names: 91 self.assertRaises(ImproperlyConfigured, setattr, settings, 92 setting_name, '') 93 94 def test_startswith_dot_too_few(self): 95 for setting_name in self.setting_names: 96 self.assertRaises(ImproperlyConfigured, setattr, settings, 97 setting_name, '.localhost') 98 99 def test_startswith_dot_sufficient_dots(self): 100 for setting_name in self.setting_names: 101 setattr(settings, setting_name, '.example.com') 102 103 def test_not_startswith_dot_too_few(self): 104 for setting_name in self.setting_names: 105 self.assertRaises(ImproperlyConfigured, setattr, settings, 106 setting_name, 'localhost') 107 108 def test_not_startswith_dot_sufficient_dots(self): 109 for setting_name in self.setting_names: 110 setattr(settings, setting_name, 'example.com') 111