Penalize IP relays, explicitly allow onion/local relays

This commit is contained in:
Jon Staab
2025-01-13 11:58:21 -08:00
parent 01dd28552d
commit 7e5ca073f3
3 changed files with 24 additions and 9 deletions
+1
View File
@@ -25,6 +25,7 @@ export const THREAD = 11
export const SEAL = 13
export const DIRECT_MESSAGE = 14
export const GENERIC_REPOST = 16
export const PICTURE_FIRST = 20
export const CHANNEL_CREATE = 40
export const CHANNEL_UPDATE = 41
export const CHANNEL_MESSAGE = 42
+8 -6
View File
@@ -39,6 +39,10 @@ export const isRelayUrl = (url: string) => {
return false
}
if (!url.match(/\./)) {
return false
}
try {
new URL(url)
} catch (e) {
@@ -48,16 +52,14 @@ export const isRelayUrl = (url: string) => {
return true
}
export const isOnionUrl = (url: string) => Boolean(stripProtocol(url).match(/^[a-z2-7]{56}.onion$/))
export const isOnionUrl = (url: string) => Boolean(stripProtocol(url).match(/^[a-z2-7]{56}.onion/))
export const isLocalhostUrl = (url: string) => Boolean(stripProtocol(url).match(/^localhost:/))
export const isLocalUrl = (url: string) => Boolean(url.match(/\.local(:[\d]+)?\/?$/))
export const isLocalUrl = (url: string) =>
Boolean(url.match(/\.local(:[\d]+)?\/?$/) || stripProtocol(url).match(/^localhost:/))
export const isIPAddress = (url: string) => Boolean(url.match(/\d+\.\d+\.\d+\.\d+/))
export const isShareableRelayUrl = (url: string) =>
Boolean(isRelayUrl(url) && !isLocalUrl(url) && !isLocalhostUrl(url))
export const isShareableRelayUrl = (url: string) => Boolean(isRelayUrl(url) && !isLocalUrl(url))
export const normalizeRelayUrl = (url: string) => {
const prefix = url.match(/^wss?:\/\//)?.[0] || "wss://"