Skip to content
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

Token delete formdata fix method #53

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f7d06c2
Token delete formdata fix method
AndreasDickow Aug 25, 2021
392b9ef
init internationalization and csp save templates
AndreasDickow Oct 6, 2021
7f2b9a3
fixing csp attributes and translations
AndreasDickow Mar 8, 2022
34510dd
TrustedDevices - start: Minor fixes
jmbizfac Mar 8, 2022
98982ce
Inline Styles removed from all subfiles in template folder
jmbizfac Mar 8, 2022
2c4a48d
Stylesheet imported for respective files
jmbizfac Mar 8, 2022
3e4e62a
javascript exported in own file
jmbizfac Mar 8, 2022
2d8cd96
EMAIL recheck onlicks removed
jmbizfac Mar 8, 2022
fb25e34
TOTP Add.html free of onclick events
jmbizfac Mar 11, 2022
9ec9708
All files checked for inline js
jmbizfac Mar 11, 2022
1057987
final adjustments
jmbizfac Mar 11, 2022
9152b6d
translation tags in templates
AndreasDickow Mar 19, 2022
8fe6575
code cleanup
AndreasDickow Mar 19, 2022
1800ff9
code cleanup
AndreasDickow Mar 29, 2022
9c5bda9
todo test redirect html code
AndreasDickow Mar 29, 2022
c99c697
template substitutions
AndreasDickow Mar 30, 2022
a5803d3
fix attestation privacy warning
AndreasDickow Jun 2, 2022
df2c10f
Update requirements.txt
AndreasDickow Jun 8, 2022
5b4fb11
Update setup.py
AndreasDickow Jun 8, 2022
7715b32
Update requirements.txt
AndreasDickow Jun 8, 2022
7ce386d
Update setup.py
AndreasDickow Jun 8, 2022
547c86b
Update setup.py
AndreasDickow Jun 8, 2022
d008981
Update requirements.txt
AndreasDickow Jun 8, 2022
8d75755
Update recheck.js
AndreasDickow Jun 9, 2022
1f67349
Update FIDO2.py
AndreasDickow Jun 30, 2022
419f66b
Update add.js
AndreasDickow Jun 30, 2022
92c4f02
Update setup.py
AndreasDickow Jul 4, 2022
bc4396d
Update __init__.py
AndreasDickow Jul 4, 2022
b273286
Update recheck.js
AndreasDickow Jul 5, 2022
ce0686c
Update setup.py
AndreasDickow Jul 5, 2022
9948002
Token delete formdata fix method
AndreasDickow Aug 25, 2021
35ac10c
update merge
AndreasDickow Jul 7, 2022
6ca0895
update merge
AndreasDickow Jul 7, 2022
738c8ee
update fido auth
AndreasDickow Jul 7, 2022
eb5b4d1
Update FIDO2.py
AndreasDickow Jul 7, 2022
ad063bd
update fido auth
AndreasDickow Jul 7, 2022
b7bcf35
update fido auth
AndreasDickow Jul 7, 2022
d0af4b5
update fido auth
AndreasDickow Jul 7, 2022
d400918
update fido auth
AndreasDickow Jul 7, 2022
b325ce3
update fido auth
AndreasDickow Jul 7, 2022
ff4e987
internationalization: german texts
AndreasDickow Jul 7, 2022
0db200f
internationalization: german texts
AndreasDickow Jul 7, 2022
c7cb057
internationalization: german texts
AndreasDickow Jul 7, 2022
aaf072b
internationalization: german texts
AndreasDickow Jul 7, 2022
3002d18
internationalization: german texts
AndreasDickow Jul 7, 2022
6b354b8
internationalization: german texts
AndreasDickow Jul 7, 2022
82ef89c
hide account details from attestation
AndreasDickow Jul 14, 2022
5caccca
remove unneccesary attestation
AndreasDickow Jul 20, 2022
fd78e54
fix CVE-2022-42731
AndreasDickow May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions mfa/static/mfa/css/mfa.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.alert-pr{
align-items: center;
}
.alert-pr>p.success,#res>p.success,.row>success{
color:green;
}

