-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Extend aspnetcore controller definition #9406
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
105462a
Extend aspnetcore controller definition
JarLob f27b5d5
Fix code style warnings
JarLob 56055bd
Add qldoc comments
JarLob 3d281fb
fix suffix match
JarLob 853a80b
filter out Controller suffixed class in non asp.net projects
JarLob c96b938
Controller is public, non-abstract, not generic class
fc10212
Add ApiController support
f05d4b8
failing tests
eed0469
Add tests
JarLob 72429cb
C#: Generic classes should not be considered controllers.
michaelnebel a7011e1
C#: Minor refactoring to avoid introducing name variable.
michaelnebel f2ada3d
C#: Also use using namespace as a hint to indicate that ASP.NET Core …
michaelnebel 85eee88
C#: Auto-format AspNetCore.ql.
michaelnebel 29639a0
C#: ControllerBase should still be considered a controller as we need…
michaelnebel 3779522
C#: Exclude stub implementation in test results.
michaelnebel fa503ec
Create 2022-08-24-aps-net-core-controllers.md
JarLob 57fcfd5
Apply suggestions from code review
JarLob 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
4 changes: 4 additions & 0 deletions
4
csharp/ql/lib/change-notes/2022-08-24-aps-net-core-controllers.md
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,4 @@ | ||
--- | ||
category: minorAnalysis | ||
--- | ||
* ASP.NET Core controller definition has been made more precise. The amount of introduced taint sources or eliminated false positives should be low though, since the most common pattern is to derive all user defined ASP.NET Core controllers from the standard Controller class, which is not affected. |
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
103 changes: 103 additions & 0 deletions
103
csharp/ql/test/library-tests/frameworks/microsoft/AspNetCore.cs
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,103 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
// has sufix "Controller" | ||
public class HomeController | ||
{ | ||
public string Index() | ||
{ | ||
return "This is Home Controller"; | ||
} | ||
} | ||
|
||
// derived from Microsoft.AspNetCore.Mvc.Controller which has suffix "Controller" | ||
public class HomeController1 : Controller | ||
{ | ||
public string Index() | ||
{ | ||
return "This is Home Controller"; | ||
} | ||
} | ||
|
||
// derived from Microsoft.AspNetCore.Mvc.ControllerBase which has attribute [Microsoft.AspNetCore.Mvc.Controller] | ||
public class HomeController2 : ControllerBase | ||
{ | ||
public string Index() | ||
{ | ||
return "This is Home Controller"; | ||
} | ||
} | ||
|
||
// has [ApiController] attribute | ||
[ApiController] | ||
public class HomeController3 | ||
{ | ||
public string Index() | ||
{ | ||
return "This is Home Controller"; | ||
} | ||
} | ||
|
||
// has [Controller] attribute | ||
[Controller] | ||
public class HomeController4 | ||
{ | ||
public string Index() | ||
{ | ||
return "This is Home Controller"; | ||
} | ||
} | ||
|
||
// derived from a class that is a controller | ||
public class HomeController5 : HomeController4 | ||
{ | ||
public string Index() | ||
{ | ||
return "This is Home Controller"; | ||
} | ||
} | ||
|
||
// is not public | ||
internal class NotHomeController : Controller | ||
{ | ||
public string Index() | ||
{ | ||
return "This is Home Controller"; | ||
} | ||
} | ||
|
||
// is abstract | ||
public abstract class NotHomeController2 : Controller | ||
{ | ||
public string Index() | ||
{ | ||
return "This is Home Controller"; | ||
} | ||
} | ||
|
||
// contains generic parameters | ||
public class NotHomeController3<T> : Controller | ||
{ | ||
public string Index() | ||
{ | ||
return "This is Home Controller"; | ||
} | ||
} | ||
|
||
// has [NonController] attribute | ||
[NonController] | ||
public class NotHomeController4 : Controller | ||
{ | ||
public string Index() | ||
{ | ||
return "This is Home Controller"; | ||
} | ||
} | ||
|
||
// derived from a class that has [NonController] attribute | ||
public class NotController : NotHomeController4 | ||
{ | ||
public string Index() | ||
{ | ||
return "This is Home Controller"; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
csharp/ql/test/library-tests/frameworks/microsoft/AspNetCore.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,6 @@ | ||
| AspNetCore.cs:4:14:4:27 | HomeController | | ||
| AspNetCore.cs:13:14:13:28 | HomeController1 | | ||
| AspNetCore.cs:22:14:22:28 | HomeController2 | | ||
| AspNetCore.cs:32:14:32:28 | HomeController3 | | ||
| AspNetCore.cs:42:14:42:28 | HomeController4 | | ||
| AspNetCore.cs:51:14:51:28 | HomeController5 | |
6 changes: 6 additions & 0 deletions
6
csharp/ql/test/library-tests/frameworks/microsoft/AspNetCore.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,6 @@ | ||
import csharp | ||
import semmle.code.csharp.frameworks.microsoft.AspNetCore | ||
|
||
from MicrosoftAspNetCoreMvcController c | ||
where c.fromSource() | ||
select c |
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,2 @@ | ||
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../resources/stubs/_frameworks/Microsoft.AspNetCore.App/Microsoft.AspNetCore.App.csproj | ||
semmle-extractor-options: /nostdlib /noconfig |
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.