Skip to content

Commit

Permalink
Issue #40. Removed bad loop helper method.
Browse files Browse the repository at this point in the history
  • Loading branch information
ejohn20 committed Feb 14, 2018
1 parent 4d2ccb6 commit 5daf570
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 57 deletions.
4 changes: 1 addition & 3 deletions Rules/Analyzer/Crypto/DesDiagnosticAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ public IEnumerable<DiagnosticInfo> GetDiagnosticInfo(SyntaxNodeAnalysisContext c
if (!_expressionSyntaxAnalyzer.IsVulnerable(context.SemanticModel, syntax))
return result;


var location = Utils.GetParentLocalDeclarationStatement(syntax);
result.Add(new DiagnosticInfo(location != null ? location.GetLocation() : syntax.GetLocation()));
result.Add(new DiagnosticInfo(syntax.GetLocation()));

return result;
}
Expand Down
3 changes: 1 addition & 2 deletions Rules/Analyzer/Crypto/Md5DiagnosticAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public IEnumerable<DiagnosticInfo> GetDiagnosticInfo(SyntaxNodeAnalysisContext c
return result;


var location = Utils.GetParentLocalDeclarationStatement(syntax);
result.Add(new DiagnosticInfo(location != null ? location.GetLocation() : syntax.GetLocation()));
result.Add(new DiagnosticInfo(syntax.GetLocation()));

return result;
}
Expand Down
4 changes: 1 addition & 3 deletions Rules/Analyzer/Crypto/Sha1DiagnosticAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ public IEnumerable<DiagnosticInfo> GetDiagnosticInfo(SyntaxNodeAnalysisContext c
if (!_expressionSyntaxAnalyzer.IsVulnerable(context.SemanticModel, syntax))
return result;


var location = Utils.GetParentLocalDeclarationStatement(syntax);
result.Add(new DiagnosticInfo(location != null ? location.GetLocation() : syntax.GetLocation()));
result.Add(new DiagnosticInfo(syntax.GetLocation()));

return result;
}
Expand Down
34 changes: 0 additions & 34 deletions Rules/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,39 +187,5 @@ public static bool IsXssWhiteListedType(ISymbol type)
}
return false;
}

/// <summary>
/// Returns the entire declaration that contains an object create expression. Helps underline the entire line, rather than just a creation expression (right side) of a line.
/// </summary>
/// <param name="syntax"></param>
/// <returns></returns>
public static LocalDeclarationStatementSyntax GetParentLocalDeclarationStatement(ObjectCreationExpressionSyntax syntax)
{
var item = syntax.Parent;

while (true)
{
//Break if the item is null
if (item == null)
{
break;
}

//Check the type
if (item is LocalDeclarationStatementSyntax)
{
return item as LocalDeclarationStatementSyntax;
}

//If no good, walk up the chain to the next parent
if (item.Parent != null)
{
item = item.Parent;
continue;
}
}

return null;
}
}
}
18 changes: 9 additions & 9 deletions Rules/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Rules/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -622,27 +622,27 @@ Label controls are often found in HTML contexts, but can also appear in other co
<value>sec0027-weak-algorithm-md5</value>
</data>
<data name="Analyzer_SEC0027_Description" xml:space="preserve">
<value>The MD5CryptoServiceProvider class uses the weak MD5 algorithm and is not an approved hashing algorithm.</value>
</data>
<data name="Analyzer_SEC0027_MessageFormat" xml:space="preserve">
<value>Use the SHA256Managed (at least) preferably SHA512Managed for hashing operations.

NOTE. This not sufficient for password hashing, which requires a unique salt and adaptive hashing algorithm. See the documentation for secure password hashing advice.</value>
</data>
<data name="Analyzer_SEC0027_MessageFormat" xml:space="preserve">
<value>The MD5CryptoServiceProvider class uses the weak MD5 algorithm and is not an approved hashing algorithm.</value>
</data>
<data name="Analyzer_SEC0027_Title" xml:space="preserve">
<value>Weak Cryptography Algorithm (MD5)</value>
</data>
<data name="Analyzer_SEC0028_Anchor" xml:space="preserve">
<value>sec0028-weak-algorithm-sha1</value>
</data>
<data name="Analyzer_SEC0028_Description" xml:space="preserve">
<value>The SHA1 algorithm has known collision weaknesses and should no longer be used in a security context. Consider upgrading the algorithm to at least SHA2.</value>
</data>
<data name="Analyzer_SEC0028_MessageFormat" xml:space="preserve">
<value>Use the SHA256Managed (at least) preferably SHA512Managed for hashing operations.

NOTE. This not sufficient for password hashing, which requires a unique salt and adaptive hashing algorithm. See the documentation for secure password hashing advice.</value>
</data>
<data name="Analyzer_SEC0028_MessageFormat" xml:space="preserve">
<value>The SHA1 algorithm has known collision weaknesses and should no longer be used in a security context. Consider upgrading the algorithm to at least SHA2.</value>
</data>
<data name="Analyzer_SEC0028_Title" xml:space="preserve">
<value>Weak Cryptography Algorithm (SHA1)</value>
</data>
Expand Down

0 comments on commit 5daf570

Please sign in to comment.