Skip to content

Commit ebc3d32

Browse files
committed
Python: Add concept for HTTP server modeling
If we want to separate out into a file, we can always do this with ``` import experimental.semmle.python.HTTP as HTTP ```
1 parent 9f1aa8c commit ebc3d32

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

python/ql/src/experimental/semmle/python/Concepts.qll

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,56 @@ module SystemCommandExecution {
3838
abstract DataFlow::Node getCommand();
3939
}
4040
}
41+
42+
/** Provides classes for modeling HTTP-related APIs. */
43+
module HTTP {
44+
/** Provides classes for modeling HTTP servers. */
45+
module Server {
46+
/**
47+
* An data-flow node that sets up a route on a server.
48+
*
49+
* Extend this class to model new APIs. If you want to model new APIs,
50+
* extend `RouteSetup::Range` instead.
51+
*/
52+
class RouteSetup extends DataFlow::Node {
53+
RouteSetup::Range range;
54+
55+
RouteSetup() { this = range }
56+
57+
/** Gets the URL pattern for this route, if it can be statically determined. */
58+
string getUrlPattern() { result = range.getUrlPattern() }
59+
60+
/** Gets a function that will handle incoming requests for this route, if any. */
61+
Function getARouteHandler() { result = range.getARouteHandler() }
62+
63+
/**
64+
* Gets a parameter that will receive parts of the url when handling incoming
65+
* requests for this route, if any. These automatically become a `RemoteFlowSource`.
66+
*/
67+
Parameter getARoutedParameter() { result = range.getARoutedParameter() }
68+
}
69+
70+
/** Provides a class for modeling new HTTP routing APIs. */
71+
module RouteSetup {
72+
/**
73+
* An data-flow node that sets up a route on a server.
74+
*
75+
* Extend this class to model new APIs. If you want to refine existing API models,
76+
* extend `RouteSetup` instead.
77+
*/
78+
abstract class Range extends DataFlow::Node {
79+
/** Gets the URL pattern for this route, if it can be statically determined. */
80+
abstract string getUrlPattern();
81+
82+
/** Gets a function that will handle incoming requests for this route, if any. */
83+
abstract Function getARouteHandler();
84+
85+
/**
86+
* Gets a parameter that will receive parts of the url when handling incoming
87+
* requests for this route, if any. These automatically become a `RemoteFlowSource`.
88+
*/
89+
abstract Parameter getARoutedParameter();
90+
}
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)