From 7cb5e7ac44642b1facc33898f41f5597f4d86354 Mon Sep 17 00:00:00 2001 From: Costin Zaharia <56015273+costin-zaharia-sonarsource@users.noreply.github.com> Date: Fri, 15 Mar 2024 13:37:43 +0100 Subject: [PATCH] Update rspec before release (#8931) --- analyzers/rspec/cs/S1312.html | 2 ++ analyzers/rspec/cs/S1312.json | 6 ++++++ analyzers/rspec/cs/S1696.html | 2 +- analyzers/rspec/cs/S2053.html | 15 ++++++++++++- analyzers/rspec/cs/S2053.json | 2 +- analyzers/rspec/cs/S2629.json | 6 ++++++ analyzers/rspec/cs/S6664.json | 6 ++++++ analyzers/rspec/cs/S6667.json | 6 ++++++ analyzers/rspec/cs/S6668.json | 6 ++++++ analyzers/rspec/cs/S6669.json | 10 ++++++++- analyzers/rspec/cs/S6670.json | 6 ++++++ analyzers/rspec/cs/S6672.json | 6 ++++++ analyzers/rspec/cs/S6673.json | 6 ++++++ analyzers/rspec/cs/S6674.json | 6 ++++++ analyzers/rspec/cs/S6675.html | 21 ++++++------------- analyzers/rspec/cs/S6675.json | 6 ++++++ analyzers/rspec/cs/S6677.json | 6 ++++++ analyzers/rspec/cs/S6678.json | 6 ++++++ analyzers/rspec/cs/S6930.html | 8 +++---- analyzers/rspec/vbnet/S2053.html | 15 ++++++++++++- analyzers/rspec/vbnet/S2053.json | 2 +- analyzers/rspec/vbnet/S6930.html | 8 +++---- .../src/SonarAnalyzer.CSharp/sonarpedia.json | 2 +- .../SonarAnalyzer.VisualBasic/sonarpedia.json | 2 +- 24 files changed, 130 insertions(+), 31 deletions(-) diff --git a/analyzers/rspec/cs/S1312.html b/analyzers/rspec/cs/S1312.html index 46a767984a2..9a8b7ff1e66 100644 --- a/analyzers/rspec/cs/S1312.html +++ b/analyzers/rspec/cs/S1312.html @@ -18,9 +18,11 @@

Why is this an issue?

  • NLog
  • log4net
  • +

    Noncompliant code example

     public Logger logger;
     
    +

    Compliant solution

     private static readonly Logger logger;
     
    diff --git a/analyzers/rspec/cs/S1312.json b/analyzers/rspec/cs/S1312.json index 5c998c3853e..82c8c50df42 100644 --- a/analyzers/rspec/cs/S1312.json +++ b/analyzers/rspec/cs/S1312.json @@ -1,6 +1,12 @@ { "title": "Logger fields should be \"private static readonly\"", "type": "CODE_SMELL", + "code": { + "impacts": { + "MAINTAINABILITY": "LOW" + }, + "attribute": "CONVENTIONAL" + }, "status": "ready", "remediation": { "func": "Constant\/Issue", diff --git a/analyzers/rspec/cs/S1696.html b/analyzers/rspec/cs/S1696.html index d1c3f078589..d247b4234f2 100644 --- a/analyzers/rspec/cs/S1696.html +++ b/analyzers/rspec/cs/S1696.html @@ -39,6 +39,6 @@

    Documentation

  • Microsoft Learn - NullReferenceException class
  • Microsoft Learn - Null-conditional operators ?. and ?[]
  • + href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/member-access-operators#null-conditional-operators--and-">Null-conditional operators ?. and ?[] diff --git a/analyzers/rspec/cs/S2053.html b/analyzers/rspec/cs/S2053.html index 7fbe9bab3db..2a006c5efd1 100644 --- a/analyzers/rspec/cs/S2053.html +++ b/analyzers/rspec/cs/S2053.html @@ -19,6 +19,19 @@

    What is the potential impact?

    of password hashes with identical salt that can then be attacked as explained before.

    With short salts, the probability of a collision between two users' passwords and salts couple might be low depending on the salt size. The shorter the salt, the higher the collision probability. In any case, using longer, cryptographically secure salt should be preferred.

    +

    Exceptions

    +

    To securely store password hashes, it is a recommended to rely on key derivation functions that are computationally intensive. Examples of such +functions are:

    + +

    When they are used for password storage, using a secure, random salt is required.

    +

    However, those functions can also be used for other purposes such as master key derivation or password-based pre-shared key generation. In those +cases, the implemented cryptographic protocol might require using a fixed salt to derive keys in a deterministic way. In such cases, using a fixed +salt is safe and accepted.

    How to fix it in .NET

    Code examples

    The following code contains examples of hard-coded salts.

    @@ -43,7 +56,7 @@

    Compliant solution

    How does this work?

    This code ensures that each user’s password has a unique salt value associated with it. It generates a salt randomly and with a length that -provides the required security level. It uses a salt length of at least 16 bytes (128 bits), as recommended by industry standards.

    +provides the required security level. It uses a salt length of at least 32 bytes (256 bits), as recommended by industry standards.

    In the case of the code sample, the class automatically takes care of generating a secure salt if none is specified.

    Resources

    Standards

    diff --git a/analyzers/rspec/cs/S2053.json b/analyzers/rspec/cs/S2053.json index 975d431704b..48635986451 100644 --- a/analyzers/rspec/cs/S2053.json +++ b/analyzers/rspec/cs/S2053.json @@ -1,5 +1,5 @@ { - "title": "Hashes should include an unpredictable salt", + "title": "Password hashing functions should use an unpredictable salt", "type": "VULNERABILITY", "code": { "impacts": { diff --git a/analyzers/rspec/cs/S2629.json b/analyzers/rspec/cs/S2629.json index d8e943e44fd..a9c5fcebff9 100644 --- a/analyzers/rspec/cs/S2629.json +++ b/analyzers/rspec/cs/S2629.json @@ -1,6 +1,12 @@ { "title": "Logging templates should be constant", "type": "CODE_SMELL", + "code": { + "impacts": { + "MAINTAINABILITY": "MEDIUM" + }, + "attribute": "EFFICIENT" + }, "status": "ready", "remediation": { "func": "Constant\/Issue", diff --git a/analyzers/rspec/cs/S6664.json b/analyzers/rspec/cs/S6664.json index 861aa69669c..dd0edaf107f 100644 --- a/analyzers/rspec/cs/S6664.json +++ b/analyzers/rspec/cs/S6664.json @@ -1,6 +1,12 @@ { "title": "The code block contains too many logging calls", "type": "CODE_SMELL", + "code": { + "impacts": { + "MAINTAINABILITY": "LOW" + }, + "attribute": "FOCUSED" + }, "status": "ready", "remediation": { "func": "Constant\/Issue", diff --git a/analyzers/rspec/cs/S6667.json b/analyzers/rspec/cs/S6667.json index 24f6f61c103..85e0a69b8e7 100644 --- a/analyzers/rspec/cs/S6667.json +++ b/analyzers/rspec/cs/S6667.json @@ -1,6 +1,12 @@ { "title": "Logging in a catch clause should pass the caught exception as a parameter.", "type": "CODE_SMELL", + "code": { + "impacts": { + "MAINTAINABILITY": "MEDIUM" + }, + "attribute": "COMPLETE" + }, "status": "ready", "remediation": { "func": "Constant\/Issue", diff --git a/analyzers/rspec/cs/S6668.json b/analyzers/rspec/cs/S6668.json index b0abe537c91..b6d9e3ef58d 100644 --- a/analyzers/rspec/cs/S6668.json +++ b/analyzers/rspec/cs/S6668.json @@ -1,6 +1,12 @@ { "title": "Logging arguments should be passed to the correct parameter", "type": "CODE_SMELL", + "code": { + "impacts": { + "RELIABILITY": "MEDIUM" + }, + "attribute": "LOGICAL" + }, "status": "ready", "remediation": { "func": "Constant\/Issue", diff --git a/analyzers/rspec/cs/S6669.json b/analyzers/rspec/cs/S6669.json index b07ed5064d2..039e2f2d53e 100644 --- a/analyzers/rspec/cs/S6669.json +++ b/analyzers/rspec/cs/S6669.json @@ -1,12 +1,20 @@ { "title": "Logger field or property name should comply with a naming convention", "type": "CODE_SMELL", + "code": { + "impacts": { + "MAINTAINABILITY": "MEDIUM" + }, + "attribute": "CONVENTIONAL" + }, "status": "ready", "remediation": { "func": "Constant\/Issue", "constantCost": "2min" }, - "tags": ["logging"], + "tags": [ + "logging" + ], "defaultSeverity": "Minor", "ruleSpecification": "RSPEC-6669", "sqKey": "S6669", diff --git a/analyzers/rspec/cs/S6670.json b/analyzers/rspec/cs/S6670.json index 0c309b18f08..ed0e2e81c32 100644 --- a/analyzers/rspec/cs/S6670.json +++ b/analyzers/rspec/cs/S6670.json @@ -1,6 +1,12 @@ { "title": "\"Trace.Write\" and \"Trace.WriteLine\" should not be used", "type": "CODE_SMELL", + "code": { + "impacts": { + "RELIABILITY": "MEDIUM" + }, + "attribute": "LOGICAL" + }, "status": "ready", "remediation": { "func": "Constant\/Issue", diff --git a/analyzers/rspec/cs/S6672.json b/analyzers/rspec/cs/S6672.json index a5e6b83d4b3..17c0d2041a1 100644 --- a/analyzers/rspec/cs/S6672.json +++ b/analyzers/rspec/cs/S6672.json @@ -1,6 +1,12 @@ { "title": "Generic logger injection should match enclosing type", "type": "CODE_SMELL", + "code": { + "impacts": { + "MAINTAINABILITY": "MEDIUM" + }, + "attribute": "CONVENTIONAL" + }, "status": "ready", "remediation": { "func": "Constant\/Issue", diff --git a/analyzers/rspec/cs/S6673.json b/analyzers/rspec/cs/S6673.json index 159ec37d9dc..956762a4416 100644 --- a/analyzers/rspec/cs/S6673.json +++ b/analyzers/rspec/cs/S6673.json @@ -1,6 +1,12 @@ { "title": "Log message template placeholders should be in the right order", "type": "CODE_SMELL", + "code": { + "impacts": { + "MAINTAINABILITY": "MEDIUM" + }, + "attribute": "CONVENTIONAL" + }, "status": "ready", "remediation": { "func": "Constant\/Issue", diff --git a/analyzers/rspec/cs/S6674.json b/analyzers/rspec/cs/S6674.json index bfd313cb1f8..b397def5caa 100644 --- a/analyzers/rspec/cs/S6674.json +++ b/analyzers/rspec/cs/S6674.json @@ -1,6 +1,12 @@ { "title": "Log message template should be syntactically correct", "type": "BUG", + "code": { + "impacts": { + "RELIABILITY": "MEDIUM" + }, + "attribute": "LOGICAL" + }, "status": "ready", "remediation": { "func": "Constant\/Issue", diff --git a/analyzers/rspec/cs/S6675.html b/analyzers/rspec/cs/S6675.html index 0844ced8723..79cd008791c 100644 --- a/analyzers/rspec/cs/S6675.html +++ b/analyzers/rspec/cs/S6675.html @@ -9,21 +9,12 @@

    Why is this an issue?

    Using Trace.WriteLineIf with such properties should be avoided since it can lead to misinterpretation and produce confusion.

    In particular, Trace.WriteLineIf may appear as equivalent to the level-specific tracing methods provided by Trace, such as Trace.Error, but it is not.

    -

    Code examples

    -

    Noncompliant code example

    -
    -public void Method(TraceSwitch traceSwitch)
    -{
    -    Trace.WriteIf(traceSwitch.TraceError, "Failed to log in!");
    -}
    -
    -

    Compliant solution

    -
    -public void Method(bool condition)
    -{
    -    Trace.WriteIf(condition, "Failed to log in!");
    -}
    -
    +

    The difference is that Trace.WriteLineIf(switch.TraceError, …​) conditionally writes the trace, based on the switch, whereas +Trace.TraceError always writes the trace, no matter whether switch.TraceError is true or +false.

    +

    Moreover, unlike Trace.TraceError, Trace.WriteLineIf(switch.TraceError, …​) would behave like +Trace.WriteLine(…​) when switch.TraceError is true, writing unfiltered to the underlying trace listeners and +not categorizing the log entry by level, as described more in detail in {rule:csharpsquid:S6670}.

    How to fix it

    The fix depends on the intent behind the use of TraceSwitch levels with How to fix it

    Code examples

    Noncompliant code example

    -[Route(@"Something\[controller]")] // Noncompliant: Replace `\` with `/`.
    +[Route(@"Something\[controller]")] // Noncompliant: Replace '\' with '/'.
     public class HomeController : Controller
     {
         [HttpGet]
    @@ -36,7 +36,7 @@ 

    Noncompliant code example

    Compliant solution

    -[Route(@"Something/[controller]")] // `\` replaced with `/`
    +[Route(@"Something/[controller]")] // '\' replaced with '/'
     public class HomeController : Controller
     {
         [HttpGet]
    @@ -47,13 +47,13 @@ 

    Noncompliant code example

     app.MapControllerRoute(
         name: "default",
    -    pattern: "{controller=Home}\\{action=Index}"); // Noncompliant: Replace `\` with `/`.
    +    pattern: "{controller=Home}\\{action=Index}"); // Noncompliant: Replace '\' with '/'.
     

    Compliant solution

     app.MapControllerRoute(
         name: "default",
    -    pattern: "{controller=Home}/{action=Index}"); // `\` replaced with `/`
    +    pattern: "{controller=Home}/{action=Index}"); // '\' replaced with '/'
     

    Resources

    Documentation

    diff --git a/analyzers/rspec/vbnet/S2053.html b/analyzers/rspec/vbnet/S2053.html index 0c12e1d3739..96412990479 100644 --- a/analyzers/rspec/vbnet/S2053.html +++ b/analyzers/rspec/vbnet/S2053.html @@ -19,6 +19,19 @@

    What is the potential impact?

    of password hashes with identical salt that can then be attacked as explained before.

    With short salts, the probability of a collision between two users' passwords and salts couple might be low depending on the salt size. The shorter the salt, the higher the collision probability. In any case, using longer, cryptographically secure salt should be preferred.

    +

    Exceptions

    +

    To securely store password hashes, it is a recommended to rely on key derivation functions that are computationally intensive. Examples of such +functions are:

    + +

    When they are used for password storage, using a secure, random salt is required.

    +

    However, those functions can also be used for other purposes such as master key derivation or password-based pre-shared key generation. In those +cases, the implemented cryptographic protocol might require using a fixed salt to derive keys in a deterministic way. In such cases, using a fixed +salt is safe and accepted.

    How to fix it in .NET

    Code examples

    The following code contains examples of hard-coded salts.

    @@ -41,7 +54,7 @@

    Compliant solution

    How does this work?

    This code ensures that each user’s password has a unique salt value associated with it. It generates a salt randomly and with a length that -provides the required security level. It uses a salt length of at least 16 bytes (128 bits), as recommended by industry standards.

    +provides the required security level. It uses a salt length of at least 32 bytes (256 bits), as recommended by industry standards.

    In the case of the code sample, the class automatically takes care of generating a secure salt if none is specified.

    Resources

    Standards

    diff --git a/analyzers/rspec/vbnet/S2053.json b/analyzers/rspec/vbnet/S2053.json index 975d431704b..48635986451 100644 --- a/analyzers/rspec/vbnet/S2053.json +++ b/analyzers/rspec/vbnet/S2053.json @@ -1,5 +1,5 @@ { - "title": "Hashes should include an unpredictable salt", + "title": "Password hashing functions should use an unpredictable salt", "type": "VULNERABILITY", "code": { "impacts": { diff --git a/analyzers/rspec/vbnet/S6930.html b/analyzers/rspec/vbnet/S6930.html index 6464b0d5e81..1c94d9b699b 100644 --- a/analyzers/rspec/vbnet/S6930.html +++ b/analyzers/rspec/vbnet/S6930.html @@ -27,7 +27,7 @@

    How to fix it

    Code examples

    Noncompliant code example

    -<Route("Something\[controller]")> ' Noncompliant: Replace `\` with `/`.
    +<Route("Something\[controller]")> ' Noncompliant: Replace '\' with '/'.
     Public Class HomeController
         Inherits Controller
     
    @@ -39,7 +39,7 @@ 

    Noncompliant code example

    Compliant solution

    -<Route("Something/[controller]")> ' `\` replaced with `/`
    +<Route("Something/[controller]")> ' '\' replaced with '/'
     Public Class HomeController
         Inherits Controller
     
    @@ -53,13 +53,13 @@ 

    Noncompliant code example

     app.MapControllerRoute(
         name:="default",
    -    pattern:="{controller=Home}\{action=Index}") ' Noncompliant: Replace `\` with `/`.
    +    pattern:="{controller=Home}\{action=Index}") ' Noncompliant: Replace '\' with '/'.
     

    Compliant solution

     app.MapControllerRoute(
         name:="default",
    -    pattern:="{controller=Home}/{action=Index}") ' `\` replaced with `/`
    +    pattern:="{controller=Home}/{action=Index}") ' '\' replaced with '/'
     

    Resources

    Documentation

    diff --git a/analyzers/src/SonarAnalyzer.CSharp/sonarpedia.json b/analyzers/src/SonarAnalyzer.CSharp/sonarpedia.json index 7f89a06bc06..3b1c51d2b5d 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/sonarpedia.json +++ b/analyzers/src/SonarAnalyzer.CSharp/sonarpedia.json @@ -3,7 +3,7 @@ "languages": [ "CSH" ], - "latest-update": "2024-02-29T15:53:45.968501800Z", + "latest-update": "2024-03-15T12:11:31.487123200Z", "options": { "no-language-in-filenames": true } diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/sonarpedia.json b/analyzers/src/SonarAnalyzer.VisualBasic/sonarpedia.json index 45abc8bce5b..274bf247898 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/sonarpedia.json +++ b/analyzers/src/SonarAnalyzer.VisualBasic/sonarpedia.json @@ -3,7 +3,7 @@ "languages": [ "VBNET" ], - "latest-update": "2024-02-29T15:54:07.274928100Z", + "latest-update": "2024-03-15T12:11:49.495514500Z", "options": { "no-language-in-filenames": true }