Skip to content

Commit beed435

Browse files
authored
Merge pull request #323 from microsoft/domain-squatting-powershell
Domain squatting powershell
2 parents cf72f5c + e90b4be commit beed435

5 files changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
5+
<qhelp>
6+
7+
<overview>
8+
<p> Do not use domains like <code>*.outlook.us</code> and <code>*.office.us</code>, as these are domains that are not owned by Microsoft. Also avoid using deprecated domains like <code>goo.gl</code>.
9+
These domains are subject to domain squatting, which can introduce a security risk to services that trust them. </p>
10+
11+
<p>In addition to the above, <code>ajax.microsoft.com</code> and <code>ajax.aspnetcdn.com</code> host old JavaScript or old CSS in a non-production CDN. This CDN has no SLA, and could disappear at any time. We recommend that you move your assets local or serve them from a fully supported production CDN, such as the <a href="https://eng.ms/docs/experiences-devices/global-experiences-platform/es365/idc-fundamentals-1js/1js-monorepo/1js-repo-docs/team-documentation/midgard/engineering-system/cdn">M365 Shared CDN (1CDN)</a>.</p>
12+
</overview>
13+
14+
<recommendation>
15+
<p>Please remove any references to any obsolete domains</p>
16+
</recommendation>
17+
18+
<references>
19+
<li>Google: <a href="https://developers.googleblog.com/en/google-url-shortener-links-will-no-longer-be-available/">Google URL Shortener links will no longer be available</a>.</li>
20+
<li>AJAX CDN: <a href="https://learn.microsoft.com/en-us/aspnet/ajax/cdn/overview">AJAX CDN Overview</a></li>
21+
</references>
22+
</qhelp>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @name Use of deprecated domain
3+
* @description Referencing deprecated domains that are not owned by Microsoft can lead to security risks
4+
* @kind problem
5+
* @id powershell/domain-squatting-static
6+
* @problem.severity error
7+
* @precision high
8+
* @tags security
9+
*/
10+
11+
import powershell
12+
13+
string obsoleteDomain(){
14+
result = [
15+
"%.outlook.us%",
16+
"%.office.us%",
17+
"%goo.gl%",
18+
"%ajax.aspnetcdn.com%",
19+
"%ajax.microsoft.com%"
20+
]
21+
}
22+
23+
from StringLiteral s, string domain
24+
where
25+
domain = obsoleteDomain() and
26+
s.getValue().matches(domain)
27+
select s, "use of obsolete domain " + domain
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| test.ps1:2:15:2:46 | https://mail.outlook.us/api/v1 | use of obsolete domain %.outlook.us% |
2+
| test.ps1:5:14:5:45 | https://portal.office.us/admin | use of obsolete domain %.office.us% |
3+
| test.ps1:8:13:8:35 | https://goo.gl/abc123 | use of obsolete domain %goo.gl% |
4+
| test.ps1:11:11:11:70 | https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.5.1.min.js | use of obsolete domain %ajax.aspnetcdn.com% |
5+
| test.ps1:14:14:14:68 | http://ajax.microsoft.com/ajax/4.0/1/MicrosoftAjax.js | use of obsolete domain %ajax.microsoft.com% |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queries/security/cwe-829/DomainSquattingStatic.ql
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# BAD: Uses outlook.us domain
2+
$outlookUrl = "https://mail.outlook.us/api/v1"
3+
4+
# BAD: Uses office.us domain
5+
$officeUrl = "https://portal.office.us/admin"
6+
7+
# BAD: Uses deprecated goo.gl shortener
8+
$shortUrl = "https://goo.gl/abc123"
9+
10+
# BAD: Uses deprecated ajax.aspnetcdn.com
11+
$cdnUrl = "https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.5.1.min.js"
12+
13+
# BAD: Uses deprecated ajax.microsoft.com
14+
$msAjaxUrl = "http://ajax.microsoft.com/ajax/4.0/1/MicrosoftAjax.js"
15+
16+
# GOOD: Uses valid Microsoft domains
17+
$validUrl1 = "https://outlook.office365.com/api/v1"
18+
$validUrl2 = "https://portal.azure.com"

0 commit comments

Comments
 (0)