Skip to content

Commit b87418e

Browse files
committed
fix: prevent IPs from being used as long URL
1 parent 1ee305f commit b87418e

File tree

2 files changed

+46
-24
lines changed

2 files changed

+46
-24
lines changed

package-lock.json

Lines changed: 41 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/shared/util/validation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ export function isHttps(url: string, useWhitelist = false): boolean {
4545
// Check if a URL string is valid.
4646
export function isValidUrl(url: string, useWhitelist = false): boolean {
4747
if (useWhitelist && isWhitelisted(url)) return true
48-
return validator.isURL(url, URL_OPTS)
48+
if (!validator.isURL(url, URL_OPTS)) return false
49+
50+
// NOTE: check whether it's an IP
51+
const host = new URL(url).hostname
52+
return !validator.isIP(host)
4953
}
5054

5155
// Tests if a short link consists of alphanumeric and hyphen characters.

0 commit comments

Comments
 (0)