-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix open redirect vulnerability on login screen #4312
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 |
---|---|---|
|
@@ -7,6 +7,8 @@ package util | |
import ( | ||
"testing" | ||
|
||
"code.gitea.io/gitea/modules/setting" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
|
@@ -42,3 +44,36 @@ func TestURLJoin(t *testing.T) { | |
assert.Equal(t, test.Expected, URLJoin(test.Base, test.Elements...)) | ||
} | ||
} | ||
|
||
func TestIsExternalURL(t *testing.T) { | ||
setting.Domain = "try.gitea.io" | ||
type test struct { | ||
Expected bool | ||
RawURL string | ||
} | ||
newTest := func(expected bool, rawURL string) test { | ||
return test{Expected: expected, RawURL: rawURL} | ||
} | ||
for _, test := range []test{ | ||
newTest(false, | ||
"https://try.gitea.io"), | ||
newTest(true, | ||
"https://example.com/"), | ||
newTest(true, | ||
"//example.com"), | ||
newTest(true, | ||
"http://example.com"), | ||
newTest(false, | ||
"a/"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this false? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because it is not external |
||
newTest(false, | ||
"https://try.gitea.io/test?param=false"), | ||
newTest(false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because it is not external |
||
"test?param=false"), | ||
newTest(false, | ||
"//try.gitea.io/test?param=false"), | ||
newTest(false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because it is not external |
||
"/hey/hey/hey#3244"), | ||
} { | ||
assert.Equal(t, test.Expected, IsExternalURL(test.RawURL)) | ||
} | ||
} |
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.