Add generic artifact data-flow

The relation between RNG and other artifacts has been added
Nonce has been completed to report its source
This commit is contained in:
Nicolas Will
2025-02-25 02:53:13 +01:00
parent 2b0b927b0b
commit eb91ecf1fb
2 changed files with 79 additions and 12 deletions

View File

@@ -2,6 +2,7 @@ private import codeql.cryptography.Model
private import java as Language
private import semmle.code.java.security.InsecureRandomnessQuery
private import semmle.code.java.security.RandomQuery
private import semmle.code.java.dataflow.DataFlow
private class UnknownLocation extends Language::Location {
UnknownLocation() { this.getFile().getAbsolutePath() = "" }
@@ -36,6 +37,10 @@ module Crypto = CryptographyBase<Language::Location, CryptoInput>;
*/
abstract class RandomnessInstance extends Crypto::RandomNumberGenerationInstance {
override DataFlow::Node asOutputData() { result.asExpr() = this }
override predicate flowsTo(Crypto::ArtifactLocatableElement other) {
RNGToArtifactFlow::flow(this.asOutputData(), other.getInput())
}
}
class SecureRandomnessInstance extends RandomnessInstance {
@@ -50,5 +55,20 @@ class InsecureRandomnessInstance extends RandomnessInstance {
InsecureRandomnessInstance() { exists(InsecureRandomnessSource node | this = node.asExpr()) }
}
/**
* Random number generation artifact to other artifact flow configuration
*/
module RNGToArtifactFlowConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
source = any(Crypto::RandomNumberGenerationInstance rng).asOutputData()
}
predicate isSink(DataFlow::Node sink) {
sink = any(Crypto::ArtifactLocatableElement other).getInput()
}
}
module RNGToArtifactFlow = DataFlow::Global<RNGToArtifactFlowConfig>;
// Import library-specific modeling
import JCA