Skip to content

Commit ebe596f

Browse files
committed
JS: Migrate CorsPermissiveConfiguration
1 parent d83ddfa commit ebe596f

File tree

2 files changed

+56
-16
lines changed

2 files changed

+56
-16
lines changed

javascript/ql/src/experimental/Security/CWE-942/CorsPermissiveConfigurationCustomizations.qll

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,45 @@ import Apollo::Apollo
1010

1111
/** Module containing sources, sinks, and sanitizers for overly permissive CORS configurations. */
1212
module CorsPermissiveConfiguration {
13+
private newtype TFlowState =
14+
TTaint() or
15+
TTrueOrNull() or
16+
TWildcard()
17+
18+
/** A flow state to asociate with a tracked value. */
19+
class FlowState extends TFlowState {
20+
/** Gets a string representation of this flow state. */
21+
string toString() {
22+
this = TTaint() and result = "taint"
23+
or
24+
this = TTrueOrNull() and result = "true-or-null"
25+
or
26+
this = TWildcard() and result = "wildcard"
27+
}
28+
29+
deprecated DataFlow::FlowLabel toFlowLabel() {
30+
this = TTaint() and result.isTaint()
31+
or
32+
this = TTrueOrNull() and result instanceof TrueAndNull
33+
or
34+
this = TWildcard() and result instanceof Wildcard
35+
}
36+
}
37+
38+
/** Predicates for working with flow states. */
39+
module FlowState {
40+
deprecated FlowState fromFlowLabel(DataFlow::FlowLabel label) { result.toFlowLabel() = label }
41+
42+
/** A tainted value. */
43+
FlowState taint() { result = TTaint() }
44+
45+
/** A `true` or `null` value. */
46+
FlowState trueOrNull() { result = TTrueOrNull() }
47+
48+
/** A `"*"` value. */
49+
FlowState wildcard() { result = TWildcard() }
50+
}
51+
1352
/**
1453
* A data flow source for permissive CORS configuration.
1554
*/
@@ -38,18 +77,18 @@ module CorsPermissiveConfiguration {
3877
}
3978

4079
/** A flow label representing `true` and `null` values. */
41-
abstract class TrueAndNull extends DataFlow::FlowLabel {
80+
abstract deprecated class TrueAndNull extends DataFlow::FlowLabel {
4281
TrueAndNull() { this = "TrueAndNull" }
4382
}
4483

45-
TrueAndNull truenullLabel() { any() }
84+
deprecated TrueAndNull truenullLabel() { any() }
4685

4786
/** A flow label representing `*` value. */
48-
abstract class Wildcard extends DataFlow::FlowLabel {
87+
abstract deprecated class Wildcard extends DataFlow::FlowLabel {
4988
Wildcard() { this = "Wildcard" }
5089
}
5190

52-
Wildcard wildcardLabel() { any() }
91+
deprecated Wildcard wildcardLabel() { any() }
5392

5493
/** An overly permissive value for `origin` (Apollo) */
5594
class TrueNullValue extends Source {

javascript/ql/src/experimental/Security/CWE-942/CorsPermissiveConfigurationQuery.qll

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,26 @@
1010

1111
import javascript
1212
import CorsPermissiveConfigurationCustomizations::CorsPermissiveConfiguration
13+
private import CorsPermissiveConfigurationCustomizations::CorsPermissiveConfiguration as CorsPermissiveConfiguration
1314

1415
/**
1516
* A data flow configuration for overly permissive CORS configuration.
1617
*/
1718
module CorsPermissiveConfigurationConfig implements DataFlow::StateConfigSig {
18-
class FlowState = DataFlow::FlowLabel;
19+
class FlowState = CorsPermissiveConfiguration::FlowState;
1920

20-
predicate isSource(DataFlow::Node source, DataFlow::FlowLabel label) {
21-
source instanceof TrueNullValue and label = truenullLabel()
21+
predicate isSource(DataFlow::Node source, FlowState state) {
22+
source instanceof TrueNullValue and state = FlowState::trueOrNull()
2223
or
23-
source instanceof WildcardValue and label = wildcardLabel()
24+
source instanceof WildcardValue and state = FlowState::wildcard()
2425
or
25-
source instanceof RemoteFlowSource and label = DataFlow::FlowLabel::taint()
26+
source instanceof RemoteFlowSource and state = FlowState::taint()
2627
}
2728

28-
predicate isSink(DataFlow::Node sink, DataFlow::FlowLabel label) {
29-
sink instanceof CorsApolloServer and label = [DataFlow::FlowLabel::taint(), truenullLabel()]
29+
predicate isSink(DataFlow::Node sink, FlowState state) {
30+
sink instanceof CorsApolloServer and state = [FlowState::taint(), FlowState::trueOrNull()]
3031
or
31-
sink instanceof ExpressCors and label = [DataFlow::FlowLabel::taint(), wildcardLabel()]
32+
sink instanceof ExpressCors and state = [FlowState::taint(), FlowState::wildcard()]
3233
}
3334

3435
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
@@ -44,11 +45,11 @@ deprecated class Configuration extends TaintTracking::Configuration {
4445
Configuration() { this = "CorsPermissiveConfiguration" }
4546

4647
override predicate isSource(DataFlow::Node source, DataFlow::FlowLabel label) {
47-
CorsPermissiveConfigurationConfig::isSource(source, label)
48+
CorsPermissiveConfigurationConfig::isSource(source, FlowState::fromFlowLabel(label))
4849
}
4950

5051
override predicate isSink(DataFlow::Node sink, DataFlow::FlowLabel label) {
51-
CorsPermissiveConfigurationConfig::isSink(sink, label)
52+
CorsPermissiveConfigurationConfig::isSink(sink, FlowState::fromFlowLabel(label))
5253
}
5354

5455
override predicate isSanitizer(DataFlow::Node node) {
@@ -57,10 +58,10 @@ deprecated class Configuration extends TaintTracking::Configuration {
5758
}
5859
}
5960

60-
private class WildcardActivated extends DataFlow::FlowLabel, Wildcard {
61+
deprecated private class WildcardActivated extends DataFlow::FlowLabel, Wildcard {
6162
WildcardActivated() { this = this }
6263
}
6364

64-
private class TrueAndNullActivated extends DataFlow::FlowLabel, TrueAndNull {
65+
deprecated private class TrueAndNullActivated extends DataFlow::FlowLabel, TrueAndNull {
6566
TrueAndNullActivated() { this = this }
6667
}

0 commit comments

Comments
 (0)