feat: remove enterprise dashboard context imports (ENT-11569)#38094
feat: remove enterprise dashboard context imports (ENT-11569)#38094
Conversation
| return redirect(settings.AUTHN_MICROFRONTEND_URL + url_path) | ||
|
|
||
| response = redirect(redirect_url) if redirect_url and is_enterprise_learner(request.user) else redirect('dashboard') | ||
| response = redirect(redirect_url) if redirect_url else redirect('dashboard') |
Check warning
Code scanning / CodeQL
URL redirection from remote source Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
To fix this without changing intended functionality, add a final allowlist-style safety validation for redirect_url in activate_account before it is used in redirect(...). If the URL is not safe, fall back to dashboard behavior (existing default). Use Django’s built-in url_has_allowed_host_and_scheme, allowing only the current host and requiring HTTPS according to request security.
Best single change:
- File:
common/djangoapps/student/views/management.py - Region:
activate_account, around lines 687–709 (whereredirect_urlis set and consumed). - Edits needed:
- Add import:
from django.utils.http import url_has_allowed_host_and_scheme - After computing
redirect_url, validate it:- If present and unsafe, set
redirect_url = None
- If present and unsafe, set
- Keep existing logic and fallback
redirect('dashboard')unchanged.
- Add import:
This preserves behavior for legitimate internal redirects and blocks untrusted external targets.
| @@ -24,6 +24,7 @@ | ||
| from django.shortcuts import redirect | ||
| from django.template.context_processors import csrf | ||
| from django.urls import reverse | ||
| from django.utils.http import url_has_allowed_host_and_scheme | ||
| from django.utils.translation import gettext as _ | ||
| from django.views.decorators.csrf import ( # pylint: disable=unused-import # noqa: F401 | ||
| csrf_exempt, | ||
| @@ -698,6 +699,13 @@ | ||
| ): | ||
| redirect_url = get_redirect_url_with_host(root_login_url, redirect_to) | ||
|
|
||
| if redirect_url and not url_has_allowed_host_and_scheme( | ||
| redirect_url, | ||
| allowed_hosts={request.get_host()}, | ||
| require_https=request.is_secure(), | ||
| ): | ||
| redirect_url = None | ||
|
|
||
| if should_redirect_to_authn_microfrontend() and not request.user.is_authenticated: | ||
| params = {'account_activation_status': activation_message_type} | ||
| if redirect_url: |
87089ed to
4637f70
Compare
pwnage101
left a comment
There was a problem hiding this comment.
Note for implementer/reviewer: looks like isort got ran with the wrong parameters. at least fix that.
325efef to
644789f
Compare
2e22c20 to
aabafbc
Compare
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
02fafbf to
c0912bf
Compare
865906c to
646712c
Compare
646712c to
6ef4473
Compare
96c6b3b to
aa08351
Compare
feat: remove enterprise dashboard context imports (ENT-11569)
ENT-11569