File tree Expand file tree Collapse file tree 7 files changed +51
-2
lines changed 
Security Features/CWE-451 Expand file tree Collapse file tree 7 files changed +51
-2
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,17 @@ import csharp
1616import  semmle.code.asp.WebConfig
1717import  semmle.code.csharp.frameworks.system.Web
1818
19+ XmlElement  getAWebConfigRoot ( WebConfigXml  webConfig )  { 
20+   result  =  webConfig .getARootElement ( ) 
21+   or 
22+   result  =  webConfig .getARootElement ( ) .getAChild ( "location" )  and 
23+   ( 
24+     not  result .hasAttribute ( "path" )  // equivalent to path="." 
25+     or 
26+     result .getAttributeValue ( "path" )  =  [ "" ,  "." ] 
27+   ) 
28+ } 
29+ 
1930/** 
2031 * Holds if the `Web.config` file `webConfig` adds an `X-Frame-Options` header. 
2132 */ 
@@ -30,8 +41,8 @@ predicate hasWebConfigXFrameOptions(WebConfigXml webConfig) {
3041  //   </httpProtocol> 
3142  // </system.webServer> 
3243  // ``` 
33-   webConfig 
34-       . getARootElement ( ) 
44+   // This can also be in a `location` 
45+   getAWebConfigRoot ( webConfig ) 
3546      .getAChild ( "system.webServer" ) 
3647      .getAChild ( "httpProtocol" ) 
3748      .getAChild ( "customHeaders" ) 
Original file line number Diff line number Diff line change 1+ --- 
2+ category : minorAnalysis 
3+ --- 
4+ *  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 1+ using  System ; 
2+ using  System . Web ; 
3+ 
4+ public  class  AddXFrameOptions  :  IHttpHandler 
5+ { 
6+ 
7+     public  void  ProcessRequest ( HttpContext  ctx ) 
8+     { 
9+     } 
10+ 
11+     public  bool  IsReusable 
12+     { 
13+         get 
14+         { 
15+             return  true ; 
16+         } 
17+     } 
18+ } 
Original file line number Diff line number Diff line change 1+ Security Features/CWE-451/MissingXFrameOptions.ql
Original file line number Diff line number Diff line change 1+ <?xml  version =" 1.0"  encoding =" utf-8" 
2+ <configuration >
3+   <location  path =" ." inheritInChildApplications =" false" 
4+     <system .webServer>
5+       <httpProtocol >
6+         <customHeaders >
7+           <add  name =" X-Frame-Options" value =" SAMEORIGIN" 
8+         </customHeaders >
9+       </httpProtocol >
10+     </system .webServer>
11+   </location >
12+ </configuration >
Original file line number Diff line number Diff line change 1+ semmle-extractor-options: /nostdlib /noconfig
2+ semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../../resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj
3+ semmle-extractor-options: ${testdir}/../../../../../resources/stubs/System.Web.cs
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments