Skip to content

Commit

Permalink
[security] SAML login issues with csp enabled
Browse files Browse the repository at this point in the history
pysaml by default gives a template which has unsafe inline code. django saml bypasses that if we use a custom template. i have defined that custom template and added a request object.

Uses the post binding form to add nonce, if the nonce is available in the request. if csp_nonce is disabled in the setting it won't be added here.

Co-authored-by: Mohammed Tabraiz <[email protected]>
  • Loading branch information
tabraiz12 and Mohammed Tabraiz authored Jan 23, 2025
1 parent afc3806 commit 864283c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def login(request,
saml_request = base64.b64encode(binary_type(request_xml))

http_response = render(request, post_binding_form_template, {
'request': request,
'target_url': location,
'params': {
'SAMLRequest': saml_request,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script type="text/javascript">
window.onload = function(){
<script type="text/javascript"{% if request.csp_nonce %} nonce="{{ request.csp_nonce }}"{% endif %}>
window.onload = function() {
document.SSO_Login.submit();
};
</script>
Expand All @@ -9,7 +9,7 @@
</p>
<form method="post" action="{{ target_url }}" name="SSO_Login">
{% for key, value in params.items %}
<input type="hidden" name="{{ key|safe }}" value="{{ value|safe }}" />
<input type="hidden" name="{{ key }}" value="{{ value }}" />
{% endfor %}
<input type="submit" value="Log in" />
</form>
</form>

0 comments on commit 864283c

Please sign in to comment.