Skip to content

Commit 2097f46

Browse files
bmispelonfelixxm
authored andcommitted
Added more tests for redirection validation.
1 parent 74fdce6 commit 2097f46

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

DjangoPlugin/tracdjangoplugin/tests.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,27 @@ def test_login_valid_with_custom_redirection_with_hostname(self):
8585
def test_login_valid_with_malicious_redirection(self):
8686
self.env.config.set("trac", "base_url", "http://localhost")
8787
User.objects.create_user(username="test", password="test")
88-
with self.settings(LOGIN_REDIRECT_URL="/test"):
89-
self.assertLoginSucceeds(
90-
username="test",
91-
password="test",
92-
check_redirect="http://localhost/test",
93-
extra_data={"next": "http://example.com/evil"},
94-
)
88+
89+
# adapted from django/tests/auth_tests/test_views.py
90+
for redirect_url in [
91+
"http://example.com",
92+
"http://example.com/evil",
93+
"http:///example.com",
94+
"https://example.com",
95+
"ftp://example.com",
96+
"///example.com",
97+
"//example.com",
98+
'javascript:alert("XSS")',
99+
]:
100+
with self.subTest(url=redirect_url), self.settings(
101+
LOGIN_REDIRECT_URL="/test"
102+
):
103+
self.assertLoginSucceeds(
104+
username="test",
105+
password="test",
106+
check_redirect="http://localhost/test",
107+
extra_data={"next": redirect_url},
108+
)
95109

96110
def assertLoginFails(self, username, password, error_message=None):
97111
if error_message is None:

0 commit comments

Comments
 (0)