Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6cc0be

Browse files
committed
Python points-to. Move extension to prevent points-to being recomputed.
1 parent f311c20 commit f6cc0be

4 files changed

Lines changed: 42 additions & 36 deletions

File tree

python/ql/src/semmle/python/types/Extensions.qll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ private import semmle.python.pointsto.PointsTo
1414
private import semmle.python.pointsto.PointsToContext
1515
private import semmle.python.objects.TObject
1616
private import semmle.python.objects.ObjectInternal
17+
private import semmle.python.web.HttpConstants
1718

1819
abstract class PointsToExtension extends @py_flow_node {
1920

@@ -96,6 +97,33 @@ class RangeIterationVariableFact extends PointsToExtension {
9697

9798
}
9899

100+
/* bottle module route constants */
101+
102+
class BottleRoutePointToExtension extends PointsToExtension {
103+
104+
string name;
105+
106+
BottleRoutePointToExtension() {
107+
exists(DefinitionNode defn |
108+
defn.getScope().(Module).getName() = "bottle" and
109+
this = defn.getValue() and
110+
name = defn.(NameNode).getId()
111+
|
112+
name = "route" or
113+
name = httpVerbLower()
114+
)
115+
}
116+
117+
override predicate pointsTo(Context context, ObjectInternal value, ControlFlowNode origin) {
118+
context.isImport() and
119+
exists(CfgOrigin orig |
120+
Module::named("bottle").attr("Bottle").(ClassObjectInternal).attribute(name, value, orig) and
121+
origin = orig.asCfgNodeOrHere(this)
122+
)
123+
}
124+
125+
}
126+
99127
/* Python 3.6+ regex module constants */
100128

101129
class ReModulePointToExtension extends PointsToExtension {

python/ql/src/semmle/python/web/Http.qll

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
import python
22
import semmle.python.security.TaintTracking
33
import semmle.python.security.strings.External
4+
import HttpConstants
45

56
/** Generic taint source from a http request */
67
abstract class HttpRequestTaintSource extends TaintSource {
78

89
}
910

10-
/** Gets an http verb */
11-
string httpVerb() {
12-
result = "GET" or result = "POST" or
13-
result = "PUT" or result = "PATCH" or
14-
result = "DELETE" or result = "OPTIONS" or
15-
result = "HEAD"
16-
}
17-
18-
/** Gets an http verb, in lower case */
19-
string httpVerbLower() {
20-
result = httpVerb().toLowerCase()
21-
}
22-
2311
/** Taint kind representing the WSGI environment.
2412
* As specified in PEP 3333. https://www.python.org/dev/peps/pep-3333/#environ-variables
2513
*/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
/** Gets an http verb */
3+
string httpVerb() {
4+
result = "GET" or result = "POST" or
5+
result = "PUT" or result = "PATCH" or
6+
result = "DELETE" or result = "OPTIONS" or
7+
result = "HEAD"
8+
}
9+
10+
/** Gets an http verb, in lower case */
11+
string httpVerbLower() {
12+
result = httpVerb().toLowerCase()
13+
}

python/ql/src/semmle/python/web/bottle/General.qll

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,3 @@ class BottleRoute extends ControlFlowNode {
5454
}
5555

5656

57-
/* bottle module route constants */
58-
59-
class BottleRoutePointToExtension extends CustomPointsToFact {
60-
61-
string name;
62-
63-
BottleRoutePointToExtension() {
64-
exists(DefinitionNode defn |
65-
defn.getScope().(Module).getName() = "bottle" and
66-
this = defn.getValue() and
67-
name = defn.(NameNode).getId()
68-
|
69-
name = "route" or
70-
name = httpVerbLower()
71-
)
72-
}
73-
74-
override predicate pointsTo(Context context, Object value, ClassObject cls, ControlFlowNode origin) {
75-
context.isImport() and
76-
ModuleObject::named("bottle").attr("Bottle").(ClassObject).attributeRefersTo(name, value, cls, origin)
77-
}
78-
}
79-

0 commit comments

Comments
 (0)