.panel-body>.paragraph{
padding-left: 15px;
}
.panel-body{
align-items: center;
}
#popUpModal{
top: 40px;
}
#popUpModal>.modal-dialog{
height: 80%;
width: 80%;
}
#two-factor-steps {
border: 1px solid #ccc;
border-radius: 3px;
padding: 15px;
}
#two-factor-steps>.row{
margin: 0px;
align-items: center;
}
49 changes: 49 additions & 0 deletions mfa/static/mfa/js/FIDO2/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
function begin_reg(){
var formData = new FormData($('#fido2_form'))
fetch(formData.get('begin'),{}).then(function(response) {
if(response.ok)
{
return response.arrayBuffer();
}
throw new Error('Error getting registration data!');
}).then(CBOR.decode).then(function(options) {
options.publicKey.attestation="direct"
console.log(options)

return navigator.credentials.create(options);
}).then(function(attestation) {
return fetch(formData.get('complete'), {
method: 'POST',
headers: {'Content-Type': 'application/cbor'},
body: CBOR.encode({
"attestationObject": new Uint8Array(attestation.response.attestationObject),
"clientDataJSON": new Uint8Array(attestation.response.clientDataJSON),
})
});
}).then(function(response) {

var stat = response.ok ? 'successful' : 'unsuccessful';
return response.json()
}).then(function (res)
{
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 %}?

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


}, 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?

})
}
$(document).ready(function (){
ua=new UAParser().getResult()
if (ua.browser.name == "Safari")
{
$("#res").html("<button class='btn btn-success' onclick='begin_reg()'>Start...</button>")
}
else
{
setTimeout(begin_reg, 500)
}
})
65 changes: 65 additions & 0 deletions mfa/static/mfa/js/FIDO2/recheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
function authen()
{
const begin_url = $('#begin').value;
const complete_url = $('u2f_login').attr('action');
const mode = $('u2f_login').attr('name') === 'complete'?'auth':'recheck';
fetch(begin_url, {
method: 'GET',
}).then(function(response) {
if(response.ok) return response.arrayBuffer();
throw new Error('No credential available to authenticate!');
}).then(CBOR.decode).then(function(options) {
console.log(options)
return navigator.credentials.get(options);
}).then(function(assertion) {
res=CBOR.encode({
"credentialId": new Uint8Array(assertion.rawId),
"authenticatorData": new Uint8Array(assertion.response.authenticatorData),
"clientDataJSON": new Uint8Array(assertion.response.clientDataJSON),
"signature": new Uint8Array(assertion.response.signature)
});

return fetch(complete_url, {

method: 'POST',
headers: {'Content-Type': 'application/cbor'},
body:res,

}).then(function (response) {if (response.ok) return res = response.json()}).then(function (res) {
if (res.status=="OK")
{
$("#msgdiv").addClass("alert alert-success").removeClass("alert-danger")
$("#msgdiv").html("Verified....please wait")
if(mode == "auth"){
window.location.href=res.redirect;
}
else if(mode === "recheck"){
mfa_success_function();
}

}
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?


if(mode === "recheck"){
mfa_failed_function();
}
}
})

})

}
$(document).ready(function () {
if (location.protocol != 'https:') {
$("#main_paragraph").addClass("alert alert-danger")
$("#main_paragraph").html("FIDO2 must work under secure context")
} else {
ua=new UAParser().getResult()
if (ua.browser.name == "Safari")
$("#res").html("<button class='btn btn-success' onclick='authen()'>Authenticate...</button>")
else
authen()
}
});
18 changes: 18 additions & 0 deletions mfa/static/mfa/js/U2F/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$(document).ready(function addToken() {
const form = $('#u2f_form');
var formData = new FormData(form);
data=JSON.parse(formData.get('token'));
u2f.register(data.appId,data.registerRequests,data.registeredKeys,function (response) {
$.ajax({
"url":form.attr('action'),method:"POST",
data:{"csrfmiddlewaretoken":formData.get('csrf_token'),"response":JSON.stringify(response)},
success:function (data) {
if (data == "OK")
{
alert(formData.get('success'))
window.location.href=formData.get('redirect')
}
}
})
},5000)
})
56 changes: 56 additions & 0 deletions mfa/static/mfa/js/U2F/recheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
$(document).ready(function () {
const form = $('#u2f_form');
var formData = new FormData(form);
if (location.protocol != 'https:')
{
$("#main_paragraph").addClass("alert alert-danger")
$("#main_paragraph").html(formData.get('protocol_message'))
}
else {


data = JSON.parse(formData.get('token'))
console.log(data)
u2f.sign(data.appId, data.challenge, data.registeredKeys, function (response) {
console.log(response)
if (response.hasOwnProperty("errorCode") && response.errorCode != 0 )
{
if (response.errorCode == 4)
{
alert("Invalid Security Key, this security isn't linked to your account")
}
else if (response.errorCode == 5)
{
alert("Verification Timeout, please refresh the page to try again")
}
else
{
alert("Unspecified error, please try again later or try another browser.")
}
}
else if(formData.get('mode') === 'auth')
{
$("#response").val(JSON.stringify(response))
$("#u2f_login").submit();
}
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 %}

method: "POST",
data: {"csrfmiddlewaretoken":formData.get('csrfmiddlewaretoken'),"response":JSON.stringify(response)},
success:function (data) {
if (data["recheck"]) {
mfa_success_function();
}
else {
mfa_failed_function();
}
}

})

}

}, 5000)
}
})
32 changes: 32 additions & 0 deletions mfa/static/mfa/js/delete-token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function confirmDel(id,confirm_url) {
$.ajax({
url:confirm_url,
data:{"id":id},
success:function (data) {
alert(data)
window.location.reload();
}
})
}
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?

