Cherry-pick MM-66789 (Include log viewer (system console) in log root path validation) (#35253)
Automatic Merge
Этот коммит содержится в:
@@ -187,6 +187,55 @@ func TestGetNotificationLogFile(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetLogsSkipSendPathValidation(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
t.Run("path validation prevents reading files outside log directory", func(t *testing.T) {
|
||||
// Create a directory to use as the allowed log root
|
||||
logDir, err := os.MkdirTemp("", "logs")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
th.Service.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.LogSettings.EnableFile = false
|
||||
})
|
||||
th.Service.Logger().Flush()
|
||||
err = os.RemoveAll(logDir)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
// Set MM_LOG_PATH to restrict log file access to logDir
|
||||
t.Setenv("MM_LOG_PATH", logDir)
|
||||
|
||||
// Create a directory outside the allowed log root
|
||||
outsideDir, err := os.MkdirTemp("", "outside")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
err = os.RemoveAll(outsideDir)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
// Create a log file outside the allowed root that should not be readable
|
||||
outsideLogLocation := config.GetLogFileLocation(outsideDir)
|
||||
err = os.WriteFile(outsideLogLocation, []byte("secret data\n"), 0644)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Point FileLocation to the outside directory
|
||||
th.Service.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.LogSettings.EnableFile = true
|
||||
*cfg.LogSettings.FileLocation = outsideDir
|
||||
})
|
||||
|
||||
// Should be blocked by path validation
|
||||
lines, appErr := th.Service.GetLogsSkipSend(th.Context, 0, 10, &model.LogFilter{})
|
||||
assert.Nil(t, lines)
|
||||
require.NotNil(t, appErr)
|
||||
assert.Equal(t, "api.admin.file_read_error", appErr.Id)
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetAdvancedLogs(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user