• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tomdesair / tus-java-server / 27493663652

14 Jun 2026 08:46AM UTC coverage: 94.813% (-0.1%) from 94.92%
27493663652

Pull #89

github

web-flow
Merge d2166ca5f into 6d81fd72b
Pull Request #89: 🛡️ Sentinel: [CRITICAL] Fix Path Traversal in AbstractDiskBasedService

621 of 700 branches covered (88.71%)

Branch coverage included in aggregate %.

3 of 4 new or added lines in 1 file covered. (75.0%)

2 existing lines in 1 file now uncovered.

1810 of 1864 relevant lines covered (97.1%)

6.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.41
/src/main/java/me/desair/tus/server/upload/disk/AbstractDiskBasedService.java
1
package me.desair.tus.server.upload.disk;
2

3
import java.io.IOException;
4
import java.nio.file.Files;
5
import java.nio.file.Path;
6
import java.nio.file.Paths;
7
import me.desair.tus.server.TusFileUploadService;
8
import me.desair.tus.server.upload.UploadId;
9
import org.apache.commons.lang3.Validate;
10
import org.slf4j.Logger;
11
import org.slf4j.LoggerFactory;
12

13
/** Common abstract super class to implement service that use the disk file system */
14
public class AbstractDiskBasedService {
15

16
  private static final Logger log = LoggerFactory.getLogger(TusFileUploadService.class);
8✔
17

18
  private Path storagePath;
19

20
  public AbstractDiskBasedService(String path) {
4✔
21
    Validate.notBlank(path, "The storage path cannot be blank");
12✔
22
    this.storagePath = Paths.get(path);
12✔
23
  }
2✔
24

25
  protected Path getStoragePath() {
26
    if (!Files.exists(storagePath)) {
12✔
27
      init();
2✔
28
    }
29
    return storagePath;
6✔
30
  }
31

32
  protected Path getPathInStorageDirectory(UploadId id) {
33
    if (!Files.exists(storagePath)) {
12✔
34
      init();
4✔
35
    }
36

37
    if (id == null) {
4✔
38
      return null;
4✔
39
    } else {
40
      Path path = storagePath.resolve(id.toString());
12✔
41
      if (!path.normalize().toAbsolutePath().startsWith(storagePath.normalize().toAbsolutePath())) {
18!
NEW
42
        throw new IllegalArgumentException("Upload ID is not valid and would result in a path traversal");
×
43
      }
44
      return path;
4✔
45
    }
46
  }
47

48
  private synchronized void init() {
49
    if (!Files.exists(storagePath)) {
12!
50
      try {
51
        Files.createDirectories(storagePath);
12✔
UNCOV
52
      } catch (IOException e) {
×
53
        String message =
×
54
            "Unable to create the directory specified by the storage path " + storagePath;
UNCOV
55
        log.error(message, e);
×
56
        throw new StoragePathNotAvailableException(message, e);
×
57
      }
2✔
58
    }
59
  }
2✔
60
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc