-
Notifications
You must be signed in to change notification settings - Fork 31
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
[breaking] Technical debt #306
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ use axum_extra::{headers::Cookie, TypedHeader}; | |
use rinja_axum::{into_response, Template}; | ||
use serde::Deserialize; | ||
|
||
use crate::controller::filters; | ||
use crate::{controller::filters, set_one}; | ||
use crate::{controller::fmt::clean_html, error::AppError, DB}; | ||
|
||
use super::{ | ||
|
@@ -35,27 +35,18 @@ pub(crate) async fn message( | |
let cookie = cookie.ok_or(AppError::NonLogin)?; | ||
let site_config = SiteConfig::get(&DB)?; | ||
let claim = Claim::get(&DB, &cookie, &site_config).ok_or(AppError::NonLogin)?; | ||
|
||
if DB | ||
.open_tree("pub_keys")? | ||
.get(u32_to_ivec(claim.uid))? | ||
.is_none() | ||
{ | ||
let user: User = get_one(&DB, "users", claim.uid)?; | ||
if user.pub_key.is_none() { | ||
return Ok(Redirect::to("/key").into_response()); | ||
} | ||
|
||
let pub_key = DB | ||
.open_tree("pub_keys")? | ||
.get(u32_to_ivec(uid))? | ||
.map(|s| String::from_utf8_lossy(&s).to_string()); | ||
|
||
let title = format!("Sending e2ee Message to {}", uid); | ||
let user: User = get_one(&DB, "users", uid)?; | ||
let rcpt: User = get_one(&DB, "users", uid)?; | ||
|
||
let title = format!("Sending e2ee Message to {}", rcpt.username); | ||
let page_message = PageMessage { | ||
receiver_id: uid, | ||
page_data: PageData::new(&title, &site_config, Some(claim), false), | ||
pub_key, | ||
pub_key: rcpt.pub_key, | ||
receiver_name: user.username, | ||
}; | ||
|
||
|
@@ -112,12 +103,8 @@ pub(crate) async fn key( | |
let cookie = cookie.ok_or(AppError::NonLogin)?; | ||
let site_config = SiteConfig::get(&DB)?; | ||
let claim = Claim::get(&DB, &cookie, &site_config).ok_or(AppError::NonLogin)?; | ||
|
||
let pub_key = DB | ||
.open_tree("pub_keys")? | ||
.get(u32_to_ivec(claim.uid))? | ||
.map(|r| String::from_utf8_lossy(&r).to_string()) | ||
.unwrap_or_default(); | ||
let user: User = get_one(&DB, "users", claim.uid)?; | ||
let pub_key = user.pub_key.unwrap_or_default(); | ||
|
||
let page_key = PageKey { | ||
page_data: PageData::new("Generate Key Pairs", &site_config, Some(claim), false), | ||
|
@@ -143,9 +130,9 @@ pub(crate) async fn key_post( | |
let claim = Claim::get(&DB, &cookie, &site_config).ok_or(AppError::NonLogin)?; | ||
|
||
let pub_key = clean_html(&input.pub_key); | ||
|
||
DB.open_tree("pub_keys")? | ||
.insert(u32_to_ivec(claim.uid), pub_key.as_str())?; | ||
let mut user: User = get_one(&DB, "users", claim.uid)?; | ||
user.pub_key = Some(pub_key); | ||
set_one(&DB, "users", claim.uid, &user)?; | ||
Comment on lines
+137
to
+139
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add size limit validation for public key The code should validate the size of the public key to prevent potential DoS attacks through extremely large keys or database storage issues. Consider adding a size limit check: let mut user: User = get_one(&DB, "users", claim.uid)?;
+ if input.pub_key.len() > 2048 { // Adjust size limit as needed
+ return Err(AppError::InvalidInput("Public key too large".into()));
+ }
user.pub_key = Some(pub_key);
set_one(&DB, "users", claim.uid, &user)?;
|
||
|
||
Ok(Redirect::to("/key")) | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -9,20 +9,14 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | default | "users_count" | N | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "users" | `uid` | [`User`] | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "usernames" | `username` | `uid` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "user_following" | `uid#uid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "user_followers" | `uid#uid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "user_stats" | `timestamp_uid_type` | N | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "user_following" | `uid#uid` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "user_followers" | `uid#uid` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "user_stats" | `timestamp#uid#type` | N | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "user_uploads" | `uid#img_id` | `image_hash.ext` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | default | "imgs_count" | N | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "home_pages" | `uid` | `u8` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "tan" | `ctype#id` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "lang" | `uid` | `lang` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! ### notification | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | tree | key | value | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! |-----------------|-----------------------|-------------------| | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | default | "notifications_count" | N | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "notifications" | `uid#nid#nt_type` | `id1#id2#is_read` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "tan" | `ctype#id` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | default | "notifications_count"| N | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "notifications" | `uid#nid#nt_type` | `id1#id2#is_read` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! ### captcha | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -36,10 +30,10 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | default | "solos_count" | N | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "solos" | `sid` | [`Solo`] | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "user_solos" | `uid#sid` | `solo_type` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "user_solos_like" | `uid#sid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "solo_users_like" | `sid#uid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "user_solos_like" | `uid#sid` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "solo_users_like" | `sid#uid` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "solo_timeline" | `sid` | `uid#solo_type` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "hashtags" | `hashtag#sid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "hashtags" | `hashtag#sid` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! ### session | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | tree | key | value | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -57,39 +51,38 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | default | "inns_count" | N | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "inns" | `iid` | [`Inn`] | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "inn_names" | `inn_name` | `iid` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "topics" | `topic#iid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "mod_inns" | `uid#iid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "user_inns" | `uid#iid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "inn_apply" | `iid#uid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "topics" | `topic#iid` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "mod_inns" | `uid#iid` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "user_inns" | `uid#iid` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "inn_apply" | `iid#uid` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "inn_users" | `iid#uid` | `&[1/2/3/4/5/8/10]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "inns_private" | `iid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "drafts" | `uid` | [`FormPost`] | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "drafts" | `uid#title` | [`FormPost`] | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "inn_feeds" | `iid#feed_id` | `uid` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "inn_items" | `iid#item_id` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "inn_items" | `iid#item_id` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! ### post | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | tree | key | value | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! |-------------------- |---------------------|----------------------| | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | default | "posts_count" | N | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "posts" | `pid` | [`Post`] | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "inn_posts" | `iid#pid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "inn_posts" | `iid#pid` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "user_posts" | `uid#pid` | `iid#inn_type` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "tags" | `tag#pid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "post_upvotes" | `pid#uid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "post_downvotes" | `pid#uid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "tags" | `tag#pid` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "post_upvotes" | `pid#uid` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "post_downvotes" | `pid#uid` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "post_timeline_idx" | `iid#pid` | `timestamp#inn_type` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "post_timeline" | `timestamp#iid#pid` | `inn_type` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "post_pageviews" | `pid` | N | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "post_pins" | `iid#pid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "post_pins" | `iid#pid` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! ### comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | tree | key | value | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! |-----------------------|----------------------|-------------| | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "post_comments_count" | `pid` | N | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "post_comments" | `pid#cid` | [`Comment`] | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "user_comments" | `uid#pid#cid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "comment_upvotes" | `pid#cid#uid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "comment_downvotes" | `pid#cid#uid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "user_comments" | `uid#pid#cid` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "comment_upvotes" | `pid#cid#uid` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "comment_downvotes" | `pid#cid#uid` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! ### rss | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | tree | key | value | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -103,16 +96,15 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "feed_links" | `feed_link` | `feed_id` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "item_links" | `item_link` | `item_id` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "items" | `item_id` | [`Item`] | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "read" | `uid#item_id` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "read" | `uid#item_id` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "star" | `uid#item_id` | `timestamp` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! ### e2ee message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | tree | key | value | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! |-----------------------|------------------|--------------------| | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | default | "messages_count" | N | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "messages" | `mid` | `#uid#uid#message` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "pub_keys" | `uid` | `pub_key` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "user_messages" | `uid#mid` | `&[]` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "messages" | `mid` | `message` | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//! | "user_messages" | `uid#uid#mid` | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub(super) mod db_utils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub(super) mod feed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -165,6 +157,9 @@ struct User { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
role: u8, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
url: String, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
about: String, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
lang: Option<String>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
home_page: u8, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub_key: Option<String>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+160
to
+162
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Document and validate new User fields. The new fields need documentation and validation:
Add validation and documentation: #[derive(Default, Encode, Decode, Serialize, Debug)]
struct User {
uid: u32,
username: String,
password_hash: String,
recovery_hash: Option<String>,
created_at: i64,
role: u8,
url: String,
about: String,
+ /// User's preferred language code (e.g., "en", "zh_cn")
+ #[garde(custom(supported_language))]
lang: Option<String>,
+ /// User's preferred home page view
+ /// Values:
+ /// - 0: Default view
+ /// - 1: Timeline view
+ /// - 2: Custom view
+ #[garde(range(max = 2))]
home_page: u8,
pub_key: Option<String>,
}
+impl User {
+ fn supported_language(lang: &Option<String>) -> garde::Result {
+ if let Some(lang) = lang {
+ if !["en", "zh_cn", "ja", "fr"].contains(&lang.as_str()) {
+ return Err(garde::Error::new("unsupported language"));
+ }
+ }
+ Ok(())
+ }
+} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
impl User { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -301,6 +296,11 @@ impl Inn { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
InnType::from(self.inn_type) == InnType::Hidden | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|| InnType::from(self.inn_type) == InnType::PrivateHidden | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fn is_private(&self) -> bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
InnType::from(self.inn_type) == InnType::Private | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|| InnType::from(self.inn_type) == InnType::PrivateHidden | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#[derive(Encode, Decode, Serialize, PartialEq, PartialOrd, Debug, Clone)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Public key validation is handled through HTML sanitization only
Based on the code analysis, the public key is only sanitized using
clean_html()
before storage, without any cryptographic validation. While this prevents XSS attacks, it doesn't ensure the key meets cryptographic standards.User.pub_key
as an optional Stringkey_post()
, the key is only processed throughclean_html(&input.pub_key)
src/lib.rs
andsrc/controller/user.rs
)🔗 Analysis chain
Verify public key format validation
While the code handles the absence of a public key gracefully, there's no validation of the public key format. Consider adding validation to ensure the key meets the required format and security standards.
Let's check if there's any key validation elsewhere in the codebase:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 111
Script:
Length of output: 134574
Script:
Length of output: 3835