-
Notifications
You must be signed in to change notification settings - Fork 0
Modernize and secure temp file creation #13
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"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 |
||
|
There was a problem hiding this comment.
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.