Skip to content
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

Merged
merged 2 commits into from
Nov 14, 2018

Conversation

valhristov
Copy link
Contributor

Fix #1992

@ghost ghost assigned valhristov Nov 12, 2018
@ghost ghost added the Status: Needs Review label Nov 12, 2018
Copy link

@sonarsource-next sonarsource-next bot left a 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:
Bug Bugs: 1
Vulnerability Vulnerabilities: 0
Code Smell Code Smells: 0

See all issues in SonarQube

Copy link

@sonarsource-next sonarsource-next bot left a 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:
Bug Bugs: 2
Vulnerability Vulnerabilities: 0
Code Smell Code Smells: 0

Including the following issue(s) which could not be reported in line:

  1. Bug Bug: Change this condition so that it does not always evaluate to 'false'; some subsequent code is never executed. (more)

See all issues in SonarQube

@@ -51,7 +51,8 @@ public CSharpMethodDeclarationTracker(IAnalyzerConfiguration analysisConfigurati
}

var methodDeclaration = context.MethodSymbol.DeclaringSyntaxReferences
.Select(r => (MethodDeclarationSyntax)r.GetSyntax())
.Select(r => r.GetSyntax())
.OfType<BaseMethodDeclarationSyntax>()
Copy link
Contributor Author

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)
Copy link
Contributor Author

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);
Copy link
Contributor Author

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)
Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@duncanp-sonar duncanp-sonar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of questions.

Copy link

@sonarsource-next sonarsource-next bot left a 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:
Bug Bugs: 2
Vulnerability Vulnerabilities: 0
Code Smell Code Smells: 0

Including the following issue(s) which could not be reported in line:

  1. Bug Bug: Change this condition so that it does not always evaluate to 'false'; some subsequent code is never executed. (more)

See all issues in SonarQube

Copy link

@sonarsource-next sonarsource-next bot left a 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:
Bug Bugs: 6
Vulnerability Vulnerabilities: 0
Code Smell Code Smells: 0

Including the following issue(s) which could not be reported in line:

  1. Bug Bug: Change this condition so that it does not always evaluate to 'false'; some subsequent code is never executed. (more)

See all issues in SonarQube

@duncanp-sonar duncanp-sonar merged commit 1e38d3b into feature/hotspots Nov 14, 2018
@duncanp-sonar duncanp-sonar deleted the val/permissions branch November 14, 2018 16:34
@ghost ghost removed the Status: Needs Review label Nov 14, 2018
Evangelink pushed a commit that referenced this pull request Nov 19, 2018
* Rule S4834: Controlling permissions is security-sensitive
Evangelink pushed a commit that referenced this pull request Nov 19, 2018
* Rule S4834: Controlling permissions is security-sensitive
Evangelink pushed a commit that referenced this pull request Nov 19, 2018
* Rule S4834: Controlling permissions is security-sensitive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants