Skip to content

feat: remove enterprise dashboard context imports (ENT-11569)#38094

Open
pwnage101 wants to merge 2 commits intomasterfrom
pwnage101/ENT-11569
Open

feat: remove enterprise dashboard context imports (ENT-11569)#38094
pwnage101 wants to merge 2 commits intomasterfrom
pwnage101/ENT-11569

Conversation

@pwnage101
Copy link
Copy Markdown
Contributor

feat: remove enterprise dashboard context imports (ENT-11569)

ENT-11569

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

Untrusted URL redirection depends on a
user-provided value
.

Copilot Autofix

AI 3 days ago

Add an explicit safety validation immediately before the redirect sink in activate_account in common/djangoapps/student/views/management.py.

Best fix:

  1. Import Django’s built-in validator:
    • from django.utils.http import url_has_allowed_host_and_scheme
  2. Before response = redirect(redirect_url) if redirect_url else redirect('dashboard'), validate redirect_url against allowed hosts and HTTPS policy:
    • Allowed hosts should include current host (request.get_host()) and optionally configured LMS host.
    • Require HTTPS when request is secure.
  3. If validation fails, set redirect_url = None so the existing fallback redirect('dashboard') is used.

This keeps existing functionality for valid internal redirects while guaranteeing a safe fallback when malformed/external URLs slip through.

Suggested changeset 1
common/djangoapps/student/views/management.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/common/djangoapps/student/views/management.py b/common/djangoapps/student/views/management.py
--- a/common/djangoapps/student/views/management.py
+++ b/common/djangoapps/student/views/management.py
@@ -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 ensure_csrf_cookie  # lint-amnesty, pylint: disable=unused-import  # noqa: F401
 from django.views.decorators.http import (  # lint-amnesty, pylint: disable=unused-import
@@ -702,6 +703,13 @@
         url_path = '/login?{}'.format(urllib.parse.urlencode(params))  # noqa: UP032
         return redirect(settings.AUTHN_MICROFRONTEND_URL + url_path)
 
+    if redirect_url and not url_has_allowed_host_and_scheme(
+        url=redirect_url,
+        allowed_hosts={request.get_host()},
+        require_https=request.is_secure(),
+    ):
+        redirect_url = None
+
     response = redirect(redirect_url) if redirect_url else redirect('dashboard')
     if show_account_activation_popup:
         response.delete_cookie(
EOF
@@ -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 ensure_csrf_cookie # lint-amnesty, pylint: disable=unused-import # noqa: F401
from django.views.decorators.http import ( # lint-amnesty, pylint: disable=unused-import
@@ -702,6 +703,13 @@
url_path = '/login?{}'.format(urllib.parse.urlencode(params)) # noqa: UP032
return redirect(settings.AUTHN_MICROFRONTEND_URL + url_path)

if redirect_url and not url_has_allowed_host_and_scheme(
url=redirect_url,
allowed_hosts={request.get_host()},
require_https=request.is_secure(),
):
redirect_url = None

response = redirect(redirect_url) if redirect_url else redirect('dashboard')
if show_account_activation_popup:
response.delete_cookie(
Copilot is powered by AI and may make mistakes. Always verify output.
@pwnage101 pwnage101 force-pushed the pwnage101/ENT-11569 branch from 87089ed to 4637f70 Compare March 4, 2026 21:58
@pwnage101 pwnage101 marked this pull request as draft March 5, 2026 00:22
Copy link
Copy Markdown
Contributor Author

@pwnage101 pwnage101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for implementer/reviewer: looks like isort got ran with the wrong parameters. at least fix that.

@pwnage101 pwnage101 added the enterprise An enterprise-related change label Mar 18, 2026
@kiram15 kiram15 force-pushed the pwnage101/ENT-11569 branch 2 times, most recently from 325efef to 644789f Compare April 20, 2026 21:22
@kiram15 kiram15 marked this pull request as ready for review April 20, 2026 21:51
@@ -802,7 +793,7 @@ def student_dashboard(request): # lint-amnesty, pylint: disable=too-many-statem
'urls': urls,
'programs_data': programs_data,
'enterprise_message': enterprise_message,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I remove enterprise_message entirely?

@kiram15 kiram15 force-pushed the pwnage101/ENT-11569 branch from 644789f to 3542e01 Compare April 23, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enterprise An enterprise-related change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants