Skip to content

Token delete formdata fix method #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 49 commits into
base: master
Choose a base branch
from

Conversation

AndreasDickow
Copy link
Contributor

Delete token used the wrong method to access formdata, I exchanged it to POST instead of GET and it fixed the error on submit

@mkalioby
Copy link
Owner

mkalioby commented Sep 5, 2021

Why the change if the AJAX is sent over GET and not POST?

{
if (res["status"] =='OK')
$("#res").html("<div class='alert alert-success'>Registered Successfully, <a href='"+formData.get('redirect')+"'> "+formData.get('success')+"</a></div>")
else
Copy link
Owner

Choose a reason for hiding this comment

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

Dont you need these with {% trans %}?



}, function(reason) {
$("#res").html("<div class='alert alert-danger'>Registeration Failed as " +reason +", <a href='javascript:void(0)' onclick='begin_reg()'> try again </a> or <a href='"+formData.get('home')+"'> Go to Security Home</a></div>")
Copy link
Owner

Choose a reason for hiding this comment

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

This as well?

}
else {
$("#msgdiv").addClass("alert alert-danger").removeClass("alert-success")
$("#msgdiv").html("Verification Failed as " + res.message + ", <a href='javascript:void(0)' onclick='authen())'> try again</a> or <a href='javascript:void(0)' onclick='history.back()'> Go Back</a>")
Copy link
Owner

Choose a reason for hiding this comment

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

This too?

}
else if(formData.get('mode') === 'recheck') {
$.ajax({
"url":"{% url 'u2f_recheck' %}",
Copy link
Owner

Choose a reason for hiding this comment

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

This won’t work under {% static %}

function deleteKey(id,name,confirm_url)
{
$("#modal-title").html("Confirm Delete")
$("#modal-body").html("Are you sure you want to delete '"+name+"'? you may lose access to your system if this your only 2FA.");
Copy link
Owner

Choose a reason for hiding this comment

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

Shall be translated, isn’t it?

window.mfa_success_function=success_func;
window.mfa_failed_function=fail_func;
$.ajax({
"url":"{% url 'mfa_recheck' %}",
Copy link
Owner

Choose a reason for hiding this comment

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

Wont work with static

}
else
{
$("#modal-title").html("Recheck Indentity")
Copy link
Owner

Choose a reason for hiding this comment

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

Shall be translated, isn’t it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, I'm not done yet, my intention was to do internationalization and be CSP conform without inline javascript or css. I will provide further updates soon.

Copy link
Owner

@mkalioby mkalioby left a comment

Choose a reason for hiding this comment

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

Thanks for the effort, please consider the comment

@mkalioby
Copy link
Owner

Hello,

Any updates about this PR.

@AndreasDickow
Copy link
Contributor Author

Still on it, to aquire strict CSP rules conformity, we have to rewrite some javascript.

@mkalioby
Copy link
Owner

Ok, can you share the rules and i can work with you on them, thanks for your help

Copy link
Owner

@mkalioby mkalioby left a comment

Choose a reason for hiding this comment

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

Did you test this version? as it wont work as the AJAX gets the URLs through a {%url%} tag which wont work with static JS.

@AndreasDickow
Copy link
Contributor Author

I now stripped as recomended all url tags from js files see my latest implemenetation master...AndreasDickow:master. Can you please review the code?

@AndreasDickow
Copy link
Contributor Author

We have now included translation tags for international usage and added a german translation of Status Messages. Additional the library is now conform with strict CSP settings not allowing javascript and style in html files.

@lvanbuiten
Copy link

Any updates on the CSP compliant part? I would like to prevent unsafe-hashes or any other inline allowance in our solution.

@mkalioby
Copy link
Owner

Added to version 3.1 and the beta is avaliable on pypi
https://pypi.org/project/django-mfa2/3.1b1/
@lvanbuiten Please give it a go thanks.

@lvanbuiten
Copy link

lvanbuiten commented Apr 17, 2025

@mkalioby Thanks I will.

[> AndreasDickow](#53 (comment))

But i was more referring to the work @AndreasDickow did on getting the templates CSP compliant. In short, don't include inline CSS or Script directly in the HTML files, but everything should be in a separate (css/js) file. Therefore the browser can trust the source of origin.

Alternatively, but I don't have much experience with it other than I know we use it, is adding the support of django-csp where you can include the Nonce(s). I tried to include the hashes of each script, but couldn't get this to work since the mfa/templates/MFA.html includes a dynamic {{ csrf_token }} and therefore changes the hash each page reload.

If the CSP changes aren't on the roadmap yet, I could try with best effort to contribute to this.

@lvanbuiten lvanbuiten mentioned this pull request Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants