Skip to content

Add C# reflection detection rules#638

Open
Copilot wants to merge 7 commits intomainfrom
copilot/add-reflection-detection-rules
Open

Add C# reflection detection rules#638
Copilot wants to merge 7 commits intomainfrom
copilot/add-reflection-detection-rules

Conversation

Copy link
Contributor

Copilot AI commented Feb 14, 2026

Summary

Fixed rule validation errors in reflection.json by capitalizing all enum values to match schema requirements.

Changes Made

  • Changed severity: "moderate" → "Moderate"
  • Changed type: "regex" → "Regex", "regexword" → "RegexWord"
  • Changed scopes: "code" → "Code"
  • Changed confidence: "medium" → "Medium", "high" → "High"

Error Fixed

Rule validation was failing because enum values must be capitalized according to the rule-schema-v1.json:

  • Severity: "Critical", "Important", "Moderate", "BestPractice", "ManualReview", "Unspecified"
  • Type: "Regex", "RegexWord", "String", "Substring"
  • Scopes: "Code", "Comment", "All", "Html"
  • Confidence: "High", "Medium", "Low", "Unspecified"

All 8 reflection rules now use proper capitalized enum values and should pass schema validation.

Original prompt

This section details on the original issue you should resolve

<issue_title>Reflection Detection</issue_title>
<issue_description>I'm not sure how exactly this applies to other languages but this is a particular issue in C#.

Using Reflection can allow for dynamic behavior at runtime, including dynamic access to APIs which are not discernable at static analysis time. Application Inspector should report when an app using reflection in a way that would allow such behavior.

If you want a project to test reflection rules against see OAT.

Proposal:

I don't think we want to overgrab here, so there are some things that seem okay.

Check the Version Number by reflecting the assembly information from a type.
Read an embedded file

And things that are less common that might be interesting:

Create an object using invoke/constructorinfo
Loading assemblies at runtime
Invoke a method (for example using invoke method)
etc.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 14, 2026 05:23
Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
Copilot AI changed the title [WIP] Add reflection detection rules for C# applications Add C# reflection detection rules Feb 14, 2026
Copilot AI requested a review from gfs February 14, 2026 05:29
@gfs
Copy link
Contributor

gfs commented Feb 14, 2026

@copilot can you please improve these new rules with must-match and must-not-match self tests in the json definitions?

Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 14, 2026

@copilot can you please improve these new rules with must-match and must-not-match self tests in the json definitions?

Added comprehensive must-match and must-not-match self-tests to all 8 reflection rules. Each rule now includes 3-4 positive test cases (code that should match) and 3-4 negative test cases (similar code that should not match). Commit: 31511d7

@gfs gfs marked this pull request as ready for review February 14, 2026 19:08
@gfs
Copy link
Contributor

gfs commented Feb 14, 2026

@copilot These changes dont even compile. D:\a\_work\1\s\AppInspector.Tests\RuleProcessor\ReflectionTests.cs(11,22): error CS0118: 'Languages' is a namespace but is used like a type [D:\a\_work\1\s\AppInspector.Tests\AppInspector.Tests.csproj::TargetFramework=net10.0] please be more careful and ensure any changes build and that tests run and pass.

@gfs gfs marked this pull request as draft February 14, 2026 19:31
…ully qualify Languages type

Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 14, 2026

@copilot These changes dont even compile. `D:\a_work\1\s\AppInspector.Tests\RuleProcessor\ReflectionTests.cs(11,22): error CS0118: 'Languages' is a namespace but is used like a type [D:\a_work\1\s\A...

Fixed the compilation error. The issue was a namespace conflict with Languages and a missing using statement for FileEntry. Both are now corrected to match the pattern used in other test files. Commit: 0677b44

@gfs gfs marked this pull request as ready for review February 14, 2026 19:49
@gfs
Copy link
Contributor

gfs commented Feb 14, 2026

@copilot the rule validation tests in particular do not pass. please fix rule validation errors.

…quirements

Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 14, 2026

@copilot the rule validation tests in particular do not pass. please fix rule validation errors.

Fixed rule validation errors. All enum values in reflection.json are now properly capitalized per schema requirements (Moderate, Regex/RegexWord, Code, High/Medium). Commit: 12ff371

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.

Reflection Detection

2 participants

Comments