Skip to content

Commit

Permalink
Used a different name for the URL redirection param
Browse files Browse the repository at this point in the history
Trac itself uses `referer`, so this change makes it easier
to integrate with some other Trac functionalities.
  • Loading branch information
bmispelon committed Jun 29, 2024
1 parent 93bbd0b commit 75fe130
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions DjangoPlugin/tracdjangoplugin/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def process_request(self, req):
def do_get(self, req):
return "plainlogin.html", {
"form": AuthenticationForm(),
"next": req.args.get("next", ""),
"referer": req.args.get("referer", ""),
}

def do_post(self, req):
Expand All @@ -132,11 +132,11 @@ def do_post(self, req):
req.environ["REMOTE_USER"] = form.get_user().username
LoginModule(self.compmgr)._do_login(req)
req.redirect(self._get_safe_redirect_url(req))
return "plainlogin.html", {"form": form, "next": req.args.get("next", "")}
return "plainlogin.html", {"form": form, "referer": req.args.get("referer", "")}

def _get_safe_redirect_url(self, req):
host = urlparse(req.base_url).hostname
redirect_url = iri_to_uri(req.args.get("next", ""))
redirect_url = iri_to_uri(req.args.get("referer", ""))

if not redirect_url:
redirect_url = settings.LOGIN_REDIRECT_URL
Expand Down
6 changes: 3 additions & 3 deletions DjangoPlugin/tracdjangoplugin/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_login_valid_with_custom_redirection(self):
username="test",
password="test",
check_redirect="/test",
extra_data={"next": "/test"},
extra_data={"referer": "/test"},
)

def test_login_valid_with_custom_redirection_with_hostname(self):
Expand All @@ -83,7 +83,7 @@ def test_login_valid_with_custom_redirection_with_hostname(self):
username="test",
password="test",
check_redirect="http://localhost/test",
extra_data={"next": "http://localhost/test"},
extra_data={"referer": "http://localhost/test"},
)

def test_login_valid_with_malicious_redirection(self):
Expand All @@ -108,7 +108,7 @@ def test_login_valid_with_malicious_redirection(self):
username="test",
password="test",
check_redirect="http://localhost/test",
extra_data={"next": redirect_url},
extra_data={"referer": redirect_url},
)

def assertLoginFails(self, username, password, error_message=None):
Expand Down
2 changes: 1 addition & 1 deletion trac-env/templates/django_theme.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</form>
</li>
# else
<li><a href="/login?next=${req.path_info|urlencode()}">Login</a></li>
<li><a href="/login?referer=${req.path_info|urlencode()}">Login</a></li>
# endif
<li><a href="${req.href.prefs()}">Preferences</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion trac-env/templates/plainlogin.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h2>Log in with your DjangoProject account</h2>
<p>
<button type="submit">Log in with DjangoProject</button>
<input type="hidden" name="__FORM_TOKEN" value="${req.form_token}">{# Trac's CSRF protection #}
<input type="hidden" name="next" value="${next|default('/')}">
<input type="hidden" name="referer" value="${referer|default('/')}">
</p>
</form>
</section>
Expand Down

0 comments on commit 75fe130

Please sign in to comment.