Anchor .config regex to prevent matching .config.json files - #721
Merged
Merged
Conversation
Updated applies_to_file_regex from ".*\\.config" to ".*\\.config$" in three rules (DS450001, DS450002, DS450003) to prevent matching files like "file.test.config.json". Added test to verify .config.json files are not incorrectly parsed as XML. Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix JSON file parsing error in DevSkim CLI
Anchor .config regex to prevent matching .config.json files
Feb 4, 2026
Giulia Stocco (gfs)
requested changes
Feb 4, 2026
Replaced test to directly validate that .config xpath rules apply to .config files but not to .config.json files. The improved test uses XML content that would trigger the rules if the filename matching were incorrect, making it a more robust validation of the fix. Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
Added assertions to verify that analyze commands complete successfully with ExitCode.Okay for both .config and .config.json test cases, ensuring proper error handling validation. Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
Contributor
|
/azp run |
Giulia Stocco (gfs)
approved these changes
Feb 5, 2026
|
Azure Pipelines successfully started running 2 pipeline(s). |
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes an issue where DevSkim CLI incorrectly attempted to parse JSON files containing .config in their filename (e.g., file.test.config.json) as XML files, resulting in parsing errors.
Changes:
- Fixed overly broad regex patterns in three .NET Framework security rules (DS450001, DS450002, DS450003)
- Changed regex from
.*\\.configto.*\\.config$to match only files ending with.config - Added comprehensive test to validate the fix works for both
.configand.config.jsonfiles
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| rules/default/security/frameworks/dotnet_framework.json | Anchored regex patterns with $ for rules DS450001, DS450002, and DS450003 to prevent matching files that merely contain .config in their name |
| DevSkim-DotNet/Microsoft.DevSkim.Tests/AnalyzeTest.cs | Added test validating that xpath rules apply to .config files but not to .config.json files |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
Copilot update branch with main and add appropriate entry to changelog |
…lot/fix-json-file-parsing
- Merged latest changes from main branch - Added changelog entry documenting the .config regex fix Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
Contributor
Author
Contributor
|
Copilot follow the copilot instructions and properly number the change in the changelog. |
Changed from [Unreleased] to [1.0.74] following semantic versioning Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
Contributor
Author
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
Giulia Stocco (gfs)
marked this pull request as ready for review
February 5, 2026 22:54
| .Where(r => r.RuleId == "DS450001" || r.RuleId == "DS450002" || r.RuleId == "DS450003"); | ||
| Assert.IsTrue(configRuleMatches.Any(), "Config xpath rules should match .config files"); | ||
|
|
||
| // Test 2: Verify the rule does NOT apply to .config.json files (even with XML-like content) |
Contributor
There was a problem hiding this comment.
100% nit that shouldn't hold up the merge, but this should be two separate tests methods.
Dan Fiedler (danfiedler-msft)
approved these changes
Feb 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix .config file regex to prevent matching JSON files
file.test.config.json) are being matched by overly broad regexdotnet_framework.json.*\\.configto.*\\.config$to match only files ending with .configChanges Made:
rules/default/security/frameworks/dotnet_framework.json:.*\\.configto.*\\.config$for rules DS450001, DS450002, DS450003.configare matched by xpath rulesTestConfigXPathRulesApplyOnlyToConfigFilesinAnalyzeTest.csthat:.configfiles with problematic patterns.config.jsonfiles even with same contentChangelog.mdwith version 1.0.74 entryVerification:
.config.jsonfiles no longer trigger XML parsing errors.configfiles still correctly trigger xpath rulesOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.