Skip to content

Rust: Recognize more sensitive data sources #19470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
May 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 28 additions & 36 deletions rust/ql/lib/codeql/rust/security/SensitiveData.qll
Original file line number Diff line number Diff line change
@@ -22,64 +22,56 @@ abstract class SensitiveData extends DataFlow::Node {
}

/**
* A function that might produce sensitive data.
*/
private class SensitiveDataFunction extends Function {
SensitiveDataClassification classification;

SensitiveDataFunction() {
HeuristicNames::nameIndicatesSensitiveData(this.getName().getText(), classification)
}

SensitiveDataClassification getClassification() { result = classification }
}

/**
* A function call data flow node that might produce sensitive data.
* A function call or enum variant data flow node that might produce sensitive data.
*/
private class SensitiveDataCall extends SensitiveData {
SensitiveDataClassification classification;

SensitiveDataCall() {
classification =
this.asExpr()
.getAstNode()
.(CallExprBase)
.getStaticTarget()
.(SensitiveDataFunction)
.getClassification()
exists(CallExprBase call, string name |
call = this.asExpr().getExpr() and
name =
[
call.getStaticTarget().(Function).getName().getText(),
call.(CallExpr).getVariant().getName().getText(),
] and
HeuristicNames::nameIndicatesSensitiveData(name, classification)
)
}

override SensitiveDataClassification getClassification() { result = classification }
}

/**
* A variable that might contain sensitive data.
* A variable access data flow node that might be sensitive data.
*/
private class SensitiveDataVariable extends Variable {
private class SensitiveVariableAccess extends SensitiveData {
SensitiveDataClassification classification;

SensitiveDataVariable() {
HeuristicNames::nameIndicatesSensitiveData(this.getText(), classification)
SensitiveVariableAccess() {
HeuristicNames::nameIndicatesSensitiveData(this.asExpr()
.getExpr()
.(VariableAccess)
.getVariable()
.(Variable)
.getText(), classification)
}

SensitiveDataClassification getClassification() { result = classification }
override SensitiveDataClassification getClassification() { result = classification }
}

private Expr fieldExprParentField(FieldExpr fe) { result = fe.getParentNode() }

/**
* A variable access data flow node that might produce sensitive data.
* A field access data flow node that might be sensitive data.
*/
private class SensitiveVariableAccess extends SensitiveData {
private class SensitiveFieldAccess extends SensitiveData {
SensitiveDataClassification classification;

SensitiveVariableAccess() {
classification =
this.asExpr()
.getAstNode()
.(VariableAccess)
.getVariable()
.(SensitiveDataVariable)
.getClassification()
SensitiveFieldAccess() {
exists(FieldExpr fe | fieldExprParentField*(fe) = this.asExpr().getExpr() |
HeuristicNames::nameIndicatesSensitiveData(fe.getIdentifier().getText(), classification)
)
}

override SensitiveDataClassification getClassification() { result = classification }
Loading
Oops, something went wrong.