Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

221 path traversal if path contains rootbucket #358

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ public String resourceKey(AbsoluteLocation resource) {
UnaryOperator<String> trimStartingSlash = str -> str.replaceFirst("^/", "");

String resourcePath = trimStartingSlash.apply(resource.location().getRawPath());
if (bucketName == null || "".equals(bucketName) || !resourcePath.contains(bucketName)) {
if (resourcePath.startsWith("eu-central-1/")) {
resourcePath = resourcePath.substring("eu-central-1/".length());
}

if (bucketName == null || "".equals(bucketName) || !resourcePath.startsWith(bucketName)) {
return resourcePath;
}

return trimStartingSlash.apply(resourcePath.substring(resourcePath.indexOf(bucketName) + bucketName.length()));
return trimStartingSlash.apply(resourcePath.substring(bucketName.length()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import de.adorsys.datasafe.types.api.utils.ExecutorServiceUtil;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.api.AbstractStringAssert;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -27,6 +28,7 @@
import java.io.OutputStream;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static de.adorsys.datasafe.types.api.shared.DockerUtil.getDockerUri;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -91,10 +93,15 @@ void init() {
void list() {
createFileWithMessage();

assertThat(storageService.list(root))
.hasSize(1)
.extracting(AbsoluteLocation::location)
.asString().contains(FILE);
Stream<AbsoluteLocation<ResolvedResource>> list = storageService.list(root);
AbstractStringAssert<?> stringAssert = assertThat(list)
.hasSize(1).extracting(AbsoluteLocation::location)
.asString();
// Adding this line to check if the List is NotEmpty or NotNull
stringAssert.isNotEmpty();
stringAssert.isNotNull();
stringAssert.doesNotContain("java");
stringAssert.contains(FILE);
}

@Test
Expand Down