forked from Marcono1234/codeql-java-queries
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaSerialization.qll
More file actions
135 lines (123 loc) · 3.52 KB
/
Copy pathJavaSerialization.qll
File metadata and controls
135 lines (123 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import java
/**
* `java.io.Externalizable`
*/
class TypeExternalizable extends Interface {
TypeExternalizable() {
hasQualifiedName("java.io", "Externalizable")
}
}
/**
* The method `Externalizable.writeExternal(ObjectOutput)`.
*/
class ExternalizableWriteExternalMethod extends Method {
ExternalizableWriteExternalMethod() {
getDeclaringType() instanceof TypeExternalizable
and hasStringSignature("writeExternal(ObjectOutput)")
}
}
/**
* A field which is likely serialized.
*/
class SerializedField extends Field {
SerializedField() {
getDeclaringType().getASourceSupertype*() instanceof TypeSerializable
and not isStatic()
and not isTransient()
}
}
/**
* `serialVersionUID` field.
*/
class SerialVersionUidField extends Field {
SerialVersionUidField() {
hasName("serialVersionUID")
and getType().hasName("long")
and isStatic()
and isFinal()
}
}
/**
* `serialPersistentFields` field.
*/
class SerialPersistentFieldsField extends Field {
SerialPersistentFieldsField() {
hasName("serialPersistentFields")
and isPrivate()
and isStatic()
and isFinal()
}
}
/**
* `readObject(ObjectInputStream)` implemented by a serializable class.
*/
class ReadObjectSerializableMethod extends Method {
ReadObjectSerializableMethod() {
isPrivate()
and hasStringSignature("readObject(ObjectInputStream)")
and getReturnType() instanceof VoidType
and getDeclaringType().getASourceSupertype*() instanceof TypeSerializable
and not isStatic()
}
}
/**
* `readResolve()` implemented by a serializable class.
*/
class ReadResolveSerializableMethod extends Method {
ReadResolveSerializableMethod() {
hasStringSignature("readResolve()")
and getReturnType() instanceof TypeObject
and getDeclaringType().getASourceSupertype*() instanceof TypeSerializable
and not isStatic()
}
}
/**
* `writeObject(ObjectOutputStream)` implemented by a serializable class.
*/
class WriteObjectSerializableMethod extends Method {
WriteObjectSerializableMethod() {
isPrivate()
and hasStringSignature("writeObject(ObjectOutputStream)")
and getReturnType() instanceof VoidType
and getDeclaringType().getASourceSupertype*() instanceof TypeSerializable
and not isStatic()
}
}
/**
* `writeReplace()` implemented by a serializable class.
*/
class WriteReplaceSerializableMethod extends Method {
WriteReplaceSerializableMethod() {
hasStringSignature("writeReplace()")
and getReturnType() instanceof TypeObject
and getDeclaringType().getASourceSupertype*() instanceof TypeSerializable
and not isStatic()
}
}
/**
* `ObjectInputStream.defaultReadObject()`
*/
class DefaultReadObjectMethod extends Method {
DefaultReadObjectMethod() {
getDeclaringType().getASourceSupertype*() instanceof TypeObjectInputStream
and hasStringSignature("defaultReadObject()")
}
}
/**
* `ObjectOutputStream.defaultWriteObject()`
*/
class DefaultWriteObjectMethod extends Method {
DefaultWriteObjectMethod() {
getDeclaringType().getASourceSupertype*() instanceof TypeObjectOutputStream
and hasStringSignature("defaultWriteObject()")
}
}
/**
* `ObjectOutputStream.putFields()`
*/
class PutFieldsMethod extends Method {
PutFieldsMethod() {
getDeclaringType().getASourceSupertype*() instanceof TypeObjectOutputStream
and hasStringSignature("putFields()")
}
}