-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Security: fix(spanner), implement look-ahead deserialization filtering in CloudClientExecutor #12308
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
base: main
Are you sure you want to change the base?
Security: fix(spanner), implement look-ahead deserialization filtering in CloudClientExecutor #12308
Changes from 1 commit
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -166,17 +166,22 @@ | |||||
| import java.io.ByteArrayInputStream; | ||||||
| import java.io.File; | ||||||
| import java.io.IOException; | ||||||
| import java.io.InvalidClassException; | ||||||
| import java.io.ObjectInputStream; | ||||||
| import java.io.ObjectOutputStream; | ||||||
| import java.io.ObjectStreamClass; | ||||||
| import java.io.Serializable; | ||||||
| import java.math.BigDecimal; | ||||||
| import java.text.ParseException; | ||||||
| import java.time.Duration; | ||||||
| import java.time.LocalDate; | ||||||
| import java.util.ArrayList; | ||||||
| import java.util.Arrays; | ||||||
| import java.util.HashSet; | ||||||
| import java.util.List; | ||||||
| import java.util.Map; | ||||||
| import java.util.Objects; | ||||||
| import java.util.Set; | ||||||
| import java.util.UUID; | ||||||
| import java.util.concurrent.ExecutionException; | ||||||
| import java.util.concurrent.Executor; | ||||||
|
|
@@ -3795,11 +3800,38 @@ private static com.google.spanner.v1.Type cloudTypeToTypeProto(@Nonnull Type clo | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| /** Define the Allowlist: ONLY allow specific, safe internal classes */ | ||||||
| private static final Set<String> ALLOWED_CLASSES = new HashSet<>(Arrays.asList( | ||||||
| "com.google.cloud.spanner.partitionOptions", | ||||||
| "com.google.cloud.spanner.partition", | ||||||
| "com.google.cloud.spanner.BatchTransactionId", | ||||||
| "java.util.ArrayList", | ||||||
| "java.lang.Number", | ||||||
| "java.lang.Long", | ||||||
| "java.lang.Integer" | ||||||
| )); | ||||||
|
|
||||||
| /** Unmarshall ByteString to serializable object. */ | ||||||
| private <T extends Serializable> T unmarshall(ByteString input) | ||||||
| throws IOException, ClassNotFoundException { | ||||||
| ObjectInputStream objectInputStream = new ObjectInputStream(input.newInput()); | ||||||
| return (T) objectInputStream.readObject(); | ||||||
| private <T extends Serializable> T unmarshall(ByteString input) throws Exception { | ||||||
|
Contributor
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
Suggested change
|
||||||
| try (InputStream is = input.newInput(); | ||||||
| ObjectInputStream ois = new SecureObjectInputStream(is)) { | ||||||
| return (T) ois.readObject(); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /** The "Look-ahead" Filter */ | ||||||
| private static class SecureObjectInputStream extends ObjectInputStream { | ||||||
| public SecureObjectInputStream(InputStream in) throws IOException { | ||||||
| super(in); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { | ||||||
| if (!ALLOWED_CLASSES.contains(desc.getName())) { | ||||||
| throw new InvalidClassException("Unauthorized deserialization attempt: ", desc.getName()); | ||||||
| } | ||||||
| return super.resolveClass(desc); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /** Marshall a serializable object into ByteString. */ | ||||||
|
|
||||||
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 class names
com.google.cloud.spanner.partitionOptionsandcom.google.cloud.spanner.partitionin theALLOWED_CLASSESset appear to be incorrect. Based on standard Java naming conventions and the pull request description mentioningcom.google.cloud.spanner.Partition, these should likely start with an uppercase letter (e.g.,PartitionandPartitionOptions). If these names are wrong, legitimate deserialization for partitioned reads/queries will fail with anInvalidClassException, breaking existing functionality.