Skip to content

Commit a893911

Browse files
committed
Ruby: Use a newtype instead of DataFlow::FlowState for insecure-download
1 parent 75fdde5 commit a893911

File tree

2 files changed

+47
-15
lines changed

2 files changed

+47
-15
lines changed

ruby/ql/lib/codeql/ruby/security/InsecureDownloadCustomizations.qll

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ module InsecureDownload {
2121
abstract class Source extends DataFlow::Node {
2222
/**
2323
* Gets a flow-label for this source.
24+
* DEPRECATED: Use `getAFlowLabel()`
2425
*/
25-
abstract DataFlow::FlowState getALabel();
26+
abstract deprecated DataFlow::FlowState getALabel();
27+
28+
abstract Label::State getAFlowLabel();
2629
}
2730

2831
/**
@@ -36,8 +39,11 @@ module InsecureDownload {
3639

3740
/**
3841
* Gets a flow-label where this sink is vulnerable.
42+
* DEPRECATED: Use `getAFlowLabel()`
3943
*/
40-
abstract DataFlow::FlowState getALabel();
44+
abstract deprecated DataFlow::FlowState getALabel();
45+
46+
abstract Label::State getAFlowLabel();
4147
}
4248

4349
/**
@@ -51,24 +57,35 @@ module InsecureDownload {
5157
module Label {
5258
/**
5359
* A flow-label for a URL that is downloaded over an insecure connection.
60+
* DEPRECATED: Use `InsecureState()`
5461
*/
55-
class Insecure extends DataFlow::FlowState {
62+
deprecated class Insecure extends DataFlow::FlowState {
5663
Insecure() { this = "insecure" }
5764
}
5865

5966
/**
6067
* A flow-label for a URL that is sensitive.
68+
* DEPRECATED: Use `SensitiveState()`
6169
*/
62-
class Sensitive extends DataFlow::FlowState {
70+
deprecated class Sensitive extends DataFlow::FlowState {
6371
Sensitive() { this = "sensitive" }
6472
}
6573

6674
/**
6775
* A flow-label for file URLs that are both sensitive and downloaded over an insecure connection.
76+
* DEPRECATED: Use `SensitiveInsecureState()`
6877
*/
69-
class SensitiveInsecure extends DataFlow::FlowState {
78+
deprecated class SensitiveInsecure extends DataFlow::FlowState {
7079
SensitiveInsecure() { this = "sensitiveInsecure" }
7180
}
81+
82+
/**
83+
* Flow-labels for reasoning about download of sensitive file through insecure connection.
84+
*/
85+
newtype State =
86+
InsecureState() or
87+
SensitiveState() or
88+
SensitiveInsecureState()
7289
}
7390

7491
/**
@@ -88,12 +105,19 @@ module InsecureDownload {
88105
* seen as a source for downloads of sensitive files through an insecure connection.
89106
*/
90107
class InsecureFileUrl extends Source, InsecureUrl {
91-
override DataFlow::FlowState getALabel() {
108+
deprecated override DataFlow::FlowState getALabel() {
92109
result instanceof Label::Insecure
93110
or
94111
hasUnsafeExtension(str) and
95112
result instanceof Label::SensitiveInsecure
96113
}
114+
115+
override Label::State getAFlowLabel() {
116+
result = Label::InsecureState()
117+
or
118+
hasUnsafeExtension(str) and
119+
result = Label::SensitiveInsecureState()
120+
}
97121
}
98122

99123
/**
@@ -103,7 +127,9 @@ module InsecureDownload {
103127
class SensitiveFileName extends Source {
104128
SensitiveFileName() { hasUnsafeExtension(this.asExpr().getConstantValue().getString()) }
105129

106-
override DataFlow::FlowState getALabel() { result instanceof Label::Sensitive }
130+
deprecated override DataFlow::FlowState getALabel() { result instanceof Label::Sensitive }
131+
132+
override Label::State getAFlowLabel() { result = Label::SensitiveState() }
107133
}
108134

109135
/**
@@ -145,11 +171,17 @@ module InsecureDownload {
145171

146172
override DataFlow::Node getDownloadCall() { result = req }
147173

148-
override DataFlow::FlowState getALabel() {
174+
deprecated override DataFlow::FlowState getALabel() {
149175
result instanceof Label::SensitiveInsecure
150176
or
151177
any(req.getAUrlPart()) instanceof InsecureUrl and result instanceof Label::Sensitive
152178
}
179+
180+
override Label::State getAFlowLabel() {
181+
result = Label::SensitiveInsecureState()
182+
or
183+
any(req.getAUrlPart()) instanceof InsecureUrl and result = Label::SensitiveState()
184+
}
153185
}
154186

155187
/**
@@ -191,7 +223,9 @@ module InsecureDownload {
191223
)
192224
}
193225

194-
override DataFlow::FlowState getALabel() { result instanceof Label::Insecure }
226+
deprecated override DataFlow::FlowState getALabel() { result instanceof Label::Insecure }
227+
228+
override Label::State getAFlowLabel() { result = Label::InsecureState() }
195229

196230
override DataFlow::Node getDownloadCall() { result = request }
197231
}

ruby/ql/lib/codeql/ruby/security/InsecureDownloadQuery.qll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,13 @@ deprecated class Configuration extends DataFlow::Configuration {
3333
}
3434

3535
private module InsecureDownloadConfig implements DataFlow::StateConfigSig {
36-
class FlowState = string;
36+
class FlowState = Label::State;
3737

38-
predicate isSource(DataFlow::Node source, DataFlow::FlowState label) {
39-
source.(Source).getALabel() = label
38+
predicate isSource(DataFlow::Node source, FlowState label) {
39+
source.(Source).getAFlowLabel() = label
4040
}
4141

42-
predicate isSink(DataFlow::Node sink, DataFlow::FlowState label) {
43-
sink.(Sink).getALabel() = label
44-
}
42+
predicate isSink(DataFlow::Node sink, FlowState label) { sink.(Sink).getAFlowLabel() = label }
4543

4644
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
4745
}

0 commit comments

Comments
 (0)