Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions csharp/ql/src/Security Features/CWE-451/MissingXFrameOptions.ql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ import csharp
import semmle.code.asp.WebConfig
import semmle.code.csharp.frameworks.system.Web

XmlElement getAWebConfigRoot(WebConfigXml webConfig) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

result = webConfig.getARootElement()
or
result = webConfig.getARootElement().getAChild("location") and
(
not result.hasAttribute("path") // equivalent to path="."
or
result.getAttributeValue("path") = ["", "."]
)
}

/**
* Holds if the `Web.config` file `webConfig` adds an `X-Frame-Options` header.
*/
Expand All @@ -30,8 +41,8 @@ predicate hasWebConfigXFrameOptions(WebConfigXml webConfig) {
// </httpProtocol>
// </system.webServer>
// ```
webConfig
.getARootElement()
// This can also be in a `location`
getAWebConfigRoot(webConfig)
.getAChild("system.webServer")
.getAChild("httpProtocol")
.getAChild("customHeaders")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* the `cs/web/missing-x-frame-options` query now correctly handles configuration nested in root `<location>` elements.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Web;

public class AddXFrameOptions : IHttpHandler
{

public void ProcessRequest(HttpContext ctx)
{
}

public bool IsReusable
{
get
{
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Security Features/CWE-451/MissingXFrameOptions.ql

Check warning

Code scanning / CodeQL

Query test without inline test expectations Warning test

Query test does not use inline test expectations.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-Frame-Options" value="SAMEORIGIN" />
</customHeaders>
</httpProtocol>
</system.webServer>
</location>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
semmle-extractor-options: /nostdlib /noconfig
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../../resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj
semmle-extractor-options: ${testdir}/../../../../../resources/stubs/System.Web.cs