$("#actionBtn").remove()
$("#modal-footer").prepend("<button id='actionBtn' class='btn btn-danger' onclick='confirmDel("+id+","+confirm_url+")'>Confirm Deletion</button>")
$("#popUpModal").modal()
}

function toggleKey(id,toggle_url) {
$.ajax({
url:toggle_url,
success:function (data) {
if (data == "Error")
$("#toggle_"+id).toggle()

},
error:function (data) {
$("#toggle_"+id).toggle()
}
})
}
27 changes: 27 additions & 0 deletions mfa/static/mfa/js/mfa-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
mfa_success_function=null;
mfa_failed_function=null;

function recheck_mfa(success_func,fail_func,must_mfa) {
if (!must_mfa) success_func()
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

success:function (data) {
if (data.hasOwnProperty("res")) {
if (data["res"])
success_func();
else fail_func();
}
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.

$("#modal-body").html(data["html"])
$("#popUpModal").modal()
}



}
})
}
68 changes: 13 additions & 55 deletions mfa/templates/FIDO2/Add.html
Original file line number Diff line number Diff line change
@@ -1,58 +1,10 @@
{% extends "base.html" %}
{% load static %}
{% load i18n %}
{% block head %}
<script type="application/javascript" src="{% static 'mfa/js/cbor.js'%}"></script>
<script type="application/javascript" src="{% static 'mfa/js/ua-parser.min.js'%}"></script>
<script type="application/javascript">
function begin_reg(){
fetch('{% url 'fido2_begin_reg' %}',{}).then(function(response) {
if(response.ok)
{
return response.arrayBuffer();
}
throw new Error('Error getting registration data!');
}).then(CBOR.decode).then(function(options) {
options.publicKey.attestation="direct"
console.log(options)

return navigator.credentials.create(options);
}).then(function(attestation) {
return fetch('{% url 'fido2_complete_reg' %}', {
method: 'POST',
headers: {'Content-Type': 'application/cbor'},
body: CBOR.encode({
"attestationObject": new Uint8Array(attestation.response.attestationObject),
"clientDataJSON": new Uint8Array(attestation.response.clientDataJSON),
})
});
}).then(function(response) {

var stat = response.ok ? 'successful' : 'unsuccessful';
return response.json()
}).then(function (res)
{
if (res["status"] =='OK')
$("#res").html("<div class='alert alert-success'>Registered Successfully, <a href='{{redirect_html}}'> {{reg_success_msg}}</a></div>")
else
$("#res").html("<div class='alert alert-danger'>Registeration Failed as " + res["message"] + ", <a href='javascript:void(0)' onclick='begin_reg()'> try again or <a href='{% url 'mfa_home' %}'> Go to Security Home</a></div>")


}, 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='{% url 'mfa_home' %}'> Go to Security Home</a></div>")
})
}
$(document).ready(function (){
ua=new UAParser().getResult()
if (ua.browser.name == "Safari")
{
$("#res").html("<button class='btn btn-success' onclick='begin_reg()'>Start...</button>")
}
else
{
setTimeout(begin_reg, 500)
}
})
</script>
<script type="application/javascript" src="{% static 'mfa/js/FIDO2/add.js' %}"></script>

{% endblock %}
{% block content %}
Expand All @@ -61,13 +13,19 @@
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">
<strong> FIDO2 Security Key</strong>
<strong> {% trans 'FIDO2 Security Key' %}</strong>
</div>
<div class="panel-body">


<div class="row alert alert-pr" id="res" align="center">
<p style="color: green">Your browser should ask you to confirm you identity.</p>
<form action="#" id="fido2_form" method="post" hidden>
<input type=hidden value="{{ redirect_html }}" id="id_redirect" name="redirect">
<input type=hidden value="{% trans 'Your device is added successfully.' %}" id="id_success" name="success">
<input type=hidden value="{% url 'fido2_begin_reg' %}" id="id_begin" name="rbegin">
<input type=hidden value="{% url 'fido2_complete_reg' %}" id="id_complete" name="complete">

</form>

<div class="row alert alert-pr" id="res">
<p class="success">{% trans 'Your browser should ask you to confirm you identity.' %}</p>

</div>
</div>
Expand Down
Loading