-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Csharp: fix cs/web/missing-x-frame-options to also consider location elements
#20658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Csharp: fix cs/web/missing-x-frame-options to also consider location elements
#20658
Conversation
…on` elements As explained in https://learn.microsoft.com/en-us/previous-versions/aspnet/ms178692(v=vs.100), it is possible to add `system.webServer` elements nested inside `location` elements in `Web.config`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Fixes the C# security query for missing X-Frame-Options headers to properly detect when these headers are configured within location elements in Web.config files, as supported by ASP.NET.
- Updated the query logic to check for X-Frame-Options headers in both direct
system.webServerelements and those nested insidelocationelements - Added comprehensive test coverage for the new
locationelement scenario
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
MissingXFrameOptions.ql |
Updated query logic to support detection of X-Frame-Options headers within location elements |
Web.config |
Test configuration demonstrating X-Frame-Options header configured within a location element |
MissingXFrameOptions.cs |
Test C# code with HTTP handler for testing the security query |
MissingXFrameOptions.qlref |
Query reference file for the test case |
options |
Test configuration options for the CodeQL extractor |
cs/web/missing-x-frame-options to also consider `locati…cs/web/missing-x-frame-options to also consider location elements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for doing this!
Maybe we should also run DCA before merging.
csharp/ql/src/Security Features/CWE-451/MissingXFrameOptions.ql
Outdated
Show resolved
Hide resolved
4c0391e to
316225b
Compare
csharp/ql/src/change-notes/2025-10-17-location-in-web-config.md
Outdated
Show resolved
Hide resolved
| import semmle.code.asp.WebConfig | ||
| import semmle.code.csharp.frameworks.system.Web | ||
|
|
||
| XmlElement getAWebConfigRoot(WebConfigXml webConfig) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! LGTM!
As explained in
https://learn.microsoft.com/en-us/previous-versions/aspnet/ms178692(v=vs.100),
it is possible to add
system.webServerelements nested insidelocationelements inWeb.config.