Skip to content

Commit 50e8034

Browse files
authored
Merge pull request #1544 from esben-semmle/js/additional-configuration-splitting
Approved by xiemaisi
2 parents 39c37f5 + fca815f commit 50e8034

File tree

68 files changed

+2908
-2371
lines changed

Some content is hidden

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

68 files changed

+2908
-2371
lines changed

javascript/ql/src/semmle/javascript/heuristics/AdditionalSinks.qll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
import javascript
88
private import SyntacticHeuristics
99
private import semmle.javascript.security.dataflow.CodeInjectionCustomizations
10-
private import semmle.javascript.security.dataflow.CommandInjection
10+
private import semmle.javascript.security.dataflow.CommandInjectionCustomizations
1111
private import semmle.javascript.security.dataflow.DomBasedXss as DomBasedXss
1212
private import semmle.javascript.security.dataflow.ReflectedXss as ReflectedXss
13-
private import semmle.javascript.security.dataflow.SqlInjection
14-
private import semmle.javascript.security.dataflow.NosqlInjection
15-
private import semmle.javascript.security.dataflow.TaintedPath
16-
private import semmle.javascript.security.dataflow.RegExpInjection
17-
private import semmle.javascript.security.dataflow.ClientSideUrlRedirect
18-
private import semmle.javascript.security.dataflow.ServerSideUrlRedirect
19-
private import semmle.javascript.security.dataflow.InsecureRandomness
13+
private import semmle.javascript.security.dataflow.SqlInjectionCustomizations
14+
private import semmle.javascript.security.dataflow.NosqlInjectionCustomizations
15+
private import semmle.javascript.security.dataflow.TaintedPathCustomizations
16+
private import semmle.javascript.security.dataflow.RegExpInjectionCustomizations
17+
private import semmle.javascript.security.dataflow.ClientSideUrlRedirectCustomizations
18+
private import semmle.javascript.security.dataflow.ServerSideUrlRedirectCustomizations
19+
private import semmle.javascript.security.dataflow.InsecureRandomnessCustomizations
2020

2121
/**
2222
* A heuristic sink for data flow in a security query.

javascript/ql/src/semmle/javascript/heuristics/AdditionalSources.qll

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

77
import javascript
88
import SyntacticHeuristics
9-
private import semmle.javascript.security.dataflow.CommandInjection
9+
private import semmle.javascript.security.dataflow.CommandInjectionCustomizations
1010

1111
/**
1212
* A heuristic source of data flow in a security query.
Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
11
/**
2-
* Provides a taint tracking configuration for reasoning about sensitive information in broken or weak cryptographic algorithms.
2+
* Provides a taint tracking configuration for reasoning about
3+
* sensitive information in broken or weak cryptographic algorithms.
4+
*
5+
* Note, for performance reasons: only import this file if
6+
* `BrokenCryptoAlgorithm::Configuration` is needed, otherwise
7+
* `BrokenCryptoAlgorithmCustomizations` should be imported instead.
38
*/
49

510
import javascript
6-
private import semmle.javascript.security.SensitiveActions
7-
private import semmle.javascript.frameworks.CryptoLibraries
811

912
module BrokenCryptoAlgorithm {
10-
/**
11-
* A data flow source for sensitive information in broken or weak cryptographic algorithms.
12-
*/
13-
abstract class Source extends DataFlow::Node {
14-
/** Gets a string that describes the type of this data flow source. */
15-
abstract string describe();
16-
}
17-
18-
/**
19-
* A data flow sink for sensitive information in broken or weak cryptographic algorithms.
20-
*/
21-
abstract class Sink extends DataFlow::Node { }
22-
23-
/**
24-
* A sanitizer for sensitive information in broken or weak cryptographic algorithms.
25-
*/
26-
abstract class Sanitizer extends DataFlow::Node { }
13+
import BrokenCryptoAlgorithmCustomizations::BrokenCryptoAlgorithm
2714

2815
/**
2916
* A taint tracking configuration for sensitive information in broken or weak cryptographic algorithms.
@@ -46,26 +33,4 @@ module BrokenCryptoAlgorithm {
4633
node instanceof Sanitizer
4734
}
4835
}
49-
50-
/**
51-
* A sensitive expression, viewed as a data flow source for sensitive information
52-
* in broken or weak cryptographic algorithms.
53-
*/
54-
class SensitiveExprSource extends Source, DataFlow::ValueNode {
55-
override SensitiveExpr astNode;
56-
57-
override string describe() { result = astNode.describe() }
58-
}
59-
60-
/**
61-
* An expression used by a broken or weak cryptographic algorithm.
62-
*/
63-
class WeakCryptographicOperationSink extends Sink {
64-
WeakCryptographicOperationSink() {
65-
exists(CryptographicOperation application |
66-
application.getAlgorithm().isWeak() and
67-
this.asExpr() = application.getInput()
68-
)
69-
}
70-
}
7136
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Provides default sources, sinks and sanitisers for reasoning about
3+
* sensitive information in broken or weak cryptographic algorithms,
4+
* as well as extension points for adding your own.
5+
*/
6+
7+
import javascript
8+
private import semmle.javascript.security.SensitiveActions
9+
private import semmle.javascript.frameworks.CryptoLibraries
10+
11+
module BrokenCryptoAlgorithm {
12+
/**
13+
* A data flow source for sensitive information in broken or weak cryptographic algorithms.
14+
*/
15+
abstract class Source extends DataFlow::Node {
16+
/** Gets a string that describes the type of this data flow source. */
17+
abstract string describe();
18+
}
19+
20+
/**
21+
* A data flow sink for sensitive information in broken or weak cryptographic algorithms.
22+
*/
23+
abstract class Sink extends DataFlow::Node { }
24+
25+
/**
26+
* A sanitizer for sensitive information in broken or weak cryptographic algorithms.
27+
*/
28+
abstract class Sanitizer extends DataFlow::Node { }
29+
30+
/**
31+
* A sensitive expression, viewed as a data flow source for sensitive information
32+
* in broken or weak cryptographic algorithms.
33+
*/
34+
class SensitiveExprSource extends Source, DataFlow::ValueNode {
35+
override SensitiveExpr astNode;
36+
37+
override string describe() { result = astNode.describe() }
38+
}
39+
40+
/**
41+
* An expression used by a broken or weak cryptographic algorithm.
42+
*/
43+
class WeakCryptographicOperationSink extends Sink {
44+
WeakCryptographicOperationSink() {
45+
exists(CryptographicOperation application |
46+
application.getAlgorithm().isWeak() and
47+
this.asExpr() = application.getInput()
48+
)
49+
}
50+
}
51+
}
Lines changed: 7 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
11
/**
2-
* Provides a dataflow tracking configuration for reasoning about clear-text logging of sensitive information.
2+
* Provides a dataflow tracking configuration for reasoning about
3+
* clear-text logging of sensitive information.
4+
*
5+
* Note, for performance reasons: only import this file if
6+
* `CleartextLogging::Configuration` is needed, otherwise
7+
* `CleartextLoggingCustomizations` should be imported instead.
38
*/
49

510
import javascript
6-
private import semmle.javascript.dataflow.InferredTypes
7-
private import semmle.javascript.security.SensitiveActions::HeuristicNames
811

912
module CleartextLogging {
10-
/**
11-
* A data flow source for clear-text logging of sensitive information.
12-
*/
13-
abstract class Source extends DataFlow::Node {
14-
/** Gets a string that describes the type of this data flow source. */
15-
abstract string describe();
16-
}
17-
18-
/**
19-
* A data flow sink for clear-text logging of sensitive information.
20-
*/
21-
abstract class Sink extends DataFlow::Node { }
22-
23-
/**
24-
* A barrier for clear-text logging of sensitive information.
25-
*/
26-
abstract class Barrier extends DataFlow::Node { }
13+
import CleartextLoggingCustomizations::CleartextLogging
2714

2815
/**
2916
* A dataflow tracking configuration for clear-text logging of sensitive information.
@@ -57,122 +44,4 @@ module CleartextLogging {
5744
)
5845
}
5946
}
60-
61-
/**
62-
* An argument to a logging mechanism.
63-
*/
64-
class LoggerSink extends Sink {
65-
LoggerSink() { this = any(LoggerCall log).getAMessageComponent() }
66-
}
67-
68-
/**
69-
* A data flow node that does not contain a clear-text password, according to its syntactic name.
70-
*/
71-
private class NameGuidedNonCleartextPassword extends NonCleartextPassword {
72-
NameGuidedNonCleartextPassword() {
73-
exists(string name | name.regexpMatch(notSensitive()) |
74-
this.asExpr().(VarAccess).getName() = name
75-
or
76-
this.(DataFlow::PropRead).getPropertyName() = name
77-
or
78-
this.(DataFlow::InvokeNode).getCalleeName() = name
79-
)
80-
or
81-
// avoid i18n strings
82-
this
83-
.(DataFlow::PropRead)
84-
.getBase()
85-
.asExpr()
86-
.(VarRef)
87-
.getName()
88-
.regexpMatch("(?is).*(messages|strings).*")
89-
}
90-
}
91-
92-
/**
93-
* A data flow node that is definitely not an object.
94-
*/
95-
private class NonObject extends NonCleartextPassword {
96-
NonObject() {
97-
forall(AbstractValue v | v = analyze().getAValue() | not v.getType() = TTObject())
98-
}
99-
}
100-
101-
/**
102-
* A data flow node that receives flow that is not a clear-text password.
103-
*/
104-
private class NonCleartextPasswordFlow extends NonCleartextPassword {
105-
NonCleartextPasswordFlow() {
106-
any(NonCleartextPassword other).(DataFlow::SourceNode).flowsTo(this)
107-
}
108-
}
109-
110-
/**
111-
* A call that might obfuscate a password, for example through hashing.
112-
*/
113-
private class ObfuscatorCall extends Barrier, DataFlow::InvokeNode {
114-
ObfuscatorCall() { getCalleeName().regexpMatch(notSensitive()) }
115-
}
116-
117-
/**
118-
* A data flow node that does not contain a clear-text password.
119-
*/
120-
abstract private class NonCleartextPassword extends DataFlow::Node { }
121-
122-
/**
123-
* An object with a property that may contain password information
124-
*
125-
* This is a source since `console.log(obj)` will show the properties of `obj`.
126-
*/
127-
private class ObjectPasswordPropertySource extends DataFlow::ValueNode, Source {
128-
string name;
129-
130-
ObjectPasswordPropertySource() {
131-
exists(DataFlow::PropWrite write |
132-
name.regexpMatch(maybePassword()) and
133-
not name.regexpMatch(notSensitive()) and
134-
write = this.(DataFlow::SourceNode).getAPropertyWrite(name) and
135-
// avoid safe values assigned to presumably unsafe names
136-
not write.getRhs() instanceof NonCleartextPassword
137-
)
138-
}
139-
140-
override string describe() { result = "an access to " + name }
141-
}
142-
143-
/** An access to a variable or property that might contain a password. */
144-
private class ReadPasswordSource extends DataFlow::ValueNode, Source {
145-
string name;
146-
147-
ReadPasswordSource() {
148-
// avoid safe values assigned to presumably unsafe names
149-
not this instanceof NonCleartextPassword and
150-
name.regexpMatch(maybePassword()) and
151-
(
152-
this.asExpr().(VarAccess).getName() = name
153-
or
154-
exists(DataFlow::SourceNode base |
155-
this = base.getAPropertyRead(name) and
156-
// avoid safe values assigned to presumably unsafe names
157-
exists(DataFlow::SourceNode baseObj | baseObj.flowsTo(base) |
158-
not base.getAPropertyWrite(name).getRhs() instanceof NonCleartextPassword
159-
)
160-
)
161-
)
162-
}
163-
164-
override string describe() { result = "an access to " + name }
165-
}
166-
167-
/** A call that might return a password. */
168-
private class CallPasswordSource extends DataFlow::ValueNode, DataFlow::InvokeNode, Source {
169-
string name;
170-
171-
CallPasswordSource() {
172-
name = getCalleeName() and
173-
name.regexpMatch("(?is)getPassword")
174-
}
175-
176-
override string describe() { result = "a call to " + name }
177-
}
17847
}

0 commit comments

Comments
 (0)