Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 45 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion src/shared/util/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,19 @@ export function isHttps(url: string, useWhitelist = false): boolean {
// Check if a URL string is valid.
export function isValidUrl(url: string, useWhitelist = false): boolean {
if (useWhitelist && isWhitelisted(url)) return true
return validator.isURL(url, URL_OPTS)
if (!validator.isURL(url, URL_OPTS)) return false

// NOTE: Reject URLs with IP addresses to prevent the use of internal or private IPs
// as long URLs. This is a security measure to mitigate risks such as
// Server-Side Request Forgery (SSRF) and unauthorized access to internal resources.
try {
// NOTE: try/catch to avoid drifts in validation
// between validator library and `URL` constructor
const host = new URL(url).hostname
return !validator.isIP(host)
} catch {
return false
}
}

// Tests if a short link consists of alphanumeric and hyphen characters.
Expand Down
5 changes: 5 additions & 0 deletions test/shared/util/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ describe('Test valid url check', () => {
const url = 'http://localhost:4566/local-bucket/file1.pdf'
expect(validation.isValidUrl(url, true)).toBe(true)
})

test('IP addresses fails check', () => {
const url = 'https://8.8.8.8:4566/local-bucket/file1.pdf'
expect(validation.isValidUrl(url)).toBe(false)
})
})

describe('Test short url check', () => {
Expand Down
Loading