Skip to content

Commit 17e3a45

Browse files
max-schaefertausbn
authored andcommitted
Apply suggestions from code review
Co-authored-by: Taus <[email protected]>
1 parent 9817845 commit 17e3a45

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

python/ql/lib/semmle/python/frameworks/Django.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,5 +2928,10 @@ module PrivateDjango {
29282928
DjangoAllowedUrl() {
29292929
this = DataFlow::BarrierGuard<djangoUrlHasAllowedHostAndScheme/3>::getABarrierNode()
29302930
}
2931+
2932+
override predicate sanitizes(UrlRedirect::FlowState state) {
2933+
// sanitize all flow states
2934+
any()
2935+
}
29312936
}
29322937
}

python/ql/lib/semmle/python/security/dataflow/UrlRedirectCustomizations.qll

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,8 @@ module UrlRedirect {
5555
abstract class Sanitizer extends DataFlow::Node {
5656
/**
5757
* Holds if this sanitizer sanitizes flow in the given state.
58-
*
59-
* By default, sanitizers sanitize all flow, but some sanitiziers, for example,
60-
* do not handle untrusted input that contains backslashes, so they only sanitize
61-
* flow in the `NoBackslashes` state.
6258
*/
63-
predicate sanitizes(FlowState state) { any() }
59+
abstract predicate sanitizes(FlowState state);
6460
}
6561

6662
/**
@@ -105,16 +101,23 @@ module UrlRedirect {
105101
string_concat.getRight() = this.asCfgNode()
106102
)
107103
}
104+
105+
override predicate sanitizes(FlowState state) {
106+
// sanitize all flow states
107+
any()
108+
}
108109
}
109110

110111
/**
111-
* A call to replace backslashes with forward slashes or eliminates them
112+
* A call that replaces backslashes with forward slashes or eliminates them
112113
* altogether, considered as a partial sanitizer, as well as an additional
113114
* flow step.
114115
*/
115116
class ReplaceBackslashesSanitizer extends Sanitizer, AdditionalFlowStep, DataFlow::MethodCallNode {
117+
DataFlow::Node receiver;
118+
116119
ReplaceBackslashesSanitizer() {
117-
this.getFunction().(DataFlow::AttrRead).getAttributeName() = "replace" and
120+
this.calls(receiver, "replace") and
118121
this.getArg(0).asExpr().(StrConst).getText() = "\\" and
119122
this.getArg(1).asExpr().(StrConst).getText() in ["/", ""]
120123
}
@@ -124,7 +127,7 @@ module UrlRedirect {
124127
override predicate step(
125128
DataFlow::Node nodeFrom, FlowState stateFrom, DataFlow::Node nodeTo, FlowState stateTo
126129
) {
127-
nodeFrom = this.getObject() and
130+
nodeFrom = receiver and
128131
stateFrom instanceof MayContainBackslashes and
129132
nodeTo = this and
130133
stateTo instanceof NoBackslashes
@@ -134,5 +137,10 @@ module UrlRedirect {
134137
/**
135138
* A comparison with a constant string, considered as a sanitizer-guard.
136139
*/
137-
class StringConstCompareAsSanitizerGuard extends Sanitizer, StringConstCompareBarrier { }
140+
class StringConstCompareAsSanitizerGuard extends Sanitizer, StringConstCompareBarrier {
141+
override predicate sanitizes(FlowState state) {
142+
// sanitize all flow states
143+
any()
144+
}
145+
}
138146
}

python/ql/lib/semmle/python/security/dataflow/UrlRedirectQuery.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private module UrlRedirectConfig implements DataFlow::StateConfigSig {
4848

4949
predicate isSink(DataFlow::Node sink, FlowState state) {
5050
sink instanceof UrlRedirect::Sink and
51-
state = state
51+
exists(state)
5252
}
5353

5454
predicate isBarrier(DataFlow::Node node, FlowState state) {

0 commit comments

Comments
 (0)