1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-12-05 23:28:10 +02:00

Prohibit connecting to loopback, link-local multicast, and link-local unicast IP addresses by default

This commit is contained in:
DarthSim
2023-03-22 20:25:51 +03:00
parent 24f4d43a0f
commit 1a9768a2c6
8 changed files with 110 additions and 18 deletions

View File

@@ -40,6 +40,8 @@ func (s *ProcessingHandlerTestSuite) SetupSuite() {
require.Nil(s.T(), err)
config.LocalFileSystemRoot = filepath.Join(wd, "/testdata")
// Disable keep-alive to test connection restrictions
config.ClientKeepAliveTimeout = 0
err = initialize()
require.Nil(s.T(), err)
@@ -58,6 +60,7 @@ func (s *ProcessingHandlerTestSuite) SetupTest() {
// We don't need config.LocalFileSystemRoot anymore as it is used
// only during initialization
config.Reset()
config.AllowLoopbackSourceAddresses = true
}
func (s *ProcessingHandlerTestSuite) send(path string, header ...http.Header) *httptest.ResponseRecorder {
@@ -210,6 +213,28 @@ func (s *ProcessingHandlerTestSuite) TestSourceValidation() {
}
}
func (s *ProcessingHandlerTestSuite) TestSourceNetworkValidation() {
data := s.readTestFile("test1.png")
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
rw.WriteHeader(200)
rw.Write(data)
}))
defer server.Close()
var rw *httptest.ResponseRecorder
u := fmt.Sprintf("/unsafe/rs:fill:4:4/plain/%s/test1.png", server.URL)
fmt.Println(u)
rw = s.send(u)
require.Equal(s.T(), 200, rw.Result().StatusCode)
config.AllowLoopbackSourceAddresses = false
rw = s.send(u)
require.Equal(s.T(), 404, rw.Result().StatusCode)
}
func (s *ProcessingHandlerTestSuite) TestSourceFormatNotSupported() {
vips.DisableLoadSupport(imagetype.PNG)
defer vips.ResetLoadSupport()