-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: More metrics for tracking taint. #18501
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
Changes from all commits
4ed4f68
75f0a7f
c6a7be6
7904ed9
72c62ac
5a037bc
65b33f3
787a6d1
98e0b64
bec01da
5f9e1c3
e5faf92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /** | ||
| * @name Cryptographic Operations | ||
| * @description List all cryptographic operations found in the database. | ||
| * @kind problem | ||
| * @problem.severity info | ||
| * @id rust/summary/cryptographic-operations | ||
| * @tags summary | ||
| */ | ||
|
|
||
| import rust | ||
| import codeql.rust.Concepts | ||
| import codeql.rust.security.WeakSensitiveDataHashingExtensions | ||
|
|
||
| /** | ||
| * Gets the type of cryptographic algorithm `alg`. | ||
| */ | ||
| string getAlgorithmType(Cryptography::CryptographicAlgorithm alg) { | ||
| alg instanceof Cryptography::EncryptionAlgorithm and result = "EncryptionAlgorithm" | ||
| or | ||
| alg instanceof Cryptography::HashingAlgorithm and result = "HashingAlgorithm" | ||
| or | ||
| alg instanceof Cryptography::PasswordHashingAlgorithm and result = "PasswordHashingAlgorithm" | ||
| } | ||
|
|
||
| /** | ||
| * Gets a feature of cryptographic algorithm `alg`. | ||
| */ | ||
| string getAlgorithmFeature(Cryptography::CryptographicAlgorithm alg) { | ||
| alg.isWeak() and result = "WEAK" | ||
| } | ||
|
|
||
| /** | ||
| * Gets a description of cryptographic algorithm `alg`. | ||
| */ | ||
| string describeAlgorithm(Cryptography::CryptographicAlgorithm alg) { | ||
| result = | ||
| getAlgorithmType(alg) + " " + alg.getName() + " " + concat(getAlgorithmFeature(alg), ", ") | ||
| } | ||
|
|
||
| /** | ||
| * Gets a feature of cryptographic operation `op`. | ||
| */ | ||
| string getOperationFeature(Cryptography::CryptographicOperation op) { | ||
| result = "inputs:" + strictcount(op.getAnInput()).toString() or | ||
| result = "blockmodes:" + strictcount(op.getBlockMode()).toString() | ||
| } | ||
|
|
||
| /** | ||
| * Gets a description of cryptographic operation `op`. | ||
| */ | ||
| string describeOperation(Cryptography::CryptographicOperation op) { | ||
|
||
| result = describeAlgorithm(op.getAlgorithm()) + " " + concat(getOperationFeature(op), ", ") | ||
| or | ||
| not exists(op.getAlgorithm()) and | ||
| result = "(unknown) " + concat(getOperationFeature(op), ", ") | ||
| } | ||
|
|
||
| from Cryptography::CryptographicOperation operation | ||
| select operation, describeOperation(operation) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /** | ||
| * @name Query Sink Counts | ||
| * @description Lists the number of query sinks of each type found in the database. Query sinks are | ||
| * flow sinks that are used as possible locations for query results. Cryptographic | ||
| * operations are excluded. | ||
| * @kind metric | ||
| * @id rust/summary/query-sink-counts | ||
| * @tags summary | ||
| */ | ||
|
|
||
| import rust | ||
| import codeql.rust.dataflow.DataFlow | ||
| import Stats | ||
|
|
||
| from string kind, int num | ||
| where num = strictcount(DataFlow::Node n | getAQuerySinkKind(n) = kind) | ||
| select kind, num |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /** | ||
| * @name Query Sinks | ||
| * @description Lists query sinks that are found in the database. Query sinks are flow sinks that | ||
| * are used as possible locations for query results. Cryptographic operations are | ||
| * excluded (see `rust/summary/cryptographic-operations` instead). | ||
| * @kind problem | ||
| * @problem.severity info | ||
| * @id rust/summary/query-sinks | ||
| * @tags summary | ||
| */ | ||
|
|
||
| import rust | ||
| import codeql.rust.dataflow.DataFlow | ||
| import Stats | ||
|
|
||
| from DataFlow::Node n | ||
| select n, "Sink for " + strictconcat(getAQuerySinkKind(n), ", ") + "." |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /** | ||
| * Taint reach computation. Taint reach is the proportion of all dataflow nodes that can be reached | ||
| * via taint flow from any active thread model source. It's usually expressed per million nodes. | ||
| */ | ||
|
|
||
| import rust | ||
| private import codeql.rust.Concepts | ||
| private import codeql.rust.dataflow.DataFlow | ||
| private import codeql.rust.dataflow.TaintTracking | ||
|
|
||
| /** | ||
| * A taint configuration for taint reach (flow to any node from any modeled source). | ||
| */ | ||
| private module TaintReachConfig implements DataFlow::ConfigSig { | ||
| predicate isSource(DataFlow::Node node) { node instanceof ActiveThreatModelSource } | ||
|
|
||
| predicate isSink(DataFlow::Node node) { any() } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This certainly looks like something that will not perform very well...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, though:
I'm guessing execution time is roughly linear in the number of nodes reached??? I'd be interested to hear your thoughts, concerns and suggestions - even if this means changing what we measure.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, let's leave it as-is for now then. |
||
| } | ||
|
|
||
| private module TaintReachFlow = TaintTracking::Global<TaintReachConfig>; | ||
|
|
||
| /** | ||
| * Gets the total number of data flow nodes that taint reaches (from any source). | ||
| */ | ||
| int getTaintedNodesCount() { result = count(DataFlow::Node n | TaintReachFlow::flowTo(n)) } | ||
|
|
||
| /** | ||
| * Gets the proportion of data flow nodes that taint reaches (from any source), | ||
| * expressed as a count per million nodes. | ||
| */ | ||
| float getTaintReach() { result = (getTaintedNodesCount() * 1000000.0) / count(DataFlow::Node n) } | ||
Uh oh!
There was an error while loading. Please reload this page.