Skip to content

Commit b21b066

Browse files
authored
Merge pull request #499 from xiemaisi/js/target-blank-location
Approved by esben-semmle
2 parents 0493b68 + c1690a6 commit b21b066

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

javascript/ql/src/DOM/TargetBlank.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import javascript
1515
import semmle.javascript.frameworks.Templating
16+
import semmle.javascript.RestrictedLocations
1617

1718
/**
1819
* Holds if the href attribute contains a host that we cannot determine statically.
@@ -53,4 +54,4 @@ where // `e` is a link that opens in a new browsing context (that is, it has `ta
5354
not exists (DOM::AttributeDefinition attr | attr = e.getAnAttribute() |
5455
not exists(attr.getName())
5556
)
56-
select e, "External links without noopener/noreferrer are a potential security risk."
57+
select (FirstLineOf)e, "External links without noopener/noreferrer are a potential security risk."

javascript/ql/test/query-tests/DOM/TargetBlank/TargetBlank.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
| tst.html:23:1:23:61 | <a>...</> | External links without noopener/noreferrer are a potential security risk. |
2+
| tst.html:24:1:24:48 | <a>...</> | External links without noopener/noreferrer are a potential security risk. |
3+
| tst.html:25:1:25:36 | <a>...</> | External links without noopener/noreferrer are a potential security risk. |
14
| tst.js:18:1:18:43 | <a href ... ple</a> | External links without noopener/noreferrer are a potential security risk. |
25
| tst.js:19:1:19:58 | <a href ... ple</a> | External links without noopener/noreferrer are a potential security risk. |
36
| tst.js:20:1:20:51 | <a data ... ple</a> | External links without noopener/noreferrer are a potential security risk. |

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,17 @@ <h1>OK, because of constant URL</h1>
1414
<a href="http://example.com" target="_blank" rel="nopoener">Example</a>
1515
<a data-ng-href="https://example.com" target="_blank">Example</a>
1616

17-
<h1>NOT OK, because of dynamic URL</h1>
17+
<h1>OK, because of constant prefix</h1>
1818
<a href="http://example.com/{{X}}" target="_blank">Example</a>
1919
<a href="http://example.com/{{X}}" target="_blank" rel="nopoener">Example</a>
2020
<a data-ng-href="https://example.com/{{X}}" target="_blank">Example</a>
2121

22+
<h1>NOT OK, because of dynamic URL</h1>
23+
<a href="http://example.com{{X}}" target="_blank">Example</a>
24+
<a href="{{target}}" target="_blank">Example</a>
25+
<a href="{{target}}" target="_blank">
26+
Example
27+
</a>
28+
2229
</body>
2330
</html>

0 commit comments

Comments
 (0)