Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
c083e381
Kaydet (Commit)
c083e381
authored
Nis 20, 2014
tarafından
Aymeric Augustin
Kaydeden (comit)
Tim Graham
Nis 21, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Prevented leaking the CSRF token through caching.
This is a security fix. Disclosure will follow shortly.
üst
8b93b314
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
1 deletion
+36
-1
cache.py
django/middleware/cache.py
+9
-1
tests.py
tests/cache/tests.py
+27
-0
No files found.
django/middleware/cache.py
Dosyayı görüntüle @
c083e381
...
...
@@ -45,7 +45,8 @@ More details about how the caching works:
from
django.conf
import
settings
from
django.core.cache
import
caches
,
DEFAULT_CACHE_ALIAS
from
django.utils.cache
import
get_cache_key
,
learn_cache_key
,
patch_response_headers
,
get_max_age
from
django.utils.cache
import
(
get_cache_key
,
get_max_age
,
has_vary_header
,
learn_cache_key
,
patch_response_headers
)
class
UpdateCacheMiddleware
(
object
):
...
...
@@ -77,8 +78,15 @@ class UpdateCacheMiddleware(object):
if
not
self
.
_should_update_cache
(
request
,
response
):
# We don't need to update the cache, just return.
return
response
if
response
.
streaming
or
response
.
status_code
!=
200
:
return
response
# Don't cache responses that set a user-specific (and maybe security
# sensitive) cookie in response to a cookie-less request.
if
not
request
.
COOKIES
and
response
.
cookies
and
has_vary_header
(
response
,
'Cookie'
):
return
response
# Try to get the timeout from the "max-age" section of the "Cache-
# Control" header before reverting to using the default cache_timeout
# length.
...
...
tests/cache/tests.py
Dosyayı görüntüle @
c083e381
...
...
@@ -18,11 +18,13 @@ from django.conf import settings
from
django.core
import
management
from
django.core.cache
import
(
cache
,
caches
,
CacheKeyWarning
,
InvalidCacheBackendError
,
DEFAULT_CACHE_ALIAS
)
from
django.core.context_processors
import
csrf
from
django.db
import
connection
,
connections
,
router
,
transaction
from
django.core.cache.utils
import
make_template_fragment_key
from
django.http
import
HttpResponse
,
StreamingHttpResponse
from
django.middleware.cache
import
(
FetchFromCacheMiddleware
,
UpdateCacheMiddleware
,
CacheMiddleware
)
from
django.middleware.csrf
import
CsrfViewMiddleware
from
django.template
import
Template
from
django.template.response
import
TemplateResponse
from
django.test
import
TestCase
,
TransactionTestCase
,
RequestFactory
,
override_settings
...
...
@@ -1741,6 +1743,10 @@ def hello_world_view(request, value):
return
HttpResponse
(
'Hello World
%
s'
%
value
)
def
csrf_view
(
request
):
return
HttpResponse
(
csrf
(
request
)[
'csrf_token'
])
@override_settings
(
CACHE_MIDDLEWARE_ALIAS
=
'other'
,
CACHE_MIDDLEWARE_KEY_PREFIX
=
'middlewareprefix'
,
...
...
@@ -1905,6 +1911,27 @@ class CacheMiddlewareTest(TestCase):
response
=
other_with_prefix_view
(
request
,
'16'
)
self
.
assertEqual
(
response
.
content
,
b
'Hello World 16'
)
def
test_sensitive_cookie_not_cached
(
self
):
"""
Django must prevent caching of responses that set a user-specific (and
maybe security sensitive) cookie in response to a cookie-less request.
"""
csrf_middleware
=
CsrfViewMiddleware
()
cache_middleware
=
CacheMiddleware
()
request
=
self
.
factory
.
get
(
'/view/'
)
self
.
assertIsNone
(
cache_middleware
.
process_request
(
request
))
csrf_middleware
.
process_view
(
request
,
csrf_view
,
(),
{})
response
=
csrf_view
(
request
)
response
=
csrf_middleware
.
process_response
(
request
,
response
)
response
=
cache_middleware
.
process_response
(
request
,
response
)
# Inserting a CSRF cookie in a cookie-less request prevented caching.
self
.
assertIsNone
(
cache_middleware
.
process_request
(
request
))
@override_settings
(
CACHE_MIDDLEWARE_KEY_PREFIX
=
'settingsprefix'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment