gitgabrio commented on code in PR #3868:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3868#discussion_r2063035562
##########
addons/common/process-svg/src/main/java/org/kie/kogito/svg/AbstractProcessSvgService.java:
##########
@@ -125,4 +126,12 @@ public Optional<String> getProcessInstanceSvg(String
processId, String processIn
return Optional.empty();
}
}
+
+ Path resolveSecure(Path baseDir, String fileName) {
Review Comment:
@bncriju
This is a duplicate of previous method
##########
addons/common/process-svg/src/test/java/org/kie/kogito/svg/AbstractProcessSvgServiceTest.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.svg;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Optional;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.kogito.svg.dataindex.DataIndexClient;
+
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+import static
org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
+
+class AbstractProcessSvgServiceTest {
+ private TestProcessSvgService service;
+
+ @BeforeEach
+ void setUp() {
+ Path securePath =
Paths.get("src/test/resources/META-INF/processSVG").toAbsolutePath();
+ service = new TestProcessSvgService(null,
Optional.of(securePath.toString()),
+ "#C0C0C0", "#030303", "#FF0000");
+ }
+
+ @Test
+ void testResolveSecureAcceptsValidPath() {
+ Path base =
Paths.get("src/test/resources/META-INF/processSVG").toAbsolutePath();
+ Path result = service.callResolveSecure(base, "travels.svg");
Review Comment:
@bncriju
This seems a contrived way to unit test a single method:
1. the tests, behind the scenes, check if the created method behave properly
in different scenarios
1. the method created (`AbstractProcessSvgService.resolveSecure(Path,
String)`) does not need any instance `status`, so it can be `static`
2. modifying it to static, and invoking directly it from your tests, would
remove all the unnecessary setup/overcomplication
##########
addons/common/persistence/filesystem/src/test/java/org/kie/persistence/filesystem/FileSystemProcessInstancesTest.java:
##########
@@ -233,16 +233,57 @@ void testBasicFlowControlledByUnitOfWork() {
assertEmpty(fileSystemBasedStorage);
}
- private class FileSystemProcessInstancesFactory extends
AbstractProcessInstancesFactory {
+ @Test
+ void testResolveSecureRejectsPathTraversalViaFindById() {
Review Comment:
@bncriju
All those tests are fulll integration tests that verify your modification in
very indirect way, and are influenced by too many other conditions: we should
aim to `unit test` the code we write
##########
addons/common/persistence/filesystem/src/main/java/org/kie/kogito/persistence/filesystem/FileSystemProcessInstances.java:
##########
@@ -197,4 +197,13 @@ protected boolean supportsUserDefinedAttributes(Path file)
{
return false;
}
}
+
+ private Path resolveSecure(Path base, String userProvided) {
+ Path target = base.resolve(userProvided).normalize();
+
+ if (!target.startsWith(base)) {
Review Comment:
Hi @bncriju
Could you please create a c ouple of unit test to verify this method,
namely
1. a test where `!target.startsWith(base)` condition is `true`
2. a test where `!target.startsWith(base)` condition is `false`
thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]