Skip to content

Commit

Permalink
Merge branch 'release/v0.19.1'
Browse files Browse the repository at this point in the history
Closes #35
  • Loading branch information
targodan committed Dec 23, 2022
2 parents 70dfc82 + 68d2735 commit 56cb04c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
6 changes: 3 additions & 3 deletions app/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ func receive(c *cli.Context) error {
}()

err = reportServer.Start()
if err != http.ErrServerClosed {
return cli.Exit(err, 10)
}

switch {
case <-shutdownStarted:
<-shutdownCompleted
default:
}
if err != http.ErrServerClosed {
return cli.Exit(err, 10)
}
return nil
}
39 changes: 29 additions & 10 deletions archiver/remoteServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"math/rand"
"net/http"
"os"
"path"
"path/filepath"
"strings"
"sync"
Expand Down Expand Up @@ -201,7 +202,7 @@ func (s *ArchiverServer) registerReport(reportID, reportName string) (*reportHan

_, exists := s.openReports[reportID]
if exists {
return nil, fmt.Errorf("report with ID '%s' already exists", reportID)
return nil, fmt.Errorf("report with ID '%s' already exists", sanitizeStringForLogs(reportID))
}

handler, err := newReportHandler(s.outdir, reportName, s.outerExt, s.wcBuilder)
Expand All @@ -219,7 +220,7 @@ func (s *ArchiverServer) getReport(reportID string) (*reportHandler, error) {

report, exists := s.openReports[reportID]
if !exists {
return nil, fmt.Errorf("report with ID '%s' does not exists", reportID)
return nil, fmt.Errorf("report with ID '%s' does not exists", sanitizeStringForLogs(reportID))
}
return report, nil
}
Expand All @@ -230,7 +231,7 @@ func (s *ArchiverServer) getAndRemoveReport(reportID string) (*reportHandler, er

report, exists := s.openReports[reportID]
if !exists {
return nil, fmt.Errorf("report with ID '%s' does not exists", reportID)
return nil, fmt.Errorf("report with ID '%s' does not exists", sanitizeStringForLogs(reportID))
}
delete(s.openReports, reportID)

Expand All @@ -241,19 +242,29 @@ type CreateReportRequest struct {
Name string `json:"name"`
}

func sanitizeFilename(name string) string {
return path.Base(path.Clean("/" + removeNewlines(name)))
}

func (s *ArchiverServer) createReport(c *gin.Context) {
var req CreateReportRequest
if err := c.ShouldBindJSON(&req); handleError(c, err) {
return
}

reportName := sanitizeFilename(req.Name)
if reportName == "." || reportName == "/" {
handleError(c, fmt.Errorf("invalid report name '%s'", sanitizeStringForLogs(req.Name)))
return
}

reportID := generateReportID()
_, err := s.registerReport(reportID, req.Name)
_, err := s.registerReport(reportID, reportName)
if handleError(c, err) {
return
}

logrus.Infof("Creating new report '%s' with ID '%s'", req.Name, reportID)
logrus.Infof("Creating new report '%s' with ID '%s'", sanitizeStringForLogs(req.Name), reportID)

c.JSON(http.StatusOK, gin.H{
"error": nil,
Expand All @@ -269,7 +280,7 @@ func (s *ArchiverServer) closeReport(c *gin.Context) {
if handleError(c, report.Close()) {
return
}
logrus.Infof("Closed report with ID '%s'", c.Param("report"))
logrus.Infof("Closed report with ID '%s'", sanitizeStringForLogs(c.Param("report")))
sendOkay(c)
}

Expand Down Expand Up @@ -357,10 +368,6 @@ func newReportHandler(dir, reportName, outerExt string, wcBuilder WriteCloserBui
}, nil
}

func sanitizePath(path string) string {
return strings.Trim(filepath.Clean(path), "/")
}

func (h *reportHandler) CreateFile(filepath string) error {
h.openFilesMux.Lock()
defer h.openFilesMux.Unlock()
Expand Down Expand Up @@ -423,3 +430,15 @@ func (h *reportHandler) Close() error {
err = errors.NewMultiError(err, os.Rename(h.reportArchiveSwpPath, h.reportArchivePath))
return err
}

func removeNewlines(s string) string {
return strings.Replace(strings.Replace(s, "\n", "", -1), "\r", "", -1)
}

func sanitizeStringForLogs(s string) string {
return removeNewlines(s)
}

func sanitizePath(path string) string {
return strings.Trim(filepath.Clean(removeNewlines(path)), "/")
}
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var YapscanVersion = Version{
Major: 0,
Minor: 19,
Bugfix: 0,
Bugfix: 1,
}

type Version struct {
Expand Down

0 comments on commit 56cb04c

Please sign in to comment.