-
Notifications
You must be signed in to change notification settings - Fork 0
Introduced protections against deserialization attacks #16
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 |
---|---|---|
|
@@ -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> | ||
|
@@ -248,6 +249,12 @@ | |
<version>${system-lambda.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.github.pixee</groupId> | ||
<artifactId>java-security-toolkit</artifactId> | ||
|
||
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. This library holds security tools for protecting Java API calls. License: MIT ✅ | Open source ✅ | More facts |
||
<version>${versions.java-security-toolkit}</version> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<dependencies> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,10 @@ | |
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
</dependency> | ||
<dependency> | ||
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. This library holds security tools for protecting Java API calls. License: MIT ✅ | Open source ✅ | More facts |
||
<groupId>io.github.pixee</groupId> | ||
<artifactId>java-security-toolkit</artifactId> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
*/ | ||
package com.iluwatar.serializedentity; | ||
|
||
import io.github.pixee.security.ObjectInputFilters; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
|
@@ -109,6 +110,7 @@ public int selectCountry() throws IOException, ClassNotFoundException { | |
Blob countryBlob = rs.getBlob("country"); | ||
ByteArrayInputStream baos = new ByteArrayInputStream(countryBlob.getBytes(1, (int) countryBlob.length())); | ||
ObjectInputStream ois = new ObjectInputStream(baos); | ||
Comment on lines
111
to
112
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 method 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: Denial of service (Detected by phrase)Matched on "denial of service"The Denial of Service (DoS) attack is focused on making a resource (site, application, server) unavailable for the purpose it was designed. There are many ways to make a service unavailable for legitimate users by manipulating network packets, programming, logical, or resources handling vulnerabilities, among others. Source: https://www.owasp.org/index.php/Denial_of_Service Try a challenge in Secure Code Warrior |
||
ObjectInputFilters.enableObjectFilterIfUnprotected(ois); | ||
country = (Country) ois.readObject(); | ||
LOGGER.info("Country: " + country); | ||
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. Logging the entire |
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
* THE SOFTWARE. | ||
*/ | ||
package com.iluwatar.serializedentity; | ||
import io.github.pixee.security.ObjectInputFilters; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.*; | ||
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. Using a wildcard import for Recommended Solution: |
||
|
@@ -85,6 +86,7 @@ void testSerializable(){ | |
// De-serialize Country | ||
try { | ||
ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("output.txt")); | ||
ObjectInputFilters.enableObjectFilterIfUnprotected(objectInputStream); | ||
Country country = (Country) objectInputStream.readObject(); | ||
objectInputStream.close(); | ||
System.out.println(country); | ||
Comment on lines
91
to
92
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. Using Recommended Solution:
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,10 @@ | |
<artifactId>junit-jupiter-engine</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
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. This library holds security tools for protecting Java API calls. License: MIT ✅ | Open source ✅ | More facts |
||
<groupId>io.github.pixee</groupId> | ||
<artifactId>java-security-toolkit</artifactId> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
*/ | ||
package com.iluwatar.tolerantreader; | ||
|
||
import io.github.pixee.security.ObjectInputFilters; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
Comment on lines
28
to
29
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 direct use of interface DataStreamFactory {
InputStream createInputStream(String path) throws IOException;
OutputStream createOutputStream(String path) throws IOException;
} This approach allows for easier mocking during testing and can accommodate different storage mechanisms without modifying the core serialization logic. |
||
import java.io.IOException; | ||
|
@@ -90,6 +91,7 @@ public static RainbowFish readV1(String filename) throws IOException, ClassNotFo | |
|
||
try (var fileIn = new FileInputStream(filename); | ||
var objIn = new ObjectInputStream(fileIn)) { | ||
ObjectInputFilters.enableObjectFilterIfUnprotected(objIn); | ||
map = (Map<String, String>) objIn.readObject(); | ||
Comment on lines
+94
to
95
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 use of ObjectInputFilter filter = ObjectInputFilter.Config.createFilter("com.iluwatar.*;java.base/*;!");
objIn.setObjectInputFilter(filter); This configuration explicitly allows certain packages while blocking others, reducing the risk of unwanted or malicious object creation during deserialization. |
||
} | ||
|
||
|
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.
This library holds security tools for protecting Java API calls.
License: MIT ✅ | Open source ✅ | More facts