-
Notifications
You must be signed in to change notification settings - Fork 227
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
Rule S4834: Controlling permissions is security-sensitive #2096
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6bee7eb
to
b31502c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SonarQube analysis found issues:
Bugs: 2
Vulnerabilities: 0
Code Smells: 0
Including the following issue(s) which could not be reported in line:
- Bug: Change this condition so that it does not always evaluate to 'false'; some subsequent code is never executed. (more)
@@ -51,7 +51,8 @@ public CSharpMethodDeclarationTracker(IAnalyzerConfiguration analysisConfigurati | |||
} | |||
|
|||
var methodDeclaration = context.MethodSymbol.DeclaringSyntaxReferences | |||
.Select(r => (MethodDeclarationSyntax)r.GetSyntax()) | |||
.Select(r => r.GetSyntax()) | |||
.OfType<BaseMethodDeclarationSyntax>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The property getters and setters are also methods, hence we filter only "normal" methods, constructors and destructors here.
@@ -103,7 +103,7 @@ bool IsTrackedRelationship(SyntaxNode contextNode, SemanticModel semanticModel, | |||
{ | |||
foreach(var baseTypeNode in context.AllBaseTypeNodes) | |||
{ | |||
if (context.Model.GetTypeInfo(baseTypeNode).Type?.DerivesFrom(type) ?? false) | |||
if (context.Model.GetTypeInfo(baseTypeNode).Type?.DerivesOrImplements(type) ?? false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to support interfaces here too.
@@ -35,7 +36,7 @@ protected MethodDeclarationTracker(IAnalyzerConfiguration analysisConfiguration, | |||
{ | |||
} | |||
|
|||
protected abstract SyntaxToken GetMethodIdentifier(SyntaxNode methodDeclaration); | |||
protected abstract SyntaxToken? GetMethodIdentifier(SyntaxNode methodDeclaration); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MethodIdentifier is null when the method is not a "normal" method, e.g. a property for example
@@ -165,6 +165,22 @@ public static SimpleNameSyntax GetIdentifier(this ExpressionSyntax expression) | |||
} | |||
} | |||
|
|||
public static SyntaxToken? GetIdentifierOrDefault(this MethodBaseSyntax methodDeclaration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the C# syntax helper
} | ||
} | ||
} | ||
|
||
bool IsTrackedMethod(IMethodSymbol methodSymbol, Compilation compilation) | ||
{ | ||
if (methodSymbol.MethodKind != MethodKind.Ordinary && | ||
methodSymbol.MethodKind != MethodKind.ReducedExtension) // Just methods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not make these conditions? This seems like quite a big constraint to bake into the base tracker class.
Also, the MethodKind enum has values for Constructor, Desctructor, PropertyGet, PropertySet etc. Presumably this check is filtering out all of those types so the changes above to handle those kinds of method symbols aren't required if this check is done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added logic to obtain identifier from all method symbol kinds and extracted the method kind check as a condition.
sonaranalyzer-dotnet/src/SonarAnalyzer.Common/Rules/Hotspots/ControllingPermissionsBase.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of questions.
b31502c
to
cceceed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SonarQube analysis found issues:
Bugs: 2
Vulnerabilities: 0
Code Smells: 0
Including the following issue(s) which could not be reported in line:
- Bug: Change this condition so that it does not always evaluate to 'false'; some subsequent code is never executed. (more)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SonarQube analysis found issues:
Bugs: 6
Vulnerabilities: 0
Code Smells: 0
Including the following issue(s) which could not be reported in line:
- Bug: Change this condition so that it does not always evaluate to 'false'; some subsequent code is never executed. (more)
Fix #1992