Skip to content

Commit a5cb357

Browse files
Fix code scanning alert no. 8: Cross-site scripting
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 368d2d0 commit a5cb357

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

feign-form/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030

3131
<name>Open Feign Forms Core</name>
3232
<dependencies>
33+
<dependency>
34+
<groupId>org.apache.commons</groupId>
35+
<artifactId>commons-text</artifactId>
36+
<version>1.12.0</version>
37+
</dependency>
3338
<dependency>
3439
<groupId>org.projectlombok</groupId>
3540
<artifactId>lombok</artifactId>

feign-form/src/test/java/feign/form/Server.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.IOException;
2929
import java.util.Collection;
3030
import java.util.List;
31+
import org.apache.commons.text.StringEscapeUtils;
3132
import lombok.val;
3233
import org.springframework.boot.autoconfigure.SpringBootApplication;
3334
import org.springframework.http.HttpStatus;
@@ -166,8 +167,9 @@ public ResponseEntity<String> uploadUnknownType(@RequestPart("file") MultipartFi
166167
@PostMapping(path = "/upload/form_data", consumes = MULTIPART_FORM_DATA_VALUE)
167168
public ResponseEntity<String> uploadFormData(@RequestPart("file") MultipartFile file) {
168169
val status = file != null ? OK : I_AM_A_TEAPOT;
170+
String sanitizedFilename = StringEscapeUtils.escapeHtml4(file.getOriginalFilename());
169171
return ResponseEntity.status(status)
170-
.body(file.getOriginalFilename() + ':' + file.getContentType());
172+
.body(sanitizedFilename + ':' + file.getContentType());
171173
}
172174

173175
@PostMapping(path = "/submit/url", consumes = APPLICATION_FORM_URLENCODED_VALUE)

0 commit comments

Comments
 (0)