Skip to content
Merged
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
3 changes: 2 additions & 1 deletion promise/src/main/java/com/iluwatar/promise/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.file.Files;
import java.util.Collections;
import java.util.Comparator;
import java.util.Map;
Comment on lines 31 to 37

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Utility class imports and uses a wide range of functionalities (I/O, networking, and collections). This could lead to violations of the Single Responsibility Principle (SRP). Consider refactoring this class into more focused classes that handle specific types of operations to improve modularity and maintainability.

Expand Down Expand Up @@ -99,7 +100,7 @@ public static Integer countLines(String fileLocation) {
public static String downloadFile(String urlString) throws IOException {
LOGGER.info("Downloading contents from url: {}", urlString);
var url = new URL(urlString);
var file = File.createTempFile("promise_pattern", null);
var file = Files.createTempFile("promise_pattern", null).toFile();
try (var bufferedReader = new BufferedReader(new InputStreamReader(url.openStream()));
var writer = new FileWriter(file)) {
String line;
Comment on lines 100 to 106

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The downloadFile method lacks validation for the urlString parameter. This could expose the application to security risks such as SSRF (Server-Side Request Forgery). It is recommended to implement input validation for URLs to ensure they are within expected and safe boundaries before processing them.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Micro-Learning Topic: Server-side request forgery (Detected by phrase)

Matched on "Server-Side Request Forgery"

What is this? (2min video)

Server-Side Request Forgery (SSRF) vulnerabilities are caused when an attacker can supply or modify a URL that reads or sends data to the server. The attacker can create a malicious request with a manipulated URL, when this request reaches the server, the server-side code executes the exploit URL causing the attacker to be able to read data from services that shouldn't be exposed.

Try a challenge in Secure Code Warrior

Expand Down
Loading