-
Notifications
You must be signed in to change notification settings - Fork 0
Introduced protections against deserialization attacks #3
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.1.3</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); | ||
ObjectInputFilters.enableObjectFilterIfUnprotected(ois); | ||
country = (Country) ois.readObject(); | ||
LOGGER.info("Country: " + country); | ||
Comment on lines
111
to
115
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 code is vulnerable to Java deserialization attacks because it deserializes objects without validating the source or the content of the serialized data. This can lead to various attacks, including arbitrary code execution if the application is processing data from untrusted sources. To mitigate this risk, it's recommended to implement a more secure form of serialization or use a library that provides safe deserialization features. Additionally, consider using validation mechanisms such as custom |
||
} | ||
|
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; | ||
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
92
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 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. Casting the result of |
||
} | ||
|
||
|
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