Going forward with #33687 we are going to drop support for relative paths entirely. For the current 6.1.x branch, we can revise handling with the understanding that while the use case is still supported it is also likely not very common.

Comment From: andreybpanfilov

@rstoyanchev

it seems the initial issue (path traversal via symlinks) was caused by the fact the FileSystemResource class does not keep in sync path, file and filePath fields:

    public FileSystemResource(String path) {
        Assert.notNull(path, "Path must not be null");
        this.path = StringUtils.cleanPath(path);
        this.file = new File(path);  <---- should be new File(this.path)
        this.filePath = this.file.toPath();
    }

compare with:

    public FileSystemResource(FileSystem fileSystem, String path) {
        Assert.notNull(fileSystem, "FileSystem must not be null");
        Assert.notNull(path, "Path must not be null");
        this.path = StringUtils.cleanPath(path);
        this.file = null;
        this.filePath = fileSystem.getPath(this.path).normalize();
    }