1
1
/**
2
- * Provides classes and predicates for identifying private data and methods for security.
2
+ * Provides classes for heuristically identifying variables and functions that
3
+ * might contain or return sensitive private data.
3
4
*
4
- * 'Private' data in general is anything that would compromise user privacy if exposed. This
5
- * library tries to guess where private data may either be stored in a variable or produced by a
6
- * method .
5
+ * 'Private' data in general is anything that would compromise user privacy if
6
+ * exposed. This library tries to guess where private data may either be stored
7
+ * in a variable or returned by a function call .
7
8
*
8
- * This library is not concerned with credentials. See `SensitiveActions ` for expressions related
9
- * to credentials.
9
+ * This library is not concerned with credentials. See `SensitiveExprs.qll ` for
10
+ * expressions related to credentials.
10
11
*/
11
12
12
- import csharp
13
- import semmle.code.csharp.frameworks.system.windows.Forms
13
+ import cpp
14
14
15
15
/** A string for `match` that identifies strings that look like they represent private data. */
16
16
private string privateNames ( ) {
@@ -32,35 +32,32 @@ private string privateNames() {
32
32
]
33
33
}
34
34
35
- /** An expression that might contain private data. */
36
- abstract class PrivateDataExpr extends Expr { }
37
-
38
- /** A method call that might produce private data. */
39
- class PrivateMethodCall extends PrivateDataExpr , MethodCall {
40
- PrivateMethodCall ( ) {
41
- exists ( string s | this .getTarget ( ) .getName ( ) .toLowerCase ( ) = s | s .matches ( privateNames ( ) ) )
42
- }
43
- }
44
-
45
- /** An indexer access that might produce private data. */
46
- class PrivateIndexerAccess extends PrivateDataExpr , IndexerAccess {
47
- PrivateIndexerAccess ( ) {
48
- exists ( string s | this .getAnIndex ( ) .getValue ( ) .toLowerCase ( ) = s | s .matches ( privateNames ( ) ) )
35
+ /**
36
+ * A variable that might contain sensitive private information.
37
+ */
38
+ class PrivateDataVariable extends Variable {
39
+ PrivateDataVariable ( ) {
40
+ this .getName ( ) .toLowerCase ( ) .matches ( privateNames ( ) ) and
41
+ not this .getUnspecifiedType ( ) instanceof IntegralType
49
42
}
50
43
}
51
44
52
- /** An access to a variable that might contain private data. */
53
- class PrivateVariableAccess extends PrivateDataExpr , VariableAccess {
54
- PrivateVariableAccess ( ) {
55
- exists ( string s | this .getTarget ( ) .getName ( ) .toLowerCase ( ) = s | s .matches ( privateNames ( ) ) )
45
+ /**
46
+ * A function that might return sensitive private information.
47
+ */
48
+ class PrivateDataFunction extends Function {
49
+ PrivateDataFunction ( ) {
50
+ this .getName ( ) .toLowerCase ( ) .matches ( privateNames ( ) ) and
51
+ not this .getUnspecifiedType ( ) instanceof IntegralType
56
52
}
57
53
}
58
54
59
- /** Reading the text property of a control that might contain private data. */
60
- class PrivateControlAccess extends PrivateDataExpr {
61
- PrivateControlAccess ( ) {
62
- exists ( TextControl c |
63
- this = c .getARead ( ) and c .getName ( ) .toLowerCase ( ) .matches ( privateNames ( ) )
64
- )
55
+ /**
56
+ * An expression whose value might be sensitive private information.
57
+ */
58
+ class PrivateDataExpr extends Expr {
59
+ PrivateDataExpr ( ) {
60
+ this .( VariableAccess ) .getTarget ( ) instanceof PrivateDataVariable or
61
+ this .( FunctionCall ) .getTarget ( ) instanceof PrivateDataFunction
65
62
}
66
63
}
0 commit comments