Skip to content

Commit

Permalink
loaddata: do not reveal the existence of the files in error messages
Browse files Browse the repository at this point in the history
return a generic error message

Signed-off-by: Nicola Murino <[email protected]>
  • Loading branch information
drakkan committed Nov 1, 2023
1 parent 50cae4e commit ebec304
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions internal/httpd/api_maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func loadData(w http.ResponseWriter, r *http.Request) {
}
fi, err := os.Stat(inputFile)
if err != nil {
sendAPIResponse(w, r, err, "", getRespStatus(err))
sendAPIResponse(w, r, fmt.Errorf("invalid input_file %q", inputFile), "", http.StatusBadRequest)
return
}
if fi.Size() > MaxRestoreSize {
Expand All @@ -171,7 +171,7 @@ func loadData(w http.ResponseWriter, r *http.Request) {

content, err := os.ReadFile(inputFile)
if err != nil {
sendAPIResponse(w, r, err, "", getRespStatus(err))
sendAPIResponse(w, r, fmt.Errorf("invalid input_file %q", inputFile), "", http.StatusBadRequest)
return
}
if err := restoreBackup(content, inputFile, scanQuota, mode, claims.Username, util.GetIPFromRemoteAddress(r.RemoteAddr), claims.Role); err != nil {
Expand All @@ -184,7 +184,7 @@ func loadData(w http.ResponseWriter, r *http.Request) {
func restoreBackup(content []byte, inputFile string, scanQuota, mode int, executor, ipAddress, role string) error {
dump, err := dataprovider.ParseDumpData(content)
if err != nil {
return util.NewValidationError(fmt.Sprintf("unable to parse backup content: %v", err))
return util.NewValidationError(fmt.Sprintf("invalid input_file %q", inputFile))
}

if err = RestoreConfigs(dump.Configs, mode, executor, ipAddress, role); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/httpd/httpd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7941,7 +7941,7 @@ func TestLoaddata(t *testing.T) {
if runtime.GOOS != osWindows {
err = os.Chmod(backupFilePath, 0111)
assert.NoError(t, err)
_, _, err = httpdtest.Loaddata(backupFilePath, "1", "", http.StatusForbidden)
_, _, err = httpdtest.Loaddata(backupFilePath, "1", "", http.StatusBadRequest)
assert.NoError(t, err)
err = os.Chmod(backupFilePath, 0644)
assert.NoError(t, err)
Expand Down

0 comments on commit ebec304

Please sign in to comment.