Skip to content
Open
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
4 changes: 3 additions & 1 deletion .mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* THE SOFTWARE.
*/

import io.github.pixee.security.HostValidator;
import io.github.pixee.security.Urls;
import java.net.*;
import java.io.*;
import java.nio.channels.*;
Comment on lines 21 to 28

Choose a reason for hiding this comment

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

The imports for HostValidator and Urls from io.github.pixee.security are included, but there is no indication that these classes are being used in the code. This could lead to confusion and maintainability issues.

Recommended Solution:
Remove the unused imports if they are not necessary. If they are intended for future use, consider adding a comment to clarify their purpose.

Expand Down Expand Up @@ -113,7 +115,7 @@ protected PasswordAuthentication getPasswordAuthentication() {
}
});
}
URL website = new URL(urlString);
URL website = Urls.create(urlString, Urls.HTTP_PROTOCOLS, HostValidator.DENY_COMMON_INFRASTRUCTURE_TARGETS);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
Comment on lines 115 to 121

Choose a reason for hiding this comment

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

The Authenticator class is set with a default username and password from environment variables, but the password is stored in a char[] and not cleared after use. This can lead to potential security issues as the password remains in memory.

Recommended Solution:
Clear the char[] containing the password after it is used to enhance security. This can be done by setting each element of the array to \0 after the PasswordAuthentication object is created.

Expand Down
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<sonar.projectKey>iluwatar_java-design-patterns</sonar.projectKey>
<sonar.moduleKey>${project.artifactId}</sonar.moduleKey>
<sonar.projectName>Java Design Patterns</sonar.projectName>
<versions.java-security-toolkit>1.2.0</versions.java-security-toolkit>
</properties>
<modules>
<module>abstract-factory</module>
Expand Down Expand Up @@ -248,6 +249,11 @@
<version>${system-lambda.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.pixee</groupId>
<artifactId>java-security-toolkit</artifactId>
<version>${versions.java-security-toolkit}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand All @@ -268,6 +274,10 @@
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.github.pixee</groupId>
<artifactId>java-security-toolkit</artifactId>
</dependency>
</dependencies>
<build>
<pluginManagement>
Expand Down
4 changes: 3 additions & 1 deletion promise/src/main/java/com/iluwatar/promise/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
package com.iluwatar.promise;

import io.github.pixee.security.HostValidator;
import io.github.pixee.security.Urls;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
Comment on lines 24 to 31

Choose a reason for hiding this comment

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

The import statements for HostValidator and Urls from the io.github.pixee.security package are not used in the provided code fragment. Unused imports can lead to confusion and should be removed to improve code maintainability and readability.

Expand Down Expand Up @@ -98,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 url = Urls.create(urlString, Urls.HTTP_PROTOCOLS, HostValidator.DENY_COMMON_INFRASTRUCTURE_TARGETS);
var file = File.createTempFile("promise_pattern", null);
try (var bufferedReader = new BufferedReader(new InputStreamReader(url.openStream()));
var writer = new FileWriter(file)) {
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 does not handle potential exceptions that could be thrown by Urls.create. If Urls.create throws an exception, it will not be caught, and the method will fail without providing a meaningful error message. It is important to handle such exceptions to ensure the method can fail gracefully and provide useful feedback.

Recommended Solution:
Wrap the call to Urls.create in a try-catch block and handle the exception appropriately, possibly logging an error message and rethrowing a custom exception if necessary.

Expand Down
Loading