Skip to content

Commit ca1c019

Browse files
committed
chore: update with Solidstate audit feedback
1 parent d87c20c commit ca1c019

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

src/ic_message/src/api_update.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@ use crate::{is_authenticated, store, types};
1010

1111
#[ic_cdk::update(guard = "is_authenticated")]
1212
async fn register_username(username: String, name: Option<String>) -> Result<UserInfo, String> {
13-
if username.len() > types::MAX_USER_SIZE {
13+
if username.len() > types::MAX_USER_NAME_SIZE {
1414
Err("username is too long".to_string())?;
1515
}
1616
if username.starts_with("_") {
1717
Err("invalid username".to_string())?;
1818
}
19+
1920
validate_key(&username.to_ascii_lowercase())?;
2021

2122
if let Some(ref name) = name {
2223
if name.is_empty() {
2324
Err("name is empty".to_string())?;
2425
}
25-
if name.len() > types::MAX_USER_NAME_SIZE {
26+
if name.len() > types::MAX_DISPLAY_NAME_SIZE {
2627
Err("name is too long".to_string())?;
2728
}
2829
if name != name.trim() {

src/ic_message/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use std::collections::BTreeSet;
66
pub const TOKEN_1: u64 = 100_000_000;
77
pub const TOKEN_FEE: u64 = 10_000; // 0.0001 token
88
pub const MIN_NAME_PRICE: u64 = TOKEN_1;
9-
pub const MAX_USER_NAME_SIZE: usize = 32;
10-
pub const MAX_USER_SIZE: usize = 20;
9+
pub const MAX_DISPLAY_NAME_SIZE: usize = 32;
10+
pub const MAX_USER_NAME_SIZE: usize = 20;
1111

1212
#[derive(CandidType, Clone, Debug, Deserialize, Serialize)]
1313
pub struct StateInfo {

src/ic_message_types/src/profile.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ pub const MAX_PROFILE_FOLLOWING: usize = 2048;
88
pub const MAX_PROFILE_BIO_SIZE: usize = 2048; // 2KB
99
pub const MAX_PROFILE_LINKS: usize = 100;
1010
pub const MAX_PROFILE_TOKENS: usize = 100;
11-
11+
pub const MAX_PROFILE_CHANNEL_ALIAS_LEN: usize = 20;
12+
pub const MAX_PROFILE_CHANNEL_TAGS_LEN: usize = 5;
13+
pub const MAX_PROFILE_CHANNEL_TAG_LEN: usize = 20;
1214
#[derive(CandidType, Clone, Debug, Deserialize, Serialize)]
1315
pub struct UserInfo {
1416
pub id: Principal,
@@ -57,6 +59,30 @@ impl UpdateProfileInput {
5759
return Err(format!("bio size limit exceeded: {}", bio.len()));
5860
}
5961
}
62+
// Check for conflicts in follow and unfollow
63+
if !self.follow.is_disjoint(&self.unfollow) {
64+
return Err("conflicting principals in follow and unfollow".to_string());
65+
}
66+
67+
for (channel, setting) in self.upsert_channels.iter() {
68+
if self.remove_channels.contains(channel) {
69+
return Err(format!(
70+
"channel {:?} exists in both upsert and remove",
71+
channel
72+
));
73+
}
74+
if setting.alias.len() > MAX_PROFILE_CHANNEL_ALIAS_LEN {
75+
return Err(format!("channel alias too long: {}", setting.alias.len()));
76+
}
77+
if setting.tags.len() > MAX_PROFILE_CHANNEL_TAGS_LEN {
78+
return Err(format!("too many tags: {}", setting.tags.len()));
79+
}
80+
for tag in &setting.tags {
81+
if tag.len() > MAX_PROFILE_CHANNEL_TAG_LEN {
82+
return Err(format!("tag too long: {}", tag.len()));
83+
}
84+
}
85+
}
6086
Ok(())
6187
}
6288
}
@@ -98,7 +124,7 @@ impl Link {
98124
#[derive(CandidType, Clone, Debug, Default, Deserialize, Serialize)]
99125
pub struct UploadImageInput {
100126
pub size: u64, // should <= 256KB
101-
pub content_type: String, // image/webp or image/svg+xml
127+
pub content_type: String, // "image/webp" | "image/png" | "image/jpeg" | "image/svg+xml"
102128
}
103129

104130
impl UploadImageInput {

0 commit comments

Comments
 (0)