Skip to content

Commit cd7cf12

Browse files
authored
Merge branch 'main' into copilot/fix-218
2 parents f3ec3ca + 0643777 commit cd7cf12

38 files changed

Lines changed: 1773 additions & 40 deletions

.github/workflows/codeql-analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Checkout repository
2020
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
2121
- name: Initialize CodeQL
22-
uses: github/codeql-action/init@76621b61decf072c1cee8dd1ce2d2a82d33c17ed
22+
uses: github/codeql-action/init@3c3833e0f8c1c83d449a7478aa59c036a9165498
2323
with:
2424
languages: ${{ matrix.language }}
2525
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -28,7 +28,7 @@ jobs:
2828
# Prefix the list here with "+" to use these queries and those in the config file.
2929
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
3030
# queries: security-extended,security-and-quality
31-
uses: github/codeql-action/autobuild@76621b61decf072c1cee8dd1ce2d2a82d33c17ed
31+
uses: github/codeql-action/autobuild@3c3833e0f8c1c83d449a7478aa59c036a9165498
3232

3333
- name: Perform CodeQL Analysis
34-
uses: github/codeql-action/analyze@76621b61decf072c1cee8dd1ce2d2a82d33c17ed
34+
uses: github/codeql-action/analyze@3c3833e0f8c1c83d449a7478aa59c036a9165498
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: copilot-setup-steps
2+
on:
3+
workflow_dispatch:
4+
jobs:
5+
copilot-setup-steps:
6+
runs-on: ubuntu-latest
7+
permissions:
8+
contents: read
9+
id-token: write
10+
environment: copilot
11+
steps:
12+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
13+
- name: Python deps for MCP server
14+
run: |
15+
python3 -m pip install --upgrade pip
16+
python3 -m pip install "fastmcp>=0.4"
17+

.github/workflows/semantic-commit-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
if: ${{ github.event_name == 'pull_request' }}
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: amannn/action-semantic-pull-request@0723387faaf9b38adef4775cd42cfd5155ed6017 # ratchet:amannn/action-semantic-pull-request@v5
17+
- uses: amannn/action-semantic-pull-request@48f256284bd46cdaab1048c3721360e808335d50 # ratchet:amannn/action-semantic-pull-request@v6
1818
name: Check PR for Semantic Commit Message
1919
env:
2020
GITHUB_TOKEN: ${{ github.token }}

.github/workflows/sonarcloud.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Set up JDK
13-
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # ratchet:actions/setup-java@v3
13+
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # ratchet:actions/setup-java@v5
1414
with:
1515
java-version: '17'
1616
distribution: temurin

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,14 @@ paket-files/
252252
# JetBrains Rider
253253
.idea/
254254
*.sln.iml
255+
256+
# Python
257+
__pycache__/
258+
*.pyc
259+
*.pyo
260+
*.pyd
261+
262+
# MCP Server temporary files
263+
tools/mcp/Directory.Build.props.backup
264+
tools/mcp/*.log
265+
tools/mcp/test-results.trx

CHANGELOG.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,62 @@
1+
## [1.8.0](https://github.com/philips-software/roslyn-analyzers/compare/v1.7.0...v1.8.0) (2025-08-13)
2+
3+
4+
### Features
5+
6+
* Add AvoidTodoCommentsAnalyzer (PH2151) to detect TODO comments in source code ([#872](https://github.com/philips-software/roslyn-analyzers/issues/872)) ([dc5da39](https://github.com/philips-software/roslyn-analyzers/commit/dc5da3926b7ffd4963fba4c820085a9e4e48865e))
7+
* Add AvoidUnusedToString analyzer (PH2153) to detect discarded ToString() calls ([#876](https://github.com/philips-software/roslyn-analyzers/issues/876)) ([643cd2e](https://github.com/philips-software/roslyn-analyzers/commit/643cd2e699a7a812029b058d15dd8caf6f6ca684))
8+
* Add code fixer for PH2140 AvoidExcludeFromCodeCoverage analyzer ([#875](https://github.com/philips-software/roslyn-analyzers/issues/875)) ([c68a267](https://github.com/philips-software/roslyn-analyzers/commit/c68a267bc27254656abc2ca713bfb102ddb51e05))
9+
* Enable PH2146 analyzer for detecting redundant ToString() calls on strings ([#870](https://github.com/philips-software/roslyn-analyzers/issues/870)) ([09afc80](https://github.com/philips-software/roslyn-analyzers/commit/09afc809d8ab8bbacc3c55cb24ff97adcf51965b))
10+
* PH2158: AvoidPkcsPaddingWithRsaEncryption security analyzer with CodeFixer ([#908](https://github.com/philips-software/roslyn-analyzers/issues/908)) ([0e91f2b](https://github.com/philips-software/roslyn-analyzers/commit/0e91f2bfbc6ecc600af3e1f9c4c5fd11b3dfeb96))
11+
12+
13+
### Bug Fixes
14+
15+
* Correct PH2147 false positive for typed discards ([#867](https://github.com/philips-software/roslyn-analyzers/issues/867)) ([a00248c](https://github.com/philips-software/roslyn-analyzers/commit/a00248c15da128f1dfed5f4c437d78cfa983c03e))
16+
* PH2012 analyzer to detect literal integer timeout values ([#868](https://github.com/philips-software/roslyn-analyzers/issues/868)) ([0b3a2c7](https://github.com/philips-software/roslyn-analyzers/commit/0b3a2c7488913b65cb4385630b2a6fb4f22e15a3))
17+
* PH2045 AvoidStaticClasses analyzer to properly handle properties, constructors, and events ([#904](https://github.com/philips-software/roslyn-analyzers/issues/904)) ([62a5650](https://github.com/philips-software/roslyn-analyzers/commit/62a565015343fdeec8b54db1333514573004338a))
18+
* PH2090 false positive for ILogger.LogError() calls ([#910](https://github.com/philips-software/roslyn-analyzers/issues/910)) ([b8c121e](https://github.com/philips-software/roslyn-analyzers/commit/b8c121e7136a764c4c1d2be34aa28c1c5ec1ab5e))
19+
* PH2101 false negative: detect null dereference when checking properties ([#842](https://github.com/philips-software/roslyn-analyzers/issues/842)) ([916ebe3](https://github.com/philips-software/roslyn-analyzers/commit/916ebe3136ebed691fb11ab9d6458f54743fc46f))
20+
* PH2136 false positive by clearing analyzer state between compilations ([#912](https://github.com/philips-software/roslyn-analyzers/issues/912)) ([9a7c4c5](https://github.com/philips-software/roslyn-analyzers/commit/9a7c4c519d8fe6801e88f0a6e6cde2f32d6fa99e))
21+
* Simplify PH2115 CodeFixer to use Formatter.FormatAsync for automatic indentation ([#914](https://github.com/philips-software/roslyn-analyzers/issues/914)) ([fcd5820](https://github.com/philips-software/roslyn-analyzers/commit/fcd5820c610203121e8596fe52f9a1b7ad169397))
22+
23+
24+
### Tests
25+
26+
* Add unit tests for AttributeHelper class ([#916](https://github.com/philips-software/roslyn-analyzers/issues/916)) ([136bf10](https://github.com/philips-software/roslyn-analyzers/commit/136bf1068a038bfe9e5f0fd5059e6b51cb670c8f))
27+
* Fix concurrency issues in GeneratedCodeDetectorTest ([#896](https://github.com/philips-software/roslyn-analyzers/issues/896)) ([21f6d8b](https://github.com/philips-software/roslyn-analyzers/commit/21f6d8b7e0535f443d002ca08e5ed211ce2d6ae6))
28+
29+
30+
### Continuous Integration
31+
32+
* Add NuGet package ecosystem to dependabot configuration with CodeAnalysis exclusions ([#891](https://github.com/philips-software/roslyn-analyzers/issues/891)) ([75bbacc](https://github.com/philips-software/roslyn-analyzers/commit/75bbacc0ec0a1ef0a5480908c7b1233ec9d46ea5))
33+
* Add types: [checks_requested] to merge_group triggers in GitHub Actions workflows ([#871](https://github.com/philips-software/roslyn-analyzers/issues/871)) ([abd4acb](https://github.com/philips-software/roslyn-analyzers/commit/abd4acba4c4bec83b0518d4ae254aea27156a4e7))
34+
* fix tagversion.yml to handle apostrophes ([#920](https://github.com/philips-software/roslyn-analyzers/issues/920)) ([8cfb271](https://github.com/philips-software/roslyn-analyzers/commit/8cfb2712603a67643360bf4a0f1b67aea63d4a44))
35+
* Improve CheckMarkdown debugging by enabling quiet mode and adding clear error messages ([#899](https://github.com/philips-software/roslyn-analyzers/issues/899)) ([3772fa0](https://github.com/philips-software/roslyn-analyzers/commit/3772fa076fbbf2eaf98ccf0642a333884898f066))
36+
* Use original zgosalvez action instead of philips-forks for pinned actions checking ([#917](https://github.com/philips-software/roslyn-analyzers/issues/917)) ([273330b](https://github.com/philips-software/roslyn-analyzers/commit/273330baf57ec728a69908192701dfc3948c798c))
37+
38+
39+
### Code Refactoring
40+
41+
* Improve LiteralHelper.IsNull() implementation to use SyntaxKind check for better robustness ([#887](https://github.com/philips-software/roslyn-analyzers/issues/887)) ([b117eef](https://github.com/philips-software/roslyn-analyzers/commit/b117eef7318b4db0a39fba622cbf89ed083e9f9a))
42+
43+
44+
### Build Systems
45+
46+
* Bump actions/checkout from 4.2.2 to 5.0.0 ([#918](https://github.com/philips-software/roslyn-analyzers/issues/918)) ([038d257](https://github.com/philips-software/roslyn-analyzers/commit/038d257d355be32743d2e8bc3a364d37f3a7555f))
47+
* Bump github/codeql-action from 3.29.7 to 3.29.8 ([#894](https://github.com/philips-software/roslyn-analyzers/issues/894)) ([413a3a0](https://github.com/philips-software/roslyn-analyzers/commit/413a3a06cac6ef325e2579fd8bd282a5be91420a))
48+
* Bump github/codeql-action from 3.29.8 to 3.29.9 ([#921](https://github.com/philips-software/roslyn-analyzers/issues/921)) ([9271e04](https://github.com/philips-software/roslyn-analyzers/commit/9271e04fe139bfdcf8c4c07b6651f32986aec111))
49+
50+
51+
### Documentation
52+
53+
* Add comprehensive GitHub Copilot instructions for repository workflow ([#883](https://github.com/philips-software/roslyn-analyzers/issues/883)) ([6e41164](https://github.com/philips-software/roslyn-analyzers/commit/6e41164fb539bead9dab917a4473fa021503323b))
54+
* Add comprehensive MSTest analyzers migration guide for Microsoft's official analyzers ([#853](https://github.com/philips-software/roslyn-analyzers/issues/853)) ([32b3b12](https://github.com/philips-software/roslyn-analyzers/commit/32b3b123e9999107b7051e73d3cef91c55e40bb1))
55+
* fix dead link in DuplicateCodeAnalyzer documentation ([#915](https://github.com/philips-software/roslyn-analyzers/issues/915)) ([e97329e](https://github.com/philips-software/roslyn-analyzers/commit/e97329ee1e0e9f93a58171e61c5d0f87f926cbab))
56+
* Improve CD documentation with detailed release process ([#881](https://github.com/philips-software/roslyn-analyzers/issues/881)) ([adbdea5](https://github.com/philips-software/roslyn-analyzers/commit/adbdea5808f43408a231602adee1dbb6ffe93a90))
57+
58+
59+
160
## [1.7.0](https://github.com/philips-software/roslyn-analyzers/compare/v1.6.4...v1.7.0) (2025-08-09)
261

362

Directory.Build.Analyzer.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
<ItemGroup>
4646
<None Include="..\packageicon.png" Pack="true" PackagePath="\" />
47-
<None Update="tools\*.ps1" CopyToOutputDirectory="Always" Pack="true" PackagePath="" />
47+
<None Include="tools\*.ps1" CopyToOutputDirectory="Always" Pack="true" PackagePath="tools" />
4848
<None Include="$(OutputPath)\netstandard2.0\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
4949
<None Include="$(OutputPath)\netstandard2.0\$(AssemblyName).pdb" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
5050
<None Include="$(OutputPath)\netstandard2.0\Philips.CodeAnalysis.Common.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# PH2149: Avoid problematic using statement patterns
2+
3+
| Property | Value |
4+
|--|--|
5+
| Package | [Philips.CodeAnalysis.MaintainabilityAnalyzers](https://www.nuget.org/packages/Philips.CodeAnalysis.MaintainabilityAnalyzers) |
6+
| Diagnostic ID | PH2149 |
7+
| Category | [Maintainability](../Maintainability.md) |
8+
| Analyzer | [AvoidProblematicUsingPatternsAnalyzer](https://github.com/philips-software/roslyn-analyzers/blob/main/Philips.CodeAnalysis.MaintainabilityAnalyzers/Maintainability/AvoidProblematicUsingPatternsAnalyzer.cs)
9+
| CodeFix | No |
10+
| Severity | Warning |
11+
| Enabled By Default | No |
12+
13+
## Introduction
14+
15+
This rule flags `using` statements that use fields, member access expressions, or local variables, which can lead to double disposal or ownership issues.
16+
17+
## Reason
18+
19+
Using statements with fields or variables can be problematic because they may dispose objects that are already being managed elsewhere, potentially causing:
20+
21+
- Double disposal exceptions when the object is disposed both by the using statement and by other code
22+
- Access to disposed objects if the field/variable is used after the using block
23+
- Unclear ownership semantics where multiple parts of code think they own the object
24+
25+
## How to fix violations
26+
27+
Replace problematic using patterns with safer alternatives:
28+
29+
- Create new objects directly in the using statement
30+
- Call methods that return disposable objects
31+
- Use parameters instead of fields when possible
32+
- Consider refactoring the design to have clearer ownership semantics
33+
34+
## Examples
35+
36+
### Incorrect
37+
38+
```csharp
39+
class BadExample
40+
{
41+
private Stream _stream = new MemoryStream();
42+
43+
public void BadMethod()
44+
{
45+
// Direct field usage - may lead to double disposal
46+
using (_stream)
47+
{
48+
// Do something
49+
}
50+
51+
// Field assignment to using variable
52+
using (var localStream = _stream)
53+
{
54+
// Do something
55+
}
56+
57+
// Member access expression
58+
using (this.Stream)
59+
{
60+
// Do something
61+
}
62+
63+
// Local variable reuse
64+
Stream existingStream = new MemoryStream();
65+
using (var localStream = existingStream)
66+
{
67+
// Do something
68+
}
69+
}
70+
}
71+
```
72+
73+
### Correct
74+
75+
```csharp
76+
class GoodExample
77+
{
78+
public void GoodMethod(Stream inputParameter)
79+
{
80+
// Create new object directly - safe
81+
using (var stream = new MemoryStream())
82+
{
83+
// Do something
84+
}
85+
86+
// Method call that returns disposable - safe
87+
using (var stream = CreateStream())
88+
{
89+
// Do something
90+
}
91+
92+
// Using parameter - safe (caller owns the object)
93+
using (var stream = inputParameter)
94+
{
95+
// Do something
96+
}
97+
}
98+
99+
private Stream CreateStream()
100+
{
101+
return new MemoryStream();
102+
}
103+
}
104+
```
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# PH2158: Avoid PKCS#1 v1.5 padding with RSA encryption
2+
3+
| Property | Value |
4+
|--|--|
5+
| Package | [Philips.CodeAnalysis.SecurityAnalyzers](https://www.nuget.org/packages/Philips.CodeAnalysis.SecurityAnalyzers) |
6+
| Diagnostic ID | PH2158 |
7+
| Category | [Security](../Security.md) |
8+
| Analyzer | [AvoidPkcsPaddingWithRsaEncryptionAnalyzer](https://github.com/philips-software/roslyn-analyzers/blob/main/Philips.CodeAnalysis.SecurityAnalyzers/AvoidPkcsPaddingWithRsaEncryptionAnalyzer.cs)
9+
| CodeFix | Yes |
10+
| Severity | Error |
11+
| Enabled By Default | No |
12+
13+
## Introduction
14+
15+
This rule identifies usage of PKCS#1 v1.5 padding with RSA encryption, which is vulnerable to padding oracle attacks.
16+
17+
## Reason
18+
19+
PKCS#1 v1.5 padding is susceptible to padding oracle attacks that can allow attackers to decrypt encrypted data or forge signatures. OAEP (Optimal Asymmetric Encryption Padding) provides significantly better security through a more robust padding scheme that includes randomness and cryptographic hashing.
20+
21+
## How to fix violations
22+
23+
Replace `RSAEncryptionPadding.Pkcs1` with `RSAEncryptionPadding.OaepSHA256` or other OAEP variants. The CodeFix provider will automatically suggest replacing `.Pkcs1` with `.OaepSHA256`.
24+
25+
## Examples
26+
27+
### Incorrect
28+
29+
```csharp
30+
using System.Security.Cryptography;
31+
32+
class Example
33+
{
34+
void EncryptData(RSA rsa, byte[] data)
35+
{
36+
// This triggers PH2158 - PKCS#1 v1.5 padding is insecure
37+
byte[] encrypted = rsa.Encrypt(data, RSAEncryptionPadding.Pkcs1);
38+
}
39+
40+
void DecryptData(RSA rsa, byte[] encryptedData)
41+
{
42+
// This also triggers PH2158
43+
byte[] decrypted = rsa.Decrypt(encryptedData, RSAEncryptionPadding.Pkcs1);
44+
}
45+
46+
void AssignPadding()
47+
{
48+
// This also triggers PH2158
49+
RSAEncryptionPadding padding = RSAEncryptionPadding.Pkcs1;
50+
}
51+
}
52+
```
53+
54+
### Correct
55+
56+
```csharp
57+
using System.Security.Cryptography;
58+
59+
class Example
60+
{
61+
void EncryptData(RSA rsa, byte[] data)
62+
{
63+
// Use OAEP padding for better security
64+
byte[] encrypted = rsa.Encrypt(data, RSAEncryptionPadding.OaepSHA256);
65+
}
66+
67+
void DecryptData(RSA rsa, byte[] encryptedData)
68+
{
69+
// Use OAEP padding for better security
70+
byte[] decrypted = rsa.Decrypt(encryptedData, RSAEncryptionPadding.OaepSHA256);
71+
}
72+
73+
void AssignPadding()
74+
{
75+
// Use OAEP padding for better security
76+
RSAEncryptionPadding padding = RSAEncryptionPadding.OaepSHA256;
77+
}
78+
}
79+
```
80+
81+
## Configuration
82+
83+
This rule is disabled by default and must be explicitly enabled in your project configuration.
84+
85+
## Suppression
86+
87+
```csharp
88+
[SuppressMessage("Philips.CodeAnalysis.SecurityAnalyzers", "PH2158:Avoid PKCS#1 v1.5 padding with RSA encryption", Justification = "Reviewed.")]
89+
```
90+
91+
## References
92+
93+
- [OAEP Padding](https://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding)
94+
- [Padding Oracle Attacks](https://en.wikipedia.org/wiki/Padding_oracle_attack)
95+
- [RSAEncryptionPadding Class](https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.rsaencryptionpadding)
96+
- [How much safer is RSA OAEP compared to RSA with PKCS1 v1.5 padding?](https://crypto.stackexchange.com/questions/47436/how-much-safer-is-rsa-oaep-compared-to-rsa-with-pkcs1-v1-5-padding)

Philips.CodeAnalysis.AnalyzerPerformance/Philips.CodeAnalysis.AnalyzerPerformance.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="MSBuild.StructuredLogger" Version="2.2.472" />
13+
<PackageReference Include="MSBuild.StructuredLogger" Version="2.3.45" />
1414
</ItemGroup>
1515

1616
<ItemGroup>

0 commit comments

Comments
 (0)