mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Merge pull request #20658 from github/redsun82/csharp-fix-xframe-options-in-location
Csharp: fix `cs/web/missing-x-frame-options` to also consider `location` elements
This commit is contained in:
@@ -16,6 +16,17 @@ import csharp
|
||||
import semmle.code.asp.WebConfig
|
||||
import semmle.code.csharp.frameworks.system.Web
|
||||
|
||||
XmlElement getAWebConfigRoot(WebConfigXml webConfig) {
|
||||
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.
|
||||
*/
|
||||
@@ -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")
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
* the `cs/web/missing-x-frame-options` query now correctly handles configuration nested in root `<location>` elements.
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
|
||||
public class AddXFrameOptions : IHttpHandler
|
||||
{
|
||||
|
||||
public void ProcessRequest(HttpContext ctx)
|
||||
{
|
||||
}
|
||||
|
||||
public bool IsReusable
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Security Features/CWE-451/MissingXFrameOptions.ql
|
||||
@@ -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>
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user