forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 20
Domain squatting powershell #323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chanel-y
wants to merge
3
commits into
main
Choose a base branch
from
domain-squatting-powershell
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
powershell/ql/src/queries/security/cwe-829/DomainSquattingStatic.qhelp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <!DOCTYPE qhelp PUBLIC | ||
| "-//Semmle//qhelp//EN" | ||
| "qhelp.dtd"> | ||
|
|
||
| <qhelp> | ||
|
|
||
| <overview> | ||
| <p> Do not use domains like <code>*.outlook.us</code> and <code>*.office.us</code> are domains that are not owned by Microsoft, or deprecated domains such as <code>goo.gl</code>. | ||
| These domains are subject to domain squatting, which can introduce a security risk to services that trust them. </p> | ||
|
|
||
| <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> | ||
| </overview> | ||
|
|
||
| <recommendation> | ||
| <p>Please remove any references to any obsolete domains</p> | ||
| </recommendation> | ||
|
|
||
| <references> | ||
| <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> | ||
| <li>AJAX CDN: <a href="https://learn.microsoft.com/en-us/aspnet/ajax/cdn/overview">AJAX CDN Overview</a></li> | ||
| </references> | ||
| </qhelp> | ||
27 changes: 27 additions & 0 deletions
27
powershell/ql/src/queries/security/cwe-829/DomainSquattingStatic.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /** | ||
| * @name Use of deprecated domain | ||
| * @description Referencing deprecated domains that are not owned by Microsoft can lead to security risks | ||
| * @kind problem | ||
| * @id powershell/domain-squatting-static | ||
| * @problem.severity error | ||
| * @precision high | ||
| * @tags security | ||
| */ | ||
|
|
||
| import powershell | ||
|
|
||
| string obsoleteDomain(){ | ||
| result = [ | ||
| "%.outlook.us%", | ||
| "%.office.us%", | ||
| "%goo.gl%", | ||
| "%ajax.aspnetcdn.com%", | ||
| "%ajax.microsoft.com%" | ||
| ] | ||
| } | ||
|
|
||
| from StringLiteral s, string domain | ||
| where | ||
| domain = obsoleteDomain() and | ||
| s.getValue().matches(domain) | ||
| select s, "use of obsolete domain " + domain |
5 changes: 5 additions & 0 deletions
5
...ql/test/query-tests/security/cwe-829/DomainSquattingStatic/DomainSquattingStatic.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| | test.ps1:2:15:2:46 | https://mail.outlook.us/api/v1 | use of obsolete domain %.outlook.us% | | ||
| | test.ps1:5:14:5:45 | https://portal.office.us/admin | use of obsolete domain %.office.us% | | ||
| | test.ps1:8:13:8:35 | https://goo.gl/abc123 | use of obsolete domain %goo.gl% | | ||
| | 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% | | ||
| | test.ps1:14:14:14:68 | http://ajax.microsoft.com/ajax/4.0/1/MicrosoftAjax.js | use of obsolete domain %ajax.microsoft.com% | |
1 change: 1 addition & 0 deletions
1
...ll/ql/test/query-tests/security/cwe-829/DomainSquattingStatic/DomainSquattingStatic.qlref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| queries/security/cwe-829/DomainSquattingStatic.ql |
18 changes: 18 additions & 0 deletions
18
powershell/ql/test/query-tests/security/cwe-829/DomainSquattingStatic/test.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # BAD: Uses outlook.us domain | ||
| $outlookUrl = "https://mail.outlook.us/api/v1" | ||
|
|
||
| # BAD: Uses office.us domain | ||
| $officeUrl = "https://portal.office.us/admin" | ||
|
|
||
| # BAD: Uses deprecated goo.gl shortener | ||
| $shortUrl = "https://goo.gl/abc123" | ||
|
|
||
| # BAD: Uses deprecated ajax.aspnetcdn.com | ||
| $cdnUrl = "https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.5.1.min.js" | ||
|
|
||
| # BAD: Uses deprecated ajax.microsoft.com | ||
| $msAjaxUrl = "http://ajax.microsoft.com/ajax/4.0/1/MicrosoftAjax.js" | ||
|
|
||
| # GOOD: Uses valid Microsoft domains | ||
| $validUrl1 = "https://outlook.office365.com/api/v1" | ||
| $validUrl2 = "https://portal.azure.com" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.