Skip to content

Commit

Permalink
Avatar check fix, peer length check
Browse files Browse the repository at this point in the history
  • Loading branch information
n9lsjr committed Dec 23, 2024
1 parent 0ec1123 commit d1e46d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/backend/swarm.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ const check_data_message = async (data, connection, topic, peer) => {

const find_missing_peers = async (active, peers) => {
for (const peer of peers) {
if (typeof peer !== 'string' || peer?.length > 64) continue
if (typeof peer !== 'string' || peer?.length !== 64) continue
if (!active.peers.some((a) => a === peer)) {
active.swarm.joinPeer(Buffer.from(peer, 'hex'));
await sleep(100);
Expand Down
21 changes: 15 additions & 6 deletions src/backend/utils.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,13 @@ const sanitize_join_swarm_data = (data) => {
const screenshare = data?.screenshare;
if (typeof screenshare !== 'boolean') return false;
// if (typeof data?.avatar !== 'string') return false

let avatar = ""
if (data.avatar !== undefined) {
avatar = Buffer.from(data.avatar, 'base64')
if (avatar.length > 200000) {
console.log("Avatar too big")
return false
}
avatar = Buffer.from(data.avatar, 'base64')
if (avatar.length > 200000) {
console.log("Avatar too big")
return false
}
}

const channels = [];
Expand Down Expand Up @@ -297,9 +296,19 @@ const sanitize_join_swarm_data = (data) => {
if (typeof videoMute !== 'boolean') return false;
const screenshare = data?.screenshare;
if (typeof screenshare !== 'boolean') return false;

let avatar = ""
if (data.avatar !== undefined) {
avatar = Buffer.from(data.avatar, 'base64')
if (avatar.length > 200000) {
console.log("Avatar too big")
return false
}
}

const clean_object = {
address,
avatar,
message,
signature,
topic,
Expand Down

0 comments on commit d1e46d0

Please sign in to comment.