-
Notifications
You must be signed in to change notification settings - Fork 20
Fix isSafeRedirectUrl host comparison on non-default ports #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -342,6 +342,39 @@ component extends="coldbox.system.testing.BaseInterceptorTest" interceptor="cbse | |
| expect( result ).toBeTrue(); | ||
| } ); | ||
|
|
||
| it( "allows URLs with non-default ports when host matches", () => { | ||
| // Simulate getRealHost returning host with port (e.g., during dev) | ||
| mockSecurityService.$( "getRealHost", "127.0.0.1:61910" ); | ||
|
|
||
| var result = security.isSafeRedirectUrl( | ||
| targetUrl = "http://127.0.0.1:61910/account", | ||
| event = mockEvent | ||
| ); | ||
| expect( result ).toBeTrue(); | ||
| } ); | ||
|
Comment on lines
+345
to
+354
|
||
|
|
||
| it( "allows URLs with different ports when host matches", () => { | ||
| // getRealHost returns host with port | ||
| mockSecurityService.$( "getRealHost", "mysite.com:8080" ); | ||
|
|
||
| // URL has a different port, but same host | ||
| var result = security.isSafeRedirectUrl( | ||
| targetUrl = "https://mysite.com:9000/account", | ||
| event = mockEvent | ||
| ); | ||
| expect( result ).toBeTrue(); | ||
| } ); | ||
|
|
||
| it( "blocks URLs with different hosts even with same port", () => { | ||
| mockSecurityService.$( "getRealHost", "mysite.com:8080" ); | ||
|
|
||
| var result = security.isSafeRedirectUrl( | ||
| targetUrl = "https://malicious.com:8080/phishing", | ||
| event = mockEvent | ||
| ); | ||
| expect( result ).toBeFalse(); | ||
| } ); | ||
|
|
||
| it( "handles invalid URLs gracefully", () => { | ||
| var result = security.isSafeRedirectUrl( targetUrl = "not a valid url://", event = mockEvent ); | ||
| expect( result ).toBeFalse(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
listFirst(..., ':')to extract the hostname will break for IPv6 addresses, which contain multiple colons (e.g.,2001:db8::1:8080or[2001:db8::1]:8080). When an IPv6 address with port is encountered, this will only return the first segment (e.g.,2001), causing the comparison to fail. Consider using a more robust approach that handles IPv6 addresses by checking for bracketed addresses first, or usinglistLast()to get the port and then removing it, or using Java's URI parsing capabilities.