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
7ec0fdf6
Kaydet (Commit)
7ec0fdf6
authored
Eki 21, 2017
tarafından
Tomer Chachamu
Kaydeden (comit)
Tim Graham
Şub 15, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28693 -- Fixed crash in CsrfViewMiddleware when an HTTPS request has an invalid host.
üst
ff551798
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
8 deletions
+24
-8
csrf.py
django/middleware/csrf.py
+11
-8
tests.py
tests/csrf_tests/tests.py
+13
-0
No files found.
django/middleware/csrf.py
Dosyayı görüntüle @
7ec0fdf6
...
@@ -10,7 +10,7 @@ import string
...
@@ -10,7 +10,7 @@ import string
from
urllib.parse
import
urlparse
from
urllib.parse
import
urlparse
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.exceptions
import
ImproperlyConfigured
from
django.core.exceptions
import
DisallowedHost
,
ImproperlyConfigured
from
django.urls
import
get_callable
from
django.urls
import
get_callable
from
django.utils.cache
import
patch_vary_headers
from
django.utils.cache
import
patch_vary_headers
from
django.utils.crypto
import
constant_time_compare
,
get_random_string
from
django.utils.crypto
import
constant_time_compare
,
get_random_string
...
@@ -262,14 +262,17 @@ class CsrfViewMiddleware(MiddlewareMixin):
...
@@ -262,14 +262,17 @@ class CsrfViewMiddleware(MiddlewareMixin):
if
server_port
not
in
(
'443'
,
'80'
):
if
server_port
not
in
(
'443'
,
'80'
):
good_referer
=
'
%
s:
%
s'
%
(
good_referer
,
server_port
)
good_referer
=
'
%
s:
%
s'
%
(
good_referer
,
server_port
)
else
:
else
:
# request.get_host() includes the port.
try
:
good_referer
=
request
.
get_host
()
# request.get_host() includes the port.
good_referer
=
request
.
get_host
()
# Here we generate a list of all acceptable HTTP referers,
except
DisallowedHost
:
# including the current host since that has been validated
pass
# upstream.
# Create a list of all acceptable HTTP referers, including the
# current host if it's permitted by ALLOWED_HOSTS.
good_hosts
=
list
(
settings
.
CSRF_TRUSTED_ORIGINS
)
good_hosts
=
list
(
settings
.
CSRF_TRUSTED_ORIGINS
)
good_hosts
.
append
(
good_referer
)
if
good_referer
is
not
None
:
good_hosts
.
append
(
good_referer
)
if
not
any
(
is_same_domain
(
referer
.
netloc
,
host
)
for
host
in
good_hosts
):
if
not
any
(
is_same_domain
(
referer
.
netloc
,
host
)
for
host
in
good_hosts
):
reason
=
REASON_BAD_REFERER
%
referer
.
geturl
()
reason
=
REASON_BAD_REFERER
%
referer
.
geturl
()
...
...
tests/csrf_tests/tests.py
Dosyayı görüntüle @
7ec0fdf6
...
@@ -294,6 +294,19 @@ class CsrfViewMiddlewareTestMixin:
...
@@ -294,6 +294,19 @@ class CsrfViewMiddlewareTestMixin:
status_code
=
403
,
status_code
=
403
,
)
)
def
test_https_malformed_host
(
self
):
"""
CsrfViewMiddleware generates a 403 response if it receives an HTTPS
request with a bad host.
"""
req
=
self
.
_get_GET_no_csrf_cookie_request
()
req
.
_is_secure_override
=
True
req
.
META
[
'HTTP_HOST'
]
=
'@malformed'
req
.
META
[
'HTTP_REFERER'
]
=
'https://www.evil.org/somepage'
req
.
META
[
'SERVER_PORT'
]
=
'443'
response
=
self
.
mw
.
process_view
(
req
,
token_view
,
(),
{})
self
.
assertEqual
(
response
.
status_code
,
403
)
@override_settings
(
DEBUG
=
True
)
@override_settings
(
DEBUG
=
True
)
def
test_https_malformed_referer
(
self
):
def
test_https_malformed_referer
(
self
):
"""
"""
...
...
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