Skip to content

Commit

Permalink
Fix text-only private pastas crashing server
Browse files Browse the repository at this point in the history
- Fixed a bug that caused encrypted uploads with no file to crash the server, as we tried to decrypt a non-existent file
- Changed wording on pasta auth page
- Removed unused import
  • Loading branch information
szabodanika committed Jul 4, 2023
1 parent d7b4462 commit 4983ac8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/endpoints/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub async fn post_admin(
pastas: &pastas,
args: &ARGS,
status: &String::from(status),
version_string: &String::from("2.0.0-20230701"),
version_string: &String::from("2.0.1-20230704"),
message: &String::from(message),
}
.render()
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/edit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::args::Args;
use crate::endpoints::errors::ErrorTemplate;
use crate::util::animalnumbers::to_u64;
use crate::util::db::{update, update_all};
use crate::util::db::update;
use crate::util::hashids::to_u64 as hashid_to_u64;
use crate::util::misc::{decrypt, encrypt, remove_expired};
use crate::{AppState, Pasta, ARGS};
Expand Down
2 changes: 1 addition & 1 deletion templates/auth_pasta.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

<form id="auth-form" method="POST" action="/{{path}}/{{id}}" enctype="multipart/form-data">
<label for="password" style="margin-bottom: 0.5rem;"> Please enter the
password to access the upload. <sup>
password to access or modify this upload. <sup>
<a href="/guide#encryption"></a></sup></label>
<input id="password-field" placeholder="Password" name="password" type="password" autocomplete="off" />
<button>Okay</button>
Expand Down
8 changes: 5 additions & 3 deletions templates/pasta.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,17 @@
// Fetch encrypted file from server
const formData = new FormData();

// {% if pasta.encrypted_key.is_some() %}
let key = decryptWithPassword(passwordField.value.trim(), "{{ pasta.encrypted_key.as_ref().unwrap() }}");

// {%- endif %}
formData.append('password', key);

const response = await fetch('/secure_file/{{ pasta.id_as_animals() }}', {
method: 'POST',
body: formData,
})

// {% if pasta.file.is_some() %}
const encryptedFile = await response.text();

// Decrypt file contents
Expand All @@ -246,8 +248,8 @@
tempAnchorEl.click();

// Remove temporary anchor element
// document.re(tempAnchorEl);

document.re(tempAnchorEl);
// {%- endif %}
});

decryptButton.addEventListener("click", () => {
Expand Down

0 comments on commit 4983ac8

Please sign in to comment.