Skip to content
Open
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
9 changes: 8 additions & 1 deletion web/utils/urlValidation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { validateRedirectUrl } from './urlValidation'
import { isPrivateOrLocalAddress, validateRedirectUrl } from './urlValidation'

describe('URL Validation', () => {
describe('validateRedirectUrl', () => {
Expand Down Expand Up @@ -56,4 +56,11 @@ describe('URL Validation', () => {
expect(() => validateRedirectUrl('//example.com')).toThrow('Invalid URL')
})
})

describe('isPrivateOrLocalAddress', () => {
it('should recognize the IPv6 loopback address', () => {
expect(isPrivateOrLocalAddress('http://[::1]/')).toBe(true)
expect(isPrivateOrLocalAddress('http://[::1]:8080/')).toBe(true)
})
})
})
2 changes: 1 addition & 1 deletion web/utils/urlValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function isPrivateOrLocalAddress(url: string): boolean {
const hostname = urlObj.hostname.toLowerCase()

// Check for localhost
if (hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '::1') return true
if (hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '[::1]') return true

// Check for private IP ranges
const ipv4Regex = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/
Expand Down