Skip to content

Commit b8399c9

Browse files
committed
Fix XSS in the idp url parameter
1 parent b835031 commit b8399c9

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

djangosaml2/tests/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ def test_unknown_idp(self):
308308
metadata_file="remote_metadata_three_idps.xml",
309309
)
310310

311-
response = self.client.get(reverse("saml2_login") + "?idp=https://unknown.org")
312-
self.assertEqual(response.status_code, 403)
311+
response = self.client.get(reverse("saml2_login") + "?idp=<b>https://unknown.org</b>")
312+
self.assertContains(response, "&lt;b&gt;https://unknown.org&lt;/b&gt;", status_code=403)
313313

314314
def test_login_authn_context(self):
315315
sp_kwargs = {

djangosaml2/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from django.template import TemplateDoesNotExist
3131
from django.urls import reverse
3232
from django.utils.decorators import method_decorator
33+
from django.utils.html import escape
3334
from django.utils.module_loading import import_string
3435
from django.utils.translation import gettext_lazy as _
3536
from django.views.decorators.csrf import csrf_exempt
@@ -152,7 +153,7 @@ def get_next_path(self, request: HttpRequest) -> str:
152153
return next_path
153154

154155
def unknown_idp(self, request, idp):
155-
msg = f"Error: IdP EntityID {idp} was not found in metadata"
156+
msg = f"Error: IdP EntityID {escape(idp)} was not found in metadata"
156157
logger.error(msg)
157158
return HttpResponse(msg.format("Please contact technical support."), status=403)
158159

0 commit comments

Comments
 (0)