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

Commit 45ac5b8

Browse files
committed
db4s: Add some safety-handling code around a username input
In theory, it should be impossible to have that username be corrupt, so this is likely unneeded. However, it doesn't hurt to check this anyway, just to be safe.
1 parent cd9d065 commit 45ac5b8

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

db4s/main.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,14 @@ func getHandler(w http.ResponseWriter, r *http.Request, userAcc string) {
283283
}
284284

285285
// The request was for a user directory, so return that list
286-
dbList, err := userDatabaseList(userAcc, pathStrings[1])
286+
desiredUserDir := pathStrings[1]
287+
err := com.ValidateUser(desiredUserDir)
288+
if err != nil {
289+
log.Printf("db4s: Validation failed for username: %s", err)
290+
http.Error(w, err.Error(), http.StatusInternalServerError)
291+
return
292+
}
293+
dbList, err := userDatabaseList(userAcc, desiredUserDir)
287294
if err != nil {
288295
http.Error(w, err.Error(), http.StatusInternalServerError)
289296
return
@@ -296,7 +303,14 @@ func getHandler(w http.ResponseWriter, r *http.Request, userAcc string) {
296303
// TODO: Refactor this and the above identical code. Doing it this way is non-optimal
297304
if pathStrings[2] == "" {
298305
// The request was for a user directory, so return that list
299-
dbList, err := userDatabaseList(userAcc, pathStrings[1])
306+
desiredUserDir := pathStrings[1]
307+
err := com.ValidateUser(desiredUserDir)
308+
if err != nil {
309+
log.Printf("db4s: Validation failed for username: %s", err)
310+
http.Error(w, err.Error(), http.StatusInternalServerError)
311+
return
312+
}
313+
dbList, err := userDatabaseList(userAcc, desiredUserDir)
300314
if err != nil {
301315
http.Error(w, err.Error(), http.StatusInternalServerError)
302316
return
@@ -331,8 +345,7 @@ func getHandler(w http.ResponseWriter, r *http.Request, userAcc string) {
331345
return
332346
}
333347
if !exists {
334-
http.Error(w, fmt.Sprintf("Database '%s%s%s' doesn't exist", dbOwner, dbFolder, dbName),
335-
http.StatusNotFound)
348+
http.Error(w, fmt.Sprintf("Database '%s%s%s' doesn't exist", dbOwner, dbFolder, dbName), http.StatusNotFound)
336349
return
337350
}
338351

0 commit comments

Comments
 (0)