mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 19:06:18 +01:00 
			
		
		
		
	Fix open redirect vulnerability on login screen (#4312)
* Fix open redirect vulnerability on login screen Signed-off-by: Jonas Franz <info@jonasfranz.software> * Reorder imports Signed-off-by: Jonas Franz <info@jonasfranz.software> * Replace www. from Domain too Signed-off-by: Jonas Franz <info@jonasfranz.software>
This commit is contained in:
		| @@ -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/"), | ||||
| 		newTest(false, | ||||
| 			"https://try.gitea.io/test?param=false"), | ||||
| 		newTest(false, | ||||
| 			"test?param=false"), | ||||
| 		newTest(false, | ||||
| 			"//try.gitea.io/test?param=false"), | ||||
| 		newTest(false, | ||||
| 			"/hey/hey/hey#3244"), | ||||
| 	} { | ||||
| 		assert.Equal(t, test.Expected, IsExternalURL(test.RawURL)) | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user