Skip to content
Closed
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: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2024-05-24 - [Insecure Deserialization Fix]
**Vulnerability:** The `Utils.readSerializable` function deserialized objects directly from `ObjectInputStream`, which can lead to insecure deserialization attacks if the stored data is tampered with.
**Learning:** `commons-io` provides `ValidatingObjectInputStream` to limit deserialization to specific allowed classes (`java.lang.*`, `java.util.*`, `me.desair.tus.server.upload.*`, `me.desair.tus.server.checksum.*`).
**Prevention:** Always use `ValidatingObjectInputStream` or equivalent mechanisms to restrict class loading when deserializing data, even if it comes from local storage, to prevent arbitrary code execution in case the storage layer is compromised.
10 changes: 8 additions & 2 deletions src/main/java/me/desair/tus/server/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import jakarta.servlet.http.HttpServletRequest;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
Expand All @@ -22,6 +21,7 @@
import java.util.regex.Pattern;
import me.desair.tus.server.HttpHeader;
import me.desair.tus.server.checksum.ChecksumAlgorithm;
import org.apache.commons.io.serialization.ValidatingObjectInputStream;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -83,7 +83,13 @@ public static <T> T readSerializable(Path path, Class<T> clazz) throws IOExcepti
// Lock will be released when the channel is closed
if (lockFileShared(channel) != null) {

try (ObjectInputStream ois = new ObjectInputStream(Channels.newInputStream(channel))) {
try (ValidatingObjectInputStream ois =
new ValidatingObjectInputStream(Channels.newInputStream(channel))) {
ois.accept(clazz);
ois.accept("java.lang.*");
ois.accept("java.util.*");
ois.accept("me.desair.tus.server.upload.*");
ois.accept("me.desair.tus.server.checksum.*");
info = clazz.cast(ois.readObject());
} catch (ClassNotFoundException
| java.io.EOFException
Expand Down
Loading