Skip to content

Commit d0663e5

Browse files
authored
Merge pull request #4971 from RasmusWL/avoid-double-route-setup-django
Python: Avoid duplicated route-setup in django
2 parents 5fa0dd7 + 9a397b6 commit d0663e5

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,23 @@ private module Django {
18721872
private class DjangoUrlsRePathCall extends DjangoRegexRouteSetup {
18731873
override CallNode node;
18741874

1875-
DjangoUrlsRePathCall() { node.getFunction() = django::urls::re_path().asCfgNode() }
1875+
DjangoUrlsRePathCall() {
1876+
node.getFunction() = django::urls::re_path().asCfgNode() and
1877+
// `django.conf.urls.url` (which we support directly with
1878+
// `DjangoConfUrlsUrlCall`), is implemented in Django 2+ as backward compatibility
1879+
// using `django.urls.re_path`. See
1880+
// https://github.com/django/django/blob/stable/3.2.x/django/conf/urls/__init__.py#L22
1881+
// Since we're still installing dependencies and analyzing their source code,
1882+
// without explicitly filtering out this call, we would be double-counting such
1883+
// route-setups :( One practical negative side effect of double-counting it, is
1884+
// that since we can't figure out the URL in the library code calling `django.urls.re_path`
1885+
// (because we only consider local flow), we will for all those cases mark ANY parameter
1886+
// as being a routed-parameter, which can lead to FPs.
1887+
not exists(Module mod |
1888+
mod.getName() = "django.conf.urls.__init__" and
1889+
node.getEnclosingModule() = mod
1890+
)
1891+
}
18761892

18771893
override DataFlow::Node getUrlPatternArg() {
18781894
result.asCfgNode() = [node.getArg(0), node.getArgByName("route")]

0 commit comments

Comments
 (0)