Skip to content

Commit 399872b

Browse files
authored
Merge pull request github#14943 from rafaelurben/patch-1
JS: Add django template urls as "save urls"
2 parents 298c6b5 + 1a05c2e commit 399872b

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

javascript/ql/src/DOM/TargetBlank.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ predicate hasDynamicHrefHostAttributeValue(DOM::ElementDefinition elem) {
4444
// ... that does not start with a fixed host or a relative path (common formats)
4545
not url.regexpMatch("(?i)((https?:)?//)?[-a-z0-9.]*/.*") and
4646
// .. that is not a call to `url_for` in a Flask / nunjucks application
47-
not url.regexpMatch("\\{\\{\\s*url(_for)?\\(.+\\).*")
47+
not url.regexpMatch("\\{\\{\\s*url(_for)?\\(.+\\).*") and
48+
// .. that is not a call to `url` in a Django application
49+
not url.regexpMatch("\\{%\\s*url.*")
4850
)
4951
)
5052
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added django URLs to detected "safe" URL patterns in `js/unsafe-external-link`.

javascript/ql/test/query-tests/DOM/TargetBlank/tst.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,7 @@ function f() {
6565
<a href="{{ url_for('foo.html', 'foo')}}" target="_blank">Example</a>;
6666

6767
// OK, nunjucks template
68-
<a href="{{ url('foo', query={bla}) }}" target="_blank">Example</a>
68+
<a href="{{ url('foo', query={bla}) }}" target="_blank">Example</a>;
69+
70+
// OK, Django application with internal links
71+
<a href="{% url 'admin:auth_user_changelist' %}" target="_blank">Example</a>

0 commit comments

Comments
 (0)