Skip to content

Commit

Permalink
bug/security fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
seguinleo committed Dec 2, 2024
1 parent 83590ae commit 925a1b0
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/assets/css/style.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/assets/css/style.min.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/assets/js/cloud/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ document.querySelector('#btn-add-note').addEventListener('click', () => {
});

document.querySelector('#btn-unlock-float').addEventListener('click', async () => {
await defaultScript.verifyFingerprint();
await defaultScript.getFingerprint();
await getNotes();
});

Expand Down
38 changes: 34 additions & 4 deletions src/assets/js/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,36 @@ export const getLockApp = async () => {
}
}

export const verifyFingerprint = async () => {
export const getFingerprint = async () => {
try {
const challenge = generateRandomBytes(16);
const userId = generateRandomBytes(8);
const challenge = generateRandomBytes(32);
const publicKeyOptions = {
challenge,
rp: {
name: 'Bloc-notes',
},
allowCredentials: [],
userVerification: "preferred",
timeout: 60000,
};
const credential = await navigator.credentials.get({ publicKey: publicKeyOptions });
if (credential) {
isLocked = false;
document.querySelector('#btn-unlock-float').classList.add('d-none');
document.querySelectorAll('#sidebar button').forEach((e) => e.classList.remove('d-none'));
document.querySelector('#btn-add-note').classList.remove('d-none');
document.querySelector('#lock-app-slider').classList.remove('d-none');
} else showError('An error occurred - No credential');
} catch (error) {
showError(`An error occurred - ${error}`);
}
};

export const createFingerprint = async () => {
try {
const challenge = generateRandomBytes(32);
const username = document.querySelector('#user-name').textContent;
const userId = new TextEncoder().encode(username);
await navigator.credentials.create({
publicKey: {
challenge,
Expand All @@ -139,6 +165,10 @@ export const verifyFingerprint = async () => {
authenticatorAttachment: 'platform',
userVerification: 'preferred',
},
excludeCredentials: [{
type: 'public-key',
id: userId
}],
timeout: 60000,
attestation: 'none',
},
Expand Down Expand Up @@ -446,7 +476,7 @@ document.querySelectorAll('.custom-check').forEach((e) => {

document.querySelector('#check-lock-app').addEventListener('change', async (e) => {
if (isLocked) return;
if (e.target.checked) await verifyFingerprint();
if (e.target.checked) await createFingerprint();
try {
const data = new URLSearchParams({ csrf_token: csrfToken, lock_app: e.target.checked });
const res = await fetch('./assets/php/lockApp.php', {
Expand Down
2 changes: 1 addition & 1 deletion src/assets/js/local/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ document.querySelector('#btn-add-note').addEventListener('click', () => {
});

document.querySelector('#btn-unlock-float').addEventListener('click', async () => {
await defaultScript.verifyFingerprint();
await defaultScript.getFingerprint();
await getNotes();
});

Expand Down
4 changes: 2 additions & 2 deletions src/assets/js/marked.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/assets/js/purify.min.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/assets/php/addNote.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
'bg-pink',
];

if (iconv_strlen($title) > 30) {
throw new Exception('Insert failed');
return;
}
if (iconv_strlen($content) > 20000) {
throw new Exception('Insert failed');
return;
}
if (in_array($color, $allColors) === false) $color = 'bg-default';

try {
Expand Down
8 changes: 8 additions & 0 deletions src/assets/php/updateNote.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
'bg-pink',
];

if (iconv_strlen($title) > 30) {
throw new Exception('Update failed');
return;
}
if (iconv_strlen($content) > 20000) {
throw new Exception('Update failed');
return;
}
if (in_array($color, $allColors) === false) $color = 'bg-default';

try {
Expand Down
18 changes: 9 additions & 9 deletions src/assets/sass/style.sass
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ select
border: none

textarea
font-size: .9rem
width: 100%
min-height: 200px
max-height: 1000px
Expand Down Expand Up @@ -279,8 +278,8 @@ input

.christmas
position: absolute
top: 10px
left: 8px
top: 7px
left: 7px
transform: rotate(-25deg)

.nav-buttons
Expand Down Expand Up @@ -357,13 +356,14 @@ input
user-select: none
text-align: center
margin-top: 10px
margin-bottom: 4px
margin-bottom: 5px

i
cursor: pointer
display: inline-flex
align-items: center
justify-content: center
font-size: 1.1rem
margin: 0 4px
width: 30px
height: 30px
Expand All @@ -377,6 +377,7 @@ input
display: flex
justify-content: center
align-items: center
font-size: 1.1rem
width: 48px
height: 48px
margin-top: 5px
Expand All @@ -392,7 +393,7 @@ input
width: 60px
height: 60px
margin: 0
font-size: 1.5rem
font-size: 1.6rem
border-radius: 48px
z-index: 1

Expand Down Expand Up @@ -470,6 +471,7 @@ input
display: inline-flex
align-items: center
justify-content: center
font-size: 1.1rem
width: 30px
height: 30px
border-radius: 50%
Expand Down Expand Up @@ -539,19 +541,17 @@ dialog
overflow-y: auto

.content
min-width: 100%
padding: 4px 1rem
border-radius: 1rem

#note-popup-box
font-size: .9rem

.popup
max-width: 1300px

.content
input,
textarea
font-size: 1rem
padding: 0
border: none
border-radius: 0
Expand Down Expand Up @@ -716,7 +716,7 @@ dialog
justify-content: center
align-items: center
top: 50svh
font-size: 1.5rem
font-size: 1.6rem
border-radius: 48px
width: 75px
height: 75px
Expand Down
2 changes: 1 addition & 1 deletion src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
<div class="close">
<i class="fa-solid fa-xmark"></i>
</div>
<div class="row bold">
<div id="user-name" class="row bold">
<?= htmlspecialchars($name, ENT_QUOTES, 'UTF-8') ?>
</div>
<div class="row">
Expand Down
Loading

0 comments on commit 925a1b0

Please sign in to comment.