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
4fb510fd
Kaydet (Commit)
4fb510fd
authored
Eki 18, 2012
tarafından
Preston Holmes
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added missed poisoned host header tests
üst
0775ab29
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
0 deletions
+65
-0
tests.py
tests/regressiontests/requests/tests.py
+65
-0
No files found.
tests/regressiontests/requests/tests.py
Dosyayı görüntüle @
4fb510fd
...
...
@@ -6,6 +6,7 @@ from datetime import datetime, timedelta
from
io
import
BytesIO
from
django.conf
import
settings
from
django.core.exceptions
import
SuspiciousOperation
from
django.core.handlers.wsgi
import
WSGIRequest
,
LimitedStream
from
django.http
import
HttpRequest
,
HttpResponse
,
parse_cookie
,
build_request_repr
,
UnreadablePostError
from
django.test.utils
import
str_prefix
...
...
@@ -109,6 +110,38 @@ class RequestsTests(unittest.TestCase):
}
self
.
assertEqual
(
request
.
get_host
(),
'internal.com:8042'
)
# Poisoned host headers are rejected as suspicious
legit_hosts
=
[
'example.com'
,
'example.com:80'
,
'12.34.56.78'
,
'12.34.56.78:443'
,
'[2001:19f0:feee::dead:beef:cafe]'
,
'[2001:19f0:feee::dead:beef:cafe]:8080'
,
]
poisoned_hosts
=
[
'example.com@evil.tld'
,
'example.com:dr.frankenstein@evil.tld'
,
'example.com:someone@somestie.com:80'
,
'example.com:80/badpath'
]
for
host
in
legit_hosts
:
request
=
HttpRequest
()
request
.
META
=
{
'HTTP_HOST'
:
host
,
}
request
.
get_host
()
for
host
in
poisoned_hosts
:
with
self
.
assertRaises
(
SuspiciousOperation
):
request
=
HttpRequest
()
request
.
META
=
{
'HTTP_HOST'
:
host
,
}
request
.
get_host
()
finally
:
settings
.
USE_X_FORWARDED_HOST
=
old_USE_X_FORWARDED_HOST
...
...
@@ -153,6 +186,38 @@ class RequestsTests(unittest.TestCase):
}
self
.
assertEqual
(
request
.
get_host
(),
'internal.com:8042'
)
# Poisoned host headers are rejected as suspicious
legit_hosts
=
[
'example.com'
,
'example.com:80'
,
'12.34.56.78'
,
'12.34.56.78:443'
,
'[2001:19f0:feee::dead:beef:cafe]'
,
'[2001:19f0:feee::dead:beef:cafe]:8080'
,
]
poisoned_hosts
=
[
'example.com@evil.tld'
,
'example.com:dr.frankenstein@evil.tld'
,
'example.com:dr.frankenstein@evil.tld:80'
,
'example.com:80/badpath'
]
for
host
in
legit_hosts
:
request
=
HttpRequest
()
request
.
META
=
{
'HTTP_HOST'
:
host
,
}
request
.
get_host
()
for
host
in
poisoned_hosts
:
with
self
.
assertRaises
(
SuspiciousOperation
):
request
=
HttpRequest
()
request
.
META
=
{
'HTTP_HOST'
:
host
,
}
request
.
get_host
()
finally
:
settings
.
USE_X_FORWARDED_HOST
=
old_USE_X_FORWARDED_HOST
...
...
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