Skip to content

Commit 5068453

Browse files
authored
Add documentation for taint configuration (#223)
1 parent bf3f6b4 commit 5068453

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

jacodb-taint-configuration/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Module jacodb-configuration
2+
3+
A module that contains a format suitable for taint configuration of static analyses.

jacodb-taint-configuration/src/main/kotlin/org/jacodb/taint/configuration/Position.kt

+24
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,55 @@ fun interface PositionResolver<out R> {
2323
fun resolve(position: Position): R
2424
}
2525

26+
/**
27+
* A representation of a position of tainted data.
28+
*/
2629
@Serializable
2730
sealed interface Position
2831

32+
/**
33+
* Represents an argument of a method call.
34+
* Numeration starts from zero, `this` parameter is not included.
35+
*
36+
* For instance, `obj.foo(a, b)` -> `a := Argument(0)`, `b := Argument(1)`
37+
*/
2938
@Serializable
3039
@SerialName("Argument")
3140
data class Argument(@SerialName("number") val index: Int) : Position
3241

42+
/**
43+
* Represents any argument of a method call except `this` instance,
44+
* This is a short form for a set of [Argument]s with all indices of the method parameters.
45+
*/
3346
@Serializable
3447
@SerialName("AnyArgument")
3548
object AnyArgument : Position {
3649
override fun toString(): String = javaClass.simpleName
3750
}
3851

52+
/**
53+
* Represents `this` argument of a method call.
54+
*/
3955
@Serializable
4056
@SerialName("This")
4157
object This : Position {
4258
override fun toString(): String = javaClass.simpleName
4359
}
4460

61+
/**
62+
* Represents the resulting value of a method call.
63+
* It is for regularly returned objects only, and it is not suitable for thrown exceptions.
64+
*/
4565
@Serializable
4666
@SerialName("Result")
4767
object Result : Position {
4868
override fun toString(): String = javaClass.simpleName
4969
}
5070

71+
/**
72+
* Represents any element of the collection (string, array, list, etc.),
73+
* returned as a result from a method call.
74+
*/
5175
@Serializable
5276
@SerialName("ResultAnyElement")
5377
object ResultAnyElement : Position {

jacodb-taint-configuration/src/main/kotlin/org/jacodb/taint/configuration/TaintAction.kt

+19
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ val actionModule = SerializersModule {
4646

4747
// TODO add marks for aliases (if you pass an object and return it from the function)
4848

49+
/**
50+
* Copies all the marks from the [from] object to the [to].
51+
* As a result, all marks from the initial object will be copied into the target object.
52+
* If some marks were present only in the [to] object, they remain unchanged.
53+
*
54+
* Behaviour should be the same as if [CopyMark] is applied to every existing mark.
55+
*/
4956
@Serializable
5057
@SerialName("CopyAllMarks")
5158
data class CopyAllMarks(
@@ -55,6 +62,9 @@ data class CopyAllMarks(
5562
override fun <R> accept(visitor: TaintActionVisitor<R>): R = visitor.visit(this)
5663
}
5764

65+
/**
66+
* Adds the [mark] to the [to] object if it is present in the [from] object.
67+
*/
5868
@Serializable
5969
@SerialName("CopyMark")
6070
data class CopyMark(
@@ -65,6 +75,9 @@ data class CopyMark(
6575
override fun <R> accept(visitor: TaintActionVisitor<R>): R = visitor.visit(this)
6676
}
6777

78+
/**
79+
* Assigns the [mark] to the [position].
80+
*/
6881
@Serializable
6982
@SerialName("AssignMark")
7083
data class AssignMark(
@@ -74,6 +87,9 @@ data class AssignMark(
7487
override fun <R> accept(visitor: TaintActionVisitor<R>): R = visitor.visit(this)
7588
}
7689

90+
/**
91+
* Removes all the marks from the [position].
92+
*/
7793
@Serializable
7894
@SerialName("RemoveAllMarks")
7995
data class RemoveAllMarks(
@@ -82,6 +98,9 @@ data class RemoveAllMarks(
8298
override fun <R> accept(visitor: TaintActionVisitor<R>): R = visitor.visit(this)
8399
}
84100

101+
/**
102+
* Removes a particular [mark] from the [position].
103+
*/
85104
@Serializable
86105
@SerialName("RemoveMark")
87106
data class RemoveMark(

jacodb-taint-configuration/src/main/kotlin/org/jacodb/taint/configuration/TaintCondition.kt

+42
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ val conditionModule = SerializersModule {
6363
}
6464
}
6565

66+
/**
67+
* A constant true condition.
68+
*/
6669
@Serializable
6770
@SerialName("ConstantTrue")
6871
object ConstantTrue : Condition {
@@ -71,6 +74,9 @@ object ConstantTrue : Condition {
7174
override fun toString(): String = javaClass.simpleName
7275
}
7376

77+
/**
78+
* A negation of the [arg].
79+
*/
7480
@Serializable
7581
@SerialName("Not")
7682
data class Not(
@@ -79,6 +85,9 @@ data class Not(
7985
override fun <R> accept(conditionVisitor: ConditionVisitor<R>): R = conditionVisitor.visit(this)
8086
}
8187

88+
/**
89+
* A conjunction of the [args].
90+
*/
8291
@Serializable
8392
@SerialName("And")
8493
data class And(
@@ -87,6 +96,9 @@ data class And(
8796
override fun <R> accept(conditionVisitor: ConditionVisitor<R>): R = conditionVisitor.visit(this)
8897
}
8998

99+
/**
100+
* A disjunction of the [args].
101+
*/
90102
@Serializable
91103
@SerialName("Or")
92104
data class Or(
@@ -95,6 +107,10 @@ data class Or(
95107
override fun <R> accept(conditionVisitor: ConditionVisitor<R>): R = conditionVisitor.visit(this)
96108
}
97109

110+
/**
111+
* A condition that an object at the [position] is a constant value,
112+
* not an environment variable or a method parameter.
113+
*/
98114
@Serializable
99115
@SerialName("IsConstant")
100116
data class IsConstant(
@@ -103,6 +119,9 @@ data class IsConstant(
103119
override fun <R> accept(conditionVisitor: ConditionVisitor<R>): R = conditionVisitor.visit(this)
104120
}
105121

122+
/**
123+
* A condition that an object at the [position] matches with the [typeMatcher].
124+
*/
106125
@Serializable
107126
@SerialName("IsType")
108127
data class IsType(
@@ -112,6 +131,9 @@ data class IsType(
112131
override fun <R> accept(conditionVisitor: ConditionVisitor<R>): R = conditionVisitor.visit(this)
113132
}
114133

134+
/**
135+
* A condition that an object at the [position] contains an annotation matching with the [typeMatcher].
136+
*/
115137
@Serializable
116138
@SerialName("AnnotationType")
117139
data class AnnotationType(
@@ -121,6 +143,9 @@ data class AnnotationType(
121143
override fun <R> accept(conditionVisitor: ConditionVisitor<R>): R = conditionVisitor.visit(this)
122144
}
123145

146+
/**
147+
* A condition that a value at the [position] is equal to a [value].
148+
*/
124149
@Serializable
125150
@SerialName("ConstantEq")
126151
data class ConstantEq(
@@ -130,6 +155,10 @@ data class ConstantEq(
130155
override fun <R> accept(conditionVisitor: ConditionVisitor<R>): R = conditionVisitor.visit(this)
131156
}
132157

158+
/**
159+
* A condition that a value at the [position] is less than a [value].
160+
* The meaning of `less` is specific for each type of the [ConstantValue].
161+
*/
133162
@Serializable
134163
@SerialName("ConstantLt")
135164
data class ConstantLt(
@@ -139,6 +168,10 @@ data class ConstantLt(
139168
override fun <R> accept(conditionVisitor: ConditionVisitor<R>): R = conditionVisitor.visit(this)
140169
}
141170

171+
/**
172+
* A condition that a value at the [position] is greater than a [value].
173+
* The meaning of `greater` is specific for each type of the [ConstantValue].
174+
*/
142175
@Serializable
143176
@SerialName("ConstantGt")
144177
data class ConstantGt(
@@ -148,6 +181,9 @@ data class ConstantGt(
148181
override fun <R> accept(conditionVisitor: ConditionVisitor<R>): R = conditionVisitor.visit(this)
149182
}
150183

184+
/**
185+
* A condition that a value at the [position] is matching with the [pattern].
186+
*/
151187
@Serializable
152188
@SerialName("ConstantMatches")
153189
data class ConstantMatches(
@@ -166,6 +202,9 @@ data class SourceFunctionMatches(
166202
override fun <R> accept(conditionVisitor: ConditionVisitor<R>): R = conditionVisitor.visit(this)
167203
}
168204

205+
/**
206+
* A condition that a value at the [position] contains the [mark].
207+
*/
169208
@Serializable
170209
@SerialName("ContainsMark")
171210
data class ContainsMark(
@@ -175,6 +214,9 @@ data class ContainsMark(
175214
override fun <R> accept(conditionVisitor: ConditionVisitor<R>): R = conditionVisitor.visit(this)
176215
}
177216

217+
/**
218+
* A condition that a value at the [position] matches exactly with the [type].
219+
*/
178220
@Serializable
179221
@SerialName("TypeMatches")
180222
data class TypeMatches(

0 commit comments

Comments
 (0)