Skip to content

Commit 7d790c9

Browse files
committed
Solve CodeQL issues: re-apply sanitizations closer so it could trace them
1 parent 8d4f8ea commit 7d790c9

4 files changed

Lines changed: 12 additions & 9 deletions

File tree

internal/app/handlers.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,7 @@ type metapayload struct {
222222
}
223223

224224
func userID(c *gin.Context) string {
225-
//TODO: suppress the warning
226-
//codeql[go/path-injection]
227-
return c.GetString(userIDKey)
225+
return common.SanitizeUid(c.GetString(userIDKey))
228226
}
229227

230228
func extFromContentType(contentType string) (string, error) {

internal/storage/fs/blobstore.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ func (fs *FileSystemStorage) GetBlobURL(uid, blobid string, write bool) (docurl
4545

4646
// LoadBlob Opens a blob by id
4747
func (fs *FileSystemStorage) LoadBlob(uid, blobid string) (reader io.ReadCloser, size int64, hash string, err error) {
48-
blobPath := path.Join(fs.getUserBlobPath(uid), common.Sanitize(blobid))
48+
uid = common.SanitizeUid(uid)
49+
blobid = common.Sanitize(blobid)
50+
blobPath := path.Join(fs.getUserBlobPath(uid), blobid)
4951
log.Debugln("Fullpath:", blobPath)
5052

5153
fi, err := os.Stat(blobPath)
@@ -77,7 +79,9 @@ func (fs *FileSystemStorage) LoadBlob(uid, blobid string) (reader io.ReadCloser,
7779
func (fs *FileSystemStorage) StoreBlob(uid, id string, fileName string, hash string, stream io.Reader) error {
7880
log.Debugf("TODO: check/save etc. write file '%s', hash '%s'", fileName, hash)
7981

80-
blobPath := path.Join(fs.getUserBlobPath(uid), common.Sanitize(id))
82+
uid = common.SanitizeUid(uid)
83+
id = common.Sanitize(id)
84+
blobPath := path.Join(fs.getUserBlobPath(uid), id)
8185
log.Info("Write: ", blobPath)
8286
file, err := os.Create(blobPath)
8387
if err != nil {

internal/storage/fs/rootstorage.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func readRootIndex(historyPath string) (string, int64, error) {
5454
}
5555

5656
func (fs *FileSystemStorage) GetRootIndex(uid string) (string, int64, error) {
57+
uid = common.SanitizeUid(uid)
5758
historyPath := fs.getPathFromUser(uid, historyFile)
5859

5960
lock, err := fslock.Lock(historyPath)
@@ -67,6 +68,7 @@ func (fs *FileSystemStorage) GetRootIndex(uid string) (string, int64, error) {
6768
}
6869

6970
func (fs *FileSystemStorage) UpdateRoot(uid string, stream io.Reader, lastGen int64) (int64, error) {
71+
uid = common.SanitizeUid(uid)
7072
historyPath := fs.getPathFromUser(uid, historyFile)
7173

7274
lock, err := fslock.Lock(historyPath)
@@ -86,7 +88,8 @@ func (fs *FileSystemStorage) UpdateRoot(uid string, stream io.Reader, lastGen in
8688
if currentGen > 0 {
8789
rootHash, _, rootErr := readRootIndex(historyPath)
8890
if rootErr == nil && rootHash != "" {
89-
blobPath := path.Join(fs.getUserBlobPath(uid), common.Sanitize(rootHash))
91+
rootHash = common.Sanitize(rootHash)
92+
blobPath := path.Join(fs.getUserBlobPath(uid), rootHash)
9093
_, blobErr := os.Stat(blobPath)
9194
rootExists = blobErr == nil
9295
}

internal/ui/handlers.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ const (
3232
)
3333

3434
func userID(c *gin.Context) string {
35-
//TODO: suppress the warning
36-
//codeql[go/path-injection]
37-
return c.GetString(userIDContextKey)
35+
return common.SanitizeUid(c.GetString(userIDContextKey))
3836
}
3937

4038
func (app *ReactAppWrapper) register(c *gin.Context) {

0 commit comments

Comments
 (0)