Fix isRelayUrl
This commit is contained in:
+11
-10
@@ -41,21 +41,22 @@ export const isRelayUrl = (url: string) => {
|
|||||||
url = "wss://" + url
|
url = "wss://" + url
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip non-ws urls
|
let parsed: URL
|
||||||
if (!url.match(/^wss?:\/\//)) return false
|
|
||||||
|
|
||||||
// Skip urls with a slash before the dot
|
|
||||||
if (url.match(/\\.*\./)) return false
|
|
||||||
|
|
||||||
// Skip non-localhost urls without a dot
|
|
||||||
if (!url.match(/\./) && !url.includes("localhost")) return false
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new URL(url)
|
parsed = new URL(url)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip non-ws urls
|
||||||
|
if (!parsed.protocol.match(/^wss?:$/)) return false
|
||||||
|
|
||||||
|
// Host is required (rejects local file paths like /home/foo/bar.png)
|
||||||
|
if (!parsed.hostname) return false
|
||||||
|
|
||||||
|
// Skip non-localhost hosts without a dot (checks host, not path)
|
||||||
|
if (!parsed.hostname.includes(".") && parsed.hostname !== "localhost") return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user