Skip to content

Commit acc66c7

Browse files
authored
Merge pull request #19984 from jketema/jketema/sec-shared
Make a proper shared library out of the concept related libraries
2 parents 53e1939 + 1990438 commit acc66c7

File tree

66 files changed

+530
-2388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+530
-2388
lines changed

config/identical-files.json

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -231,35 +231,10 @@
231231
"java/ql/src/experimental/Security/CWE/CWE-400/LocalThreadResourceAbuse.qhelp",
232232
"java/ql/src/experimental/Security/CWE/CWE-400/ThreadResourceAbuse.qhelp"
233233
],
234-
"CryptoAlgorithms Python/JS/Ruby": [
235-
"javascript/ql/lib/semmle/javascript/security/CryptoAlgorithms.qll",
236-
"python/ql/lib/semmle/python/concepts/CryptoAlgorithms.qll",
237-
"ruby/ql/lib/codeql/ruby/security/CryptoAlgorithms.qll",
238-
"rust/ql/lib/codeql/rust/security/CryptoAlgorithms.qll"
239-
],
240-
"CryptoAlgorithmNames Python/JS/Ruby": [
241-
"javascript/ql/lib/semmle/javascript/security/internal/CryptoAlgorithmNames.qll",
242-
"python/ql/lib/semmle/python/concepts/internal/CryptoAlgorithmNames.qll",
243-
"ruby/ql/lib/codeql/ruby/security/internal/CryptoAlgorithmNames.qll",
244-
"rust/ql/lib/codeql/rust/security/internal/CryptoAlgorithmNames.qll"
245-
],
246-
"SensitiveDataHeuristics Python/JS": [
247-
"javascript/ql/lib/semmle/javascript/security/internal/SensitiveDataHeuristics.qll",
248-
"python/ql/lib/semmle/python/security/internal/SensitiveDataHeuristics.qll",
249-
"ruby/ql/lib/codeql/ruby/security/internal/SensitiveDataHeuristics.qll",
250-
"swift/ql/lib/codeql/swift/security/internal/SensitiveDataHeuristics.qll",
251-
"rust/ql/lib/codeql/rust/security/internal/SensitiveDataHeuristics.qll"
252-
],
253234
"IncompleteUrlSubstringSanitization": [
254235
"javascript/ql/src/Security/CWE-020/IncompleteUrlSubstringSanitization.qll",
255236
"ruby/ql/src/queries/security/cwe-020/IncompleteUrlSubstringSanitization.qll"
256237
],
257-
"Concepts Python/Ruby/JS": [
258-
"python/ql/lib/semmle/python/internal/ConceptsShared.qll",
259-
"ruby/ql/lib/codeql/ruby/internal/ConceptsShared.qll",
260-
"javascript/ql/lib/semmle/javascript/internal/ConceptsShared.qll",
261-
"rust/ql/lib/codeql/rust/internal/ConceptsShared.qll"
262-
],
263238
"ApiGraphModels": [
264239
"javascript/ql/lib/semmle/javascript/frameworks/data/internal/ApiGraphModels.qll",
265240
"ruby/ql/lib/codeql/ruby/frameworks/data/internal/ApiGraphModels.qll",

javascript/ql/lib/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extractor: javascript
66
library: true
77
upgrades: upgrades
88
dependencies:
9+
codeql/concepts: ${workspace}
910
codeql/dataflow: ${workspace}
1011
codeql/mad: ${workspace}
1112
codeql/regex: ${workspace}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
*/
66

77
import javascript
8+
private import semmle.javascript.dataflow.internal.sharedlib.DataFlowArg
89
private import codeql.threatmodels.ThreatModels
10+
private import codeql.concepts.ConceptsShared
11+
12+
private module ConceptsShared = ConceptsMake<Location, JSDataFlow>;
913

1014
/**
1115
* A data flow source, for a specific threat-model.
@@ -206,7 +210,7 @@ abstract class PersistentWriteAccess extends DataFlow::Node {
206210
* Provides models for cryptographic things.
207211
*/
208212
module Cryptography {
209-
private import semmle.javascript.internal.ConceptsShared::Cryptography as SC
213+
private import ConceptsShared::Cryptography as SC
210214

211215
/**
212216
* A data-flow node that is an application of a cryptographic algorithm. For example,

javascript/ql/lib/semmle/javascript/frameworks/CryptoLibraries.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import javascript
66
import semmle.javascript.Concepts::Cryptography
7-
private import semmle.javascript.security.internal.CryptoAlgorithmNames
7+
private import codeql.concepts.internal.CryptoAlgorithmNames
88

99
/**
1010
* A key used in a cryptographic algorithm.

javascript/ql/lib/semmle/javascript/internal/ConceptsImports.qll

Lines changed: 0 additions & 7 deletions
This file was deleted.

javascript/ql/lib/semmle/javascript/internal/ConceptsShared.qll

Lines changed: 0 additions & 181 deletions
This file was deleted.
Lines changed: 1 addition & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,5 @@
11
/**
22
* Provides classes modeling cryptographic algorithms, separated into strong and weak variants.
3-
*
4-
* The classification into strong and weak are based on Wikipedia, OWASP and Google (2021).
53
*/
64

7-
private import internal.CryptoAlgorithmNames
8-
9-
/**
10-
* A cryptographic algorithm.
11-
*/
12-
private newtype TCryptographicAlgorithm =
13-
MkHashingAlgorithm(string name, boolean isWeak) {
14-
isStrongHashingAlgorithm(name) and isWeak = false
15-
or
16-
isWeakHashingAlgorithm(name) and isWeak = true
17-
} or
18-
MkEncryptionAlgorithm(string name, boolean isWeak) {
19-
isStrongEncryptionAlgorithm(name) and isWeak = false
20-
or
21-
isWeakEncryptionAlgorithm(name) and isWeak = true
22-
} or
23-
MkPasswordHashingAlgorithm(string name, boolean isWeak) {
24-
isStrongPasswordHashingAlgorithm(name) and isWeak = false
25-
or
26-
isWeakPasswordHashingAlgorithm(name) and isWeak = true
27-
}
28-
29-
/**
30-
* Gets the most specific `CryptographicAlgorithm` that matches the given `name`.
31-
* A matching algorithm is one where the name of the algorithm matches the start of name, with allowances made for different name formats.
32-
* In the case that multiple `CryptographicAlgorithm`s match the given `name`, the algorithm(s) with the longest name will be selected. This is intended to select more specific versions of algorithms when multiple versions could match - for example "SHA3_224" matches against both "SHA3" and "SHA3224", but the latter is a more precise match.
33-
*/
34-
bindingset[name]
35-
private CryptographicAlgorithm getBestAlgorithmForName(string name) {
36-
result =
37-
max(CryptographicAlgorithm algorithm |
38-
algorithm.getName() =
39-
[
40-
name.toUpperCase(), // the full name
41-
name.toUpperCase().regexpCapture("^([\\w]+)(?:-.*)?$", 1), // the name prior to any dashes or spaces
42-
name.toUpperCase().regexpCapture("^([A-Z0-9]+)(?:(-|_).*)?$", 1) // the name prior to any dashes, spaces, or underscores
43-
].regexpReplaceAll("[-_ ]", "") // strip dashes, underscores, and spaces
44-
|
45-
algorithm order by algorithm.getName().length()
46-
)
47-
}
48-
49-
/**
50-
* A cryptographic algorithm.
51-
*/
52-
abstract class CryptographicAlgorithm extends TCryptographicAlgorithm {
53-
/** Gets a textual representation of this element. */
54-
string toString() { result = this.getName() }
55-
56-
/**
57-
* Gets the normalized name of this algorithm (upper-case, no spaces, dashes or underscores).
58-
*/
59-
abstract string getName();
60-
61-
/**
62-
* Holds if the name of this algorithm is the most specific match for `name`.
63-
* This predicate matches quite liberally to account for different ways of formatting algorithm names, e.g. using dashes, underscores, or spaces as separators, including or not including block modes of operation, etc.
64-
*/
65-
bindingset[name]
66-
predicate matchesName(string name) { this = getBestAlgorithmForName(name) }
67-
68-
/**
69-
* Holds if this algorithm is weak.
70-
*/
71-
abstract predicate isWeak();
72-
}
73-
74-
/**
75-
* A hashing algorithm such as `MD5` or `SHA512`.
76-
*/
77-
class HashingAlgorithm extends MkHashingAlgorithm, CryptographicAlgorithm {
78-
string name;
79-
boolean isWeak;
80-
81-
HashingAlgorithm() { this = MkHashingAlgorithm(name, isWeak) }
82-
83-
override string getName() { result = name }
84-
85-
override predicate isWeak() { isWeak = true }
86-
}
87-
88-
/**
89-
* An encryption algorithm such as `DES` or `AES512`.
90-
*/
91-
class EncryptionAlgorithm extends MkEncryptionAlgorithm, CryptographicAlgorithm {
92-
string name;
93-
boolean isWeak;
94-
95-
EncryptionAlgorithm() { this = MkEncryptionAlgorithm(name, isWeak) }
96-
97-
override string getName() { result = name }
98-
99-
override predicate isWeak() { isWeak = true }
100-
101-
/** Holds if this algorithm is a stream cipher. */
102-
predicate isStreamCipher() { isStreamCipher(name) }
103-
}
104-
105-
/**
106-
* A password hashing algorithm such as `PBKDF2` or `SCRYPT`.
107-
*/
108-
class PasswordHashingAlgorithm extends MkPasswordHashingAlgorithm, CryptographicAlgorithm {
109-
string name;
110-
boolean isWeak;
111-
112-
PasswordHashingAlgorithm() { this = MkPasswordHashingAlgorithm(name, isWeak) }
113-
114-
override string getName() { result = name }
115-
116-
override predicate isWeak() { isWeak = true }
117-
}
5+
import codeql.concepts.CryptoAlgorithms

javascript/ql/lib/semmle/javascript/security/SensitiveActions.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
import javascript
13-
import semmle.javascript.security.internal.SensitiveDataHeuristics
13+
import codeql.concepts.internal.SensitiveDataHeuristics
1414
private import HeuristicNames
1515

1616
/** An expression that might contain sensitive data. */

0 commit comments

Comments
 (0)