Skip to content

Commit 8e5557e

Browse files
committed
Python: Avoid duplicated route-setup in django
When using `django.conf.urls.url` with Django 2+
1 parent d7ca065 commit 8e5557e

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,22 @@ 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, we mark ANY parameter as being a
1885+
// routed-parameter, which can lead to FPs.
1886+
not exists(Module mod |
1887+
mod.getName() = "django.conf.urls.__init__" and
1888+
node.getEnclosingModule() = mod
1889+
)
1890+
}
18761891

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

0 commit comments

Comments
 (0)