Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 40313cd

Browse files
committed
common, db4s, webui: Sanitise some of our log messages
1 parent 0b272ef commit 40313cd

File tree

9 files changed

+191
-178
lines changed

9 files changed

+191
-178
lines changed

common/postgresql.go

Lines changed: 105 additions & 92 deletions
Large diffs are not rendered by default.

common/responses.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ func UploadResponse(w http.ResponseWriter, r *http.Request, loggedInUser, target
506506
}
507507

508508
// Log the successful database upload
509-
log.Printf("Database uploaded: '%s%s%s', bytes: %v\n", loggedInUser, targetFolder, targetDB, numBytes)
509+
log.Printf("Database uploaded: '%s%s%s', bytes: %v\n", loggedInUser, targetFolder, SanitiseLogString(targetDB), numBytes)
510510

511511
// Generate the formatted server string
512512
var server string

common/sqlite.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func GetSQLiteRowCount(sdb *sqlite.Conn, dbTable string) (int, error) {
241241
var rowCount int
242242
err := sdb.OneValue(dbQuery, &rowCount)
243243
if err != nil {
244-
log.Printf("Error occurred when counting total rows for table '%s'. Error: %s\n", dbTable, err)
244+
log.Printf("Error occurred when counting total rows for table '%s'. Error: %s\n", SanitiseLogString(dbTable), err)
245245
return 0, errors.New("Database query failure")
246246
}
247247
return rowCount, nil
@@ -287,7 +287,7 @@ func OpenSQLiteDatabaseDefensive(w http.ResponseWriter, r *http.Request, dbOwner
287287
if id == "" {
288288
// The requested database wasn't found, or the user doesn't have permission to access it
289289
err = fmt.Errorf("Requested database not found")
290-
log.Printf("Requested database not found. Owner: '%s%s%s'", dbOwner, dbFolder, dbName)
290+
log.Printf("Requested database not found. Owner: '%s%s%s'", SanitiseLogString(dbOwner), SanitiseLogString(dbFolder), SanitiseLogString(dbName))
291291
w.WriteHeader(http.StatusNotFound)
292292
fmt.Fprintf(w, "%s", err.Error())
293293
return
@@ -921,7 +921,7 @@ func TablesAndViews(sdb *sqlite.Conn, dbName string) (list []string, err error)
921921
}
922922
if len(list) == 0 {
923923
// No table names were returned, so abort
924-
log.Printf("The database '%s' doesn't seem to have any tables. Aborting.", dbName)
924+
log.Printf("The database '%s' doesn't seem to have any tables. Aborting.", SanitiseLogString(dbName))
925925
return
926926
}
927927

common/userinput.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func GetDatabase(r *http.Request, allowGet bool) (dbName string, err error) {
7272
}
7373
err = ValidateDB(dbName)
7474
if err != nil {
75-
log.Printf("Validation failed for database name '%s': %s", dbName, err)
75+
log.Printf("Validation failed for database name '%s': %s", SanitiseLogString(dbName), err)
7676
return "", errors.New("Invalid database name")
7777
}
7878
return dbName, nil
@@ -325,7 +325,7 @@ func GetOD(ignoreLeading int, r *http.Request) (dbOwner string, dbName string, e
325325

326326
// Check that at least an owner/database combination was requested
327327
if len(pathStrings) < (3 + ignoreLeading) {
328-
log.Printf("Something wrong with the requested URL: %v\n", r.URL.Path)
328+
log.Printf("Something wrong with the requested URL: %v\n", SanitiseLogString(r.URL.Path))
329329
return "", "", errors.New("Invalid URL")
330330
}
331331
dbOwner = pathStrings[1+ignoreLeading]

common/util.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func AddDatabase(loggedInUser, dbOwner, dbFolder, dbName string, createBranch bo
4848
tempDB, err := ioutil.TempFile(Conf.DiskCache.Directory, "dbhub-upload-")
4949
if err != nil {
5050
log.Printf("Error creating temporary file. User: '%s', Database: '%s%s%s', Error: %v\n", loggedInUser,
51-
dbOwner, dbFolder, dbName, err)
51+
SanitiseLogString(dbOwner), SanitiseLogString(dbFolder), SanitiseLogString(dbName), err)
5252
return
5353
}
5454
tempDBName := tempDB.Name()
@@ -62,7 +62,7 @@ func AddDatabase(loggedInUser, dbOwner, dbFolder, dbName string, createBranch bo
6262
numBytes, err = io.CopyBuffer(tempDB, newDB, buf)
6363
if err != nil {
6464
log.Printf("Error when writing the uploaded db to a temp file. User: '%s', Database: '%s%s%s' "+
65-
"Error: %v\n", loggedInUser, dbOwner, dbFolder, dbName, err)
65+
"Error: %v\n", loggedInUser, SanitiseLogString(dbOwner), SanitiseLogString(dbFolder), SanitiseLogString(dbName), err)
6666
return
6767
}
6868
if numBytes == 0 {
@@ -329,7 +329,7 @@ func AddDatabase(loggedInUser, dbOwner, dbFolder, dbName string, createBranch bo
329329
if !ok {
330330
m := fmt.Sprintf("Error when counting commits in branch '%s' of database '%s%s%s'\n", branchName,
331331
dbOwner, dbFolder, dbName)
332-
log.Print(m)
332+
log.Print(SanitiseLogString(m))
333333
return 0, "", "", errors.New(m)
334334
}
335335
}
@@ -761,7 +761,7 @@ func DeleteBranchHistory(dbOwner, dbFolder, dbName, branchName, commitID string)
761761
c, ok = commitList[c.Parent]
762762
if !ok {
763763
log.Printf("Error when counting # of commits while rewriting branch '%s' of database '%s%s%s'\n",
764-
branchName, dbOwner, dbFolder, dbName)
764+
SanitiseLogString(branchName), SanitiseLogString(dbOwner), SanitiseLogString(dbFolder), SanitiseLogString(dbName))
765765
err = fmt.Errorf("Error when counting commits during branch history rewrite")
766766
return
767767
}
@@ -1008,7 +1008,7 @@ func IsCommitInBranchHistory(dbOwner, dbFolder, dbName, branchName, commitID str
10081008
c, ok = commitList[c.Parent]
10091009
if !ok {
10101010
log.Printf("Broken commit history encountered for branch '%s' in '%s%s%s', when looking for "+
1011-
"commit '%s'\n", branchName, dbOwner, dbFolder, dbName, c.Parent)
1011+
"commit '%s'\n", SanitiseLogString(branchName), SanitiseLogString(dbOwner), SanitiseLogString(dbFolder), SanitiseLogString(dbName), c.Parent)
10121012
return false, fmt.Errorf("Broken commit history encountered for branch '%s' when looking up "+
10131013
"commit details", branchName)
10141014
}

db4s/main.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ func licenceAddHandler(w http.ResponseWriter, r *http.Request) {
440440
}
441441
err = com.ValidateLicence(l)
442442
if err != nil {
443-
log.Printf("Validation failed for licence ID: '%s': %s", l, err)
443+
log.Printf("Validation failed for licence ID: '%s': %s", com.SanitiseLogString(l), err)
444444
http.Error(w, "Validation of licence ID failed", http.StatusBadRequest)
445445
return
446446
}
@@ -451,7 +451,7 @@ func licenceAddHandler(w http.ResponseWriter, r *http.Request) {
451451
if z := r.FormValue("licence_name"); z != "" {
452452
err = com.ValidateLicenceFullName(z)
453453
if err != nil {
454-
log.Printf("Validation failed for licence full name: '%s': %s", z, err)
454+
log.Printf("Validation failed for licence full name: '%s': %s", com.SanitiseLogString(z), err)
455455
http.Error(w, "Validation of licence full name failed", http.StatusBadRequest)
456456
return
457457
}
@@ -554,7 +554,7 @@ func licenceAddHandler(w http.ResponseWriter, r *http.Request) {
554554
_, _ = fmt.Fprintf(w, "Success")
555555

556556
// Log the new license addition
557-
log.Printf("New licence '%s' added to the server by user '%v'\n", licID, userAcc)
557+
log.Printf("New licence '%s' added to the server by user '%v'\n", com.SanitiseLogString(licID), userAcc)
558558
return
559559
}
560560

@@ -577,7 +577,7 @@ func licenceGetHandler(w http.ResponseWriter, r *http.Request) {
577577
// Validate the licence name
578578
err = com.ValidateLicence(l)
579579
if err != nil {
580-
log.Printf("Validation failed for licence name: '%s': %s", l, err)
580+
log.Printf("Validation failed for licence name: '%s': %s", com.SanitiseLogString(l), err)
581581
http.Error(w, "Validation of licence name failed", http.StatusBadRequest)
582582
return
583583
}
@@ -621,7 +621,7 @@ func licenceGetHandler(w http.ResponseWriter, r *http.Request) {
621621
}
622622

623623
// Log the transfer
624-
log.Printf("Licence '%s' downloaded by user '%v', %d bytes\n", licenceName, userAcc, bytesWritten)
624+
log.Printf("Licence '%s' downloaded by user '%v', %d bytes\n", com.SanitiseLogString(licenceName), userAcc, bytesWritten)
625625
return
626626
}
627627

@@ -674,7 +674,7 @@ func licenceRemoveHandler(w http.ResponseWriter, r *http.Request) {
674674
// Validate the licence name
675675
err = com.ValidateLicence(l)
676676
if err != nil {
677-
log.Printf("Validation failed for licence name: '%s': %s", l, err)
677+
log.Printf("Validation failed for licence name: '%s': %s", com.SanitiseLogString(l), err)
678678
http.Error(w, "Validation of licence name failed", http.StatusBadRequest)
679679
return
680680
}
@@ -703,7 +703,7 @@ func licenceRemoveHandler(w http.ResponseWriter, r *http.Request) {
703703
fmt.Fprintf(w, "Success")
704704

705705
// Log the transfer
706-
log.Printf("Licence '%s' removed by user '%v'\n", licenceName, userAcc)
706+
log.Printf("Licence '%s' removed by user '%v'\n", com.SanitiseLogString(licenceName), userAcc)
707707
return
708708
}
709709

@@ -907,7 +907,7 @@ func retrieveDatabase(w http.ResponseWriter, r *http.Request, pageName string, u
907907
}
908908

909909
// Log the transfer
910-
log.Printf("'%s%s%s' downloaded by user '%v', %v bytes", dbOwner, dbFolder, dbName, userAcc, bytesWritten)
910+
log.Printf("'%s%s%s' downloaded by user '%v', %v bytes", com.SanitiseLogString(dbOwner), dbFolder, dbName, userAcc, bytesWritten)
911911
return nil
912912
}
913913

0 commit comments

Comments
 (0)