mirror of
https://github.com/corda/corda.git
synced 2025-02-21 09:51:57 +00:00
Forbid internal classes from being serialised. (#655)
This commit is contained in:
parent
bcf4c4a2bb
commit
ea53bab7d7
@ -472,4 +472,7 @@ fun <T> Class<T>.checkNotUnorderedHashMap() {
|
|||||||
if (HashMap::class.java.isAssignableFrom(this) && !LinkedHashMap::class.java.isAssignableFrom(this)) {
|
if (HashMap::class.java.isAssignableFrom(this) && !LinkedHashMap::class.java.isAssignableFrom(this)) {
|
||||||
throw NotSerializableException("Map type $this is unstable under iteration. Suggested fix: use LinkedHashMap instead.")
|
throw NotSerializableException("Map type $this is unstable under iteration. Suggested fix: use LinkedHashMap instead.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Class<*>.requireExternal(msg: String = "Internal class")
|
||||||
|
= require(!name.startsWith("net.corda.node.") && !name.contains(".internal.")) { "$msg: $name" }
|
||||||
|
@ -5,6 +5,7 @@ package net.corda.nodeapi
|
|||||||
import com.esotericsoftware.kryo.Registration
|
import com.esotericsoftware.kryo.Registration
|
||||||
import com.esotericsoftware.kryo.Serializer
|
import com.esotericsoftware.kryo.Serializer
|
||||||
import com.google.common.util.concurrent.ListenableFuture
|
import com.google.common.util.concurrent.ListenableFuture
|
||||||
|
import net.corda.core.requireExternal
|
||||||
import net.corda.core.serialization.*
|
import net.corda.core.serialization.*
|
||||||
import net.corda.core.toFuture
|
import net.corda.core.toFuture
|
||||||
import net.corda.core.toObservable
|
import net.corda.core.toObservable
|
||||||
@ -60,6 +61,7 @@ class RPCKryo(observableSerializer: Serializer<Observable<Any>>) : CordaKryo(mak
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getRegistration(type: Class<*>): Registration {
|
override fun getRegistration(type: Class<*>): Registration {
|
||||||
|
type.requireExternal("RPC not allowed to deserialise internal classes")
|
||||||
if (Observable::class.java != type && Observable::class.java.isAssignableFrom(type)) {
|
if (Observable::class.java != type && Observable::class.java.isAssignableFrom(type)) {
|
||||||
return super.getRegistration(Observable::class.java)
|
return super.getRegistration(Observable::class.java)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user