@@ -117,6 +117,11 @@ def test_is_safe_url(self):
117
117
'javascript:alert("XSS")' ,
118
118
'\n javascript:alert(x)' ,
119
119
'\x08 //example.com' ,
120
+ r'http://otherserver\@example.com' ,
121
+ r'http:\\testserver\@example.com' ,
122
+ r'http://testserver\me:[email protected] ' ,
123
+ r'http://testserver\@example.com' ,
124
+ r'http:\\testserver\confirm\[email protected] ' ,
120
125
'\n ' ):
121
126
self .assertFalse (http .is_safe_url (bad_url , host = 'testserver' ), "%s should be blocked" % bad_url )
122
127
for good_url in ('/view/?param=http://example.com' ,
@@ -126,8 +131,15 @@ def test_is_safe_url(self):
126
131
'https://testserver/' ,
127
132
'HTTPS://testserver/' ,
128
133
'//testserver/' ,
134
+ 'http://testserver/[email protected] ' ,
129
135
'/url%20with%20spaces/' ):
130
136
self .assertTrue (http .is_safe_url (good_url , host = 'testserver' ), "%s should be allowed" % good_url )
137
+ # Valid basic auth credentials are allowed.
138
+ self .assertTrue (http .is_safe_url (r'http://user:pass@testserver/' , host = 'user:pass@testserver' ))
139
+ # A path without host is allowed.
140
+ self .
assertTrue (
http .
is_safe_url (
'/confirm/[email protected] ' ))
141
+ # Basic auth without host is not allowed.
142
+ self .assertFalse (http .is_safe_url (r'http://testserver\@example.com' ))
131
143
132
144
def test_urlsafe_base64_roundtrip (self ):
133
145
bytestring = b'foo'
0 commit comments