mirror of
https://github.com/github/codeql.git
synced 2025-12-23 12:16:33 +01:00
C++: Convert to C++ and make it look more like SensitiveExprs.qll.
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
/**
|
||||
* Provides classes and predicates for identifying private data and methods for security.
|
||||
* Provides classes for heuristically identifying variables and functions that
|
||||
* might contain or return sensitive private data.
|
||||
*
|
||||
* 'Private' data in general is anything that would compromise user privacy if exposed. This
|
||||
* library tries to guess where private data may either be stored in a variable or produced by a
|
||||
* method.
|
||||
* 'Private' data in general is anything that would compromise user privacy if
|
||||
* exposed. This library tries to guess where private data may either be stored
|
||||
* in a variable or returned by a function call.
|
||||
*
|
||||
* This library is not concerned with credentials. See `SensitiveActions` for expressions related
|
||||
* to credentials.
|
||||
* This library is not concerned with credentials. See `SensitiveExprs.qll` for
|
||||
* expressions related to credentials.
|
||||
*/
|
||||
|
||||
import csharp
|
||||
import semmle.code.csharp.frameworks.system.windows.Forms
|
||||
import cpp
|
||||
|
||||
/** A string for `match` that identifies strings that look like they represent private data. */
|
||||
private string privateNames() {
|
||||
@@ -32,35 +32,32 @@ private string privateNames() {
|
||||
]
|
||||
}
|
||||
|
||||
/** An expression that might contain private data. */
|
||||
abstract class PrivateDataExpr extends Expr { }
|
||||
|
||||
/** A method call that might produce private data. */
|
||||
class PrivateMethodCall extends PrivateDataExpr, MethodCall {
|
||||
PrivateMethodCall() {
|
||||
exists(string s | this.getTarget().getName().toLowerCase() = s | s.matches(privateNames()))
|
||||
/**
|
||||
* A variable that might contain sensitive private information.
|
||||
*/
|
||||
class PrivateDataVariable extends Variable {
|
||||
PrivateDataVariable() {
|
||||
this.getName().toLowerCase().matches(privateNames()) and
|
||||
not this.getUnspecifiedType() instanceof IntegralType
|
||||
}
|
||||
}
|
||||
|
||||
/** An indexer access that might produce private data. */
|
||||
class PrivateIndexerAccess extends PrivateDataExpr, IndexerAccess {
|
||||
PrivateIndexerAccess() {
|
||||
exists(string s | this.getAnIndex().getValue().toLowerCase() = s | s.matches(privateNames()))
|
||||
/**
|
||||
* A function that might return sensitive private information.
|
||||
*/
|
||||
class PrivateDataFunction extends Function {
|
||||
PrivateDataFunction() {
|
||||
this.getName().toLowerCase().matches(privateNames()) and
|
||||
not this.getUnspecifiedType() instanceof IntegralType
|
||||
}
|
||||
}
|
||||
|
||||
/** An access to a variable that might contain private data. */
|
||||
class PrivateVariableAccess extends PrivateDataExpr, VariableAccess {
|
||||
PrivateVariableAccess() {
|
||||
exists(string s | this.getTarget().getName().toLowerCase() = s | s.matches(privateNames()))
|
||||
}
|
||||
}
|
||||
|
||||
/** Reading the text property of a control that might contain private data. */
|
||||
class PrivateControlAccess extends PrivateDataExpr {
|
||||
PrivateControlAccess() {
|
||||
exists(TextControl c |
|
||||
this = c.getARead() and c.getName().toLowerCase().matches(privateNames())
|
||||
)
|
||||
/**
|
||||
* An expression whose value might be sensitive private information.
|
||||
*/
|
||||
class PrivateDataExpr extends Expr {
|
||||
PrivateDataExpr() {
|
||||
this.(VariableAccess).getTarget() instanceof PrivateDataVariable or
|
||||
this.(FunctionCall).getTarget() instanceof PrivateDataFunction
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user