Don't proxy same-site image urls (#8238)
* don't proxy same-site urls * fix empty site url case
Этот коммит содержится в:
@@ -876,6 +876,10 @@ func (a *App) imageProxyConfig() (proxyType, proxyURL, options, siteURL string)
|
|||||||
proxyURL += "/"
|
proxyURL += "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if siteURL == "" || siteURL[len(siteURL)-1] != '/' {
|
||||||
|
siteURL += "/"
|
||||||
|
}
|
||||||
|
|
||||||
if cfg.ServiceSettings.ImageProxyOptions != nil {
|
if cfg.ServiceSettings.ImageProxyOptions != nil {
|
||||||
options = *cfg.ServiceSettings.ImageProxyOptions
|
options = *cfg.ServiceSettings.ImageProxyOptions
|
||||||
}
|
}
|
||||||
@@ -890,12 +894,12 @@ func (a *App) ImageProxyAdder() func(string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return func(url string) string {
|
return func(url string) string {
|
||||||
if url == "" || strings.HasPrefix(url, proxyURL) {
|
if url == "" || strings.HasPrefix(url, siteURL) || strings.HasPrefix(url, proxyURL) {
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
|
|
||||||
if url[0] == '/' {
|
if url[0] == '/' {
|
||||||
url = siteURL + url
|
url = siteURL + url[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
switch proxyType {
|
switch proxyType {
|
||||||
|
|||||||
@@ -190,6 +190,10 @@ func TestImageProxy(t *testing.T) {
|
|||||||
th := Setup().InitBasic()
|
th := Setup().InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
|
*cfg.ServiceSettings.SiteURL = "http://mymattermost.com"
|
||||||
|
})
|
||||||
|
|
||||||
for name, tc := range map[string]struct {
|
for name, tc := range map[string]struct {
|
||||||
ProxyType string
|
ProxyType string
|
||||||
ProxyURL string
|
ProxyURL string
|
||||||
@@ -211,6 +215,12 @@ func TestImageProxy(t *testing.T) {
|
|||||||
ImageURL: "http://mydomain.com/myimage",
|
ImageURL: "http://mydomain.com/myimage",
|
||||||
ProxiedImageURL: "https://127.0.0.1/x1000/http://mydomain.com/myimage",
|
ProxiedImageURL: "https://127.0.0.1/x1000/http://mydomain.com/myimage",
|
||||||
},
|
},
|
||||||
|
"willnorris/imageproxy_SameSite": {
|
||||||
|
ProxyType: "willnorris/imageproxy",
|
||||||
|
ProxyURL: "https://127.0.0.1",
|
||||||
|
ImageURL: "http://mymattermost.com/myimage",
|
||||||
|
ProxiedImageURL: "http://mymattermost.com/myimage",
|
||||||
|
},
|
||||||
"willnorris/imageproxy_EmptyImageURL": {
|
"willnorris/imageproxy_EmptyImageURL": {
|
||||||
ProxyType: "willnorris/imageproxy",
|
ProxyType: "willnorris/imageproxy",
|
||||||
ProxyURL: "https://127.0.0.1",
|
ProxyURL: "https://127.0.0.1",
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user