mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 10:56:10 +01:00 
			
		
		
		
	Use hostmatcher to replace matchlist, improve security (#17605)
				
					
				
			Use hostmacher to replace matchlist. And we introduce a better DialContext to do a full host/IP check, otherwise the attackers can still bypass the allow/block list by a 302 redirection.
This commit is contained in:
		| @@ -7,7 +7,6 @@ package migrations | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"crypto/tls" | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"net/http" | ||||
| @@ -19,7 +18,6 @@ import ( | ||||
| 	"code.gitea.io/gitea/modules/log" | ||||
| 	base "code.gitea.io/gitea/modules/migration" | ||||
| 	"code.gitea.io/gitea/modules/proxy" | ||||
| 	"code.gitea.io/gitea/modules/setting" | ||||
| 	"code.gitea.io/gitea/modules/structs" | ||||
| 	"code.gitea.io/gitea/modules/util" | ||||
|  | ||||
| @@ -100,12 +98,7 @@ func NewGithubDownloaderV3(ctx context.Context, baseURL, userName, password, tok | ||||
| 			) | ||||
| 			var client = &http.Client{ | ||||
| 				Transport: &oauth2.Transport{ | ||||
| 					Base: &http.Transport{ | ||||
| 						TLSClientConfig: &tls.Config{InsecureSkipVerify: setting.Migrations.SkipTLSVerify}, | ||||
| 						Proxy: func(req *http.Request) (*url.URL, error) { | ||||
| 							return proxy.Proxy()(req) | ||||
| 						}, | ||||
| 					}, | ||||
| 					Base:   NewMigrationHTTPTransport(), | ||||
| 					Source: oauth2.ReuseTokenSource(nil, ts), | ||||
| 				}, | ||||
| 			} | ||||
| @@ -113,14 +106,13 @@ func NewGithubDownloaderV3(ctx context.Context, baseURL, userName, password, tok | ||||
| 			downloader.addClient(client, baseURL) | ||||
| 		} | ||||
| 	} else { | ||||
| 		var transport = NewMigrationHTTPTransport() | ||||
| 		transport.Proxy = func(req *http.Request) (*url.URL, error) { | ||||
| 			req.SetBasicAuth(userName, password) | ||||
| 			return proxy.Proxy()(req) | ||||
| 		} | ||||
| 		var client = &http.Client{ | ||||
| 			Transport: &http.Transport{ | ||||
| 				TLSClientConfig: &tls.Config{InsecureSkipVerify: setting.Migrations.SkipTLSVerify}, | ||||
| 				Proxy: func(req *http.Request) (*url.URL, error) { | ||||
| 					req.SetBasicAuth(userName, password) | ||||
| 					return proxy.Proxy()(req) | ||||
| 				}, | ||||
| 			}, | ||||
| 			Transport: transport, | ||||
| 		} | ||||
| 		downloader.addClient(client, baseURL) | ||||
| 	} | ||||
| @@ -316,12 +308,7 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease) | ||||
| 		r.Published = rel.PublishedAt.Time | ||||
| 	} | ||||
|  | ||||
| 	httpClient := &http.Client{ | ||||
| 		Transport: &http.Transport{ | ||||
| 			TLSClientConfig: &tls.Config{InsecureSkipVerify: setting.Migrations.SkipTLSVerify}, | ||||
| 			Proxy:           proxy.Proxy(), | ||||
| 		}, | ||||
| 	} | ||||
| 	httpClient := NewMigrationHTTPClient() | ||||
|  | ||||
| 	for _, asset := range rel.Assets { | ||||
| 		var assetID = *asset.ID // Don't optimize this, for closure we need a local variable | ||||
|   | ||||
		Reference in New Issue
	
	Block a user