Skip to content

Commit 7c85448

Browse files
authored
Merge pull request github#12080 from alexrford/js-use-shared-cryptography
JS: Use shared `CryptographicOperation` concept
2 parents 0e3f4f6 + 9cfd0f5 commit 7c85448

File tree

16 files changed

+368
-151
lines changed

16 files changed

+368
-151
lines changed

javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/EndpointCharacteristics.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ private class CryptographicOperationFlowCharacteristic extends NotASinkCharacter
409409
CryptographicOperationFlowCharacteristic() { this = "CryptographicOperationFlow" }
410410

411411
override predicate appliesToEndpoint(DataFlow::Node n) {
412-
any(CryptographicOperation op).getInput() = n
412+
any(CryptographicOperation op).getAnInput() = n
413413
}
414414
}
415415

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
category: breaking
3+
---
4+
* The `CryptographicOperation` concept has been changed to use a range pattern. This is a breaking change and existing implementations of `CryptographicOperation` will need to be updated in order to compile. These implementations can be updated by:
5+
1. Extending `CryptographicOperation::Range` rather than `CryptographicOperation`
6+
2. Renaming the `getInput()` member predicate as `getAnInput()`
7+
3. Implementing the `BlockMode getBlockMode()` member predicate. The implementation for this can be `none()` if the operation is a hashing operation or an encryption operation using a stream cipher.

javascript/ql/lib/semmle/javascript/Concepts.qll

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,40 @@ abstract class PersistentWriteAccess extends DataFlow::Node {
110110
*/
111111
abstract DataFlow::Node getValue();
112112
}
113+
114+
/**
115+
* Provides models for cryptographic things.
116+
*/
117+
module Cryptography {
118+
private import semmle.javascript.internal.ConceptsShared::Cryptography as SC
119+
120+
/**
121+
* A data-flow node that is an application of a cryptographic algorithm. For example,
122+
* encryption, decryption, signature-validation.
123+
*
124+
* Extend this class to refine existing API models. If you want to model new APIs,
125+
* extend `CryptographicOperation::Range` instead.
126+
*/
127+
class CryptographicOperation extends SC::CryptographicOperation instanceof CryptographicOperation::Range {
128+
/**
129+
* DEPRECATED. This predicate has been renamed to `getAnInput`.
130+
*
131+
* To implement `CryptographicOperation`, please extend
132+
* `CryptographicOperation::Range` and implement `getAnInput` instead of
133+
* extending this class directly.
134+
*/
135+
deprecated final DataFlow::Node getInput() { result = this.getAnInput() }
136+
}
137+
138+
class EncryptionAlgorithm = SC::EncryptionAlgorithm;
139+
140+
class HashingAlgorithm = SC::HashingAlgorithm;
141+
142+
class PasswordHashingAlgorithm = SC::PasswordHashingAlgorithm;
143+
144+
module CryptographicOperation = SC::CryptographicOperation;
145+
146+
class BlockMode = SC::BlockMode;
147+
148+
class CryptographicAlgorithm = SC::CryptographicAlgorithm;
149+
}

0 commit comments

Comments
 (0)