|
| 1 | +/** |
| 2 | + * Provides classes and predicates for identifying sensitive data. |
| 3 | + * |
| 4 | + * 'Sensitive' data is anything that should not be sent in unencrypted form. This library tries to |
| 5 | + * guess where sensitive data may either be stored in a variable or produced by a method. |
| 6 | + */ |
| 7 | + |
| 8 | +import unified |
| 9 | +import codeql.concepts.internal.SensitiveDataHeuristics |
| 10 | +private import codeql.unified.internal.typeinference.TypeInference as TypeInference |
| 11 | + |
| 12 | +/** |
| 13 | + * A data flow node that might contain sensitive data. |
| 14 | + */ |
| 15 | +cached |
| 16 | +abstract class SensitiveData extends DataFlow::Node { |
| 17 | + /** |
| 18 | + * Gets the classification of sensitive data this expression might contain. |
| 19 | + */ |
| 20 | + cached |
| 21 | + abstract SensitiveDataClassification getClassification(); |
| 22 | +} |
| 23 | + |
| 24 | +/** |
| 25 | + * An identifier that might contain sensitive data. |
| 26 | + */ |
| 27 | +private class SensitiveDataIdentifier extends SensitiveData { |
| 28 | + SensitiveDataClassification classification; |
| 29 | + |
| 30 | + SensitiveDataIdentifier() { |
| 31 | + exists(IdentifierExpr e | e = this.asExpr() | |
| 32 | + HeuristicNames::nameIndicatesSensitiveData(e.getValue(), classification) |
| 33 | + ) |
| 34 | + } |
| 35 | + |
| 36 | + override SensitiveDataClassification getClassification() { result = classification } |
| 37 | +} |
| 38 | + |
| 39 | +private Expr memberAccessParent(MemberAccessExpr e) { result = e.getParent() } |
| 40 | + |
| 41 | +/** |
| 42 | + * A member access that might contain sensitive data. This includes a member itself and |
| 43 | + * components of a receiver chain, for example: |
| 44 | + * ``` |
| 45 | + * object.password |
| 46 | + * password.value |
| 47 | + * password.getValue() |
| 48 | + * ``` |
| 49 | + */ |
| 50 | +private class SensitiveDataMemberAccess extends SensitiveData { |
| 51 | + SensitiveDataClassification classification; |
| 52 | + |
| 53 | + SensitiveDataMemberAccess() { |
| 54 | + exists(MemberAccessExpr e | memberAccessParent*(e) = this.asExpr() | |
| 55 | + HeuristicNames::nameIndicatesSensitiveData(e.getMemberName(), classification) |
| 56 | + ) |
| 57 | + } |
| 58 | + |
| 59 | + override SensitiveDataClassification getClassification() { result = classification } |
| 60 | +} |
| 61 | + |
| 62 | +/** |
| 63 | + * A function call that might produce sensitive data. |
| 64 | + */ |
| 65 | +private class SensitiveDataCall extends SensitiveData { |
| 66 | + SensitiveDataClassification classification; |
| 67 | + |
| 68 | + SensitiveDataCall() { |
| 69 | + exists(CallExpr call, string name | |
| 70 | + call = this.asExpr() and |
| 71 | + name = |
| 72 | + [ |
| 73 | + call.getCallee().(Identifier).getValue(), |
| 74 | + call.getCallee().(MemberAccessExpr).getMemberName() |
| 75 | + ] and |
| 76 | + HeuristicNames::nameIndicatesSensitiveData(name, classification) |
| 77 | + ) |
| 78 | + } |
| 79 | + |
| 80 | + override SensitiveDataClassification getClassification() { result = classification } |
| 81 | +} |
0 commit comments