mirror of
https://github.com/github/codeql.git
synced 2025-12-20 10:46:30 +01:00
Python: Refactor RouteSetup with default impl for getUrlPattern
Having multiple copies of the StrConst data-flow tracking code means that if we need to update this to be more sophisticated, we could easily forget to do it somewhere :| Until we have a proper `.getAPossibleStringValue` helper, this refactoring should be nice :)
This commit is contained in:
@@ -163,8 +163,16 @@ module HTTP {
|
||||
* extend `RouteSetup` instead.
|
||||
*/
|
||||
abstract class Range extends DataFlow::Node {
|
||||
/** Gets the argument used to set the URL pattern. */
|
||||
abstract DataFlow::Node getUrlPatternArg();
|
||||
|
||||
/** Gets the URL pattern for this route, if it can be statically determined. */
|
||||
abstract string getUrlPattern();
|
||||
string getUrlPattern() {
|
||||
exists(StrConst str |
|
||||
DataFlow::localFlow(DataFlow::exprNode(str), this.getUrlPatternArg()) and
|
||||
result = str.getText()
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets a function that will handle incoming requests for this route, if any. */
|
||||
abstract Function getARouteHandler();
|
||||
|
||||
@@ -170,14 +170,8 @@ private module Django {
|
||||
|
||||
DjangoUrlsPathCall() { node.getFunction() = django::urls::path().asCfgNode() }
|
||||
|
||||
override string getUrlPattern() {
|
||||
exists(StrConst str, ControlFlowNode urlPatternArg |
|
||||
urlPatternArg = [node.getArg(0), node.getArgByName("route")]
|
||||
|
|
||||
DataFlow::localFlow(DataFlow::exprNode(str),
|
||||
any(DataFlow::Node n | n.asCfgNode() = urlPatternArg)) and
|
||||
result = str.getText()
|
||||
)
|
||||
override DataFlow::Node getUrlPatternArg() {
|
||||
result.asCfgNode() = [node.getArg(0), node.getArgByName("route")]
|
||||
}
|
||||
|
||||
override Function getARouteHandler() {
|
||||
@@ -200,14 +194,8 @@ private module Django {
|
||||
|
||||
DjangoUrlsRePathCall() { node.getFunction() = django::urls::re_path().asCfgNode() }
|
||||
|
||||
override string getUrlPattern() {
|
||||
exists(StrConst str, ControlFlowNode urlPatternArg |
|
||||
urlPatternArg = [node.getArg(0), node.getArgByName("route")]
|
||||
|
|
||||
DataFlow::localFlow(DataFlow::exprNode(str),
|
||||
any(DataFlow::Node n | n.asCfgNode() = urlPatternArg)) and
|
||||
result = str.getText()
|
||||
)
|
||||
override DataFlow::Node getUrlPatternArg() {
|
||||
result.asCfgNode() = [node.getArg(0), node.getArgByName("route")]
|
||||
}
|
||||
|
||||
override Function getARouteHandler() {
|
||||
|
||||
@@ -131,16 +131,6 @@ private module Flask {
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets the argument used to pass in the URL pattern. */
|
||||
abstract DataFlow::Node getUrlPatternArg();
|
||||
|
||||
override string getUrlPattern() {
|
||||
exists(StrConst str |
|
||||
DataFlow::localFlow(DataFlow::exprNode(str), this.getUrlPatternArg()) and
|
||||
result = str.getText()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user