";let n=document.getElementById("TableOfContents");n&&(n.innerHTML=e)}rerender(){this.renderFilterMenu(),this.renderPageContent(),this.populateRightNav(),this.runHooks("afterRerender")}renderPageContent(){let e={};Object.keys(this.ifFunctionsByRef).forEach(t=>{let s=this.ifFunctionsByRef[t],o=s.value,n=(0,h.reresolveFunctionNode)(s,{variables:this.selectedValsByTraitId});this.ifFunctionsByRef[t]=n,o!==n.value&&(e[t]=n.value)});let t=document.getElementsByClassName("cdoc__toggleable");for(let n=0;n{this.fitCustomizationMenuToScreen()})}addDropdownEventListeners(){let e=document.getElementsByClassName("cdoc-dropdown");for(let t=0;t{let t=e.target;for(;!t.classList.contains("cdoc-dropdown")&&t.parentElement;)t=t.parentElement;let n=t.classList.toggle("cdoc-dropdown__expanded");t.setAttribute("aria-expanded",n.toString())});document.addEventListener("keydown",e=>{if(e.key==="Enter"){let t=e.target;t.classList.contains("cdoc-filter__option")&&t.click()}}),document.addEventListener("click",t=>{for(let n=0;nthis.handleFilterSelectionChange(e));this.addDropdownEventListeners()}locateFilterSelectorEl(){let e=document.getElementById("cdoc-selector");return!!e&&(this.filterSelectorEl=e,!0)}applyFilterSelectionOverrides(){let s=Object.keys(this.selectedValsByTraitId),e=!1,t=this.browserStorage.getTraitVals();Object.keys(t).forEach(n=>{s.includes(n)&&this.selectedValsByTraitId[n]!==t[n]&&(this.selectedValsByTraitId[n]=t[n],e=!0)});let n=(0,j.getTraitValsFromUrl)({url:new URL(window.location.href),traitIds:s});return Object.keys(n).forEach(t=>{this.selectedValsByTraitId[t]!==n[t]&&(this.selectedValsByTraitId[t]=n[t],e=!0)}),e}updateEditButton(){let t=document.getElementsByClassName("toc-edit-btn")[0];if(!t)return;let e=t.getElementsByTagName("a")[0];e&&(e.href=e.href.replace(/\.md\/$/,".mdoc.md/"))}revealPage(){this.runHooks("beforeReveal"),this.filterSelectorEl&&(this.filterSelectorEl.style.position="sticky",this.filterSelectorEl.style.backgroundColor="white",this.filterSelectorEl.style.paddingTop="10px",this.filterSelectorEl.style.visibility="visible",this.filterSelectorEl.style.zIndex="1000");let e=document.getElementById("cdoc-content");e&&(e.style.visibility="visible"),this.runHooks("afterReveal")}renderFilterMenu(){if(!this.filterSelectorEl||!this.filtersManifest)throw new Error("Cannot render filter selector without filtersManifest and filterSelectorEl");let e=(0,l.resolveFilters)({filtersManifest:this.filtersManifest,valsByTraitId:this.selectedValsByTraitId});Object.keys(e).forEach(t=>{let n=e[t];this.selectedValsByTraitId[t]=n.currentValue});let t=(0,y.buildCustomizationMenuUi)(e);this.filterSelectorEl.innerHTML=t,this.fitCustomizationMenuToScreen(),this.addFilterSelectorEventListeners()}fitCustomizationMenuToScreen(){let e=document.getElementById(g);if(!e)return;let s=e.classList.contains(n),t=document.getElementById(v);if(!t)throw new Error("Dropdown menu not found");let o=document.getElementById(b);if(!o)throw new Error("Menu wrapper not found");let i=e.scrollWidth>o.clientWidth;!s&&i?(e.classList.add(n),t.classList.remove(n)):s&&!i&&(e.classList.remove(n),t.classList.add(n))}get cdocsState(){return{selectedValsByTraitId:this.selectedValsByTraitId,ifFunctionsByRef:this.ifFunctionsByRef,filtersManifest:this.filtersManifest,browserStorage:this.browserStorage,filterSelectorEl:this.filterSelectorEl}}};e.ClientFiltersManager=r,t=r,s={value:0[0]}}),y=e(e=>{Object.defineProperty(e,"__esModule",{value:!0});var t=j();window.clientFiltersManager=t.ClientFiltersManager.instance}),y()})()Detect an XPath input from an HTTP request
This rule is designed to detect and prevent potential XPath Injection vulnerabilities in your C# code. XPath Injection is a type of attack where an attacker can manipulate the structure of an XPath query by injecting malicious input. This can lead to unauthorized data access or manipulation in XML databases or documents.
The importance of this rule lies in its ability to safeguard sensitive data and uphold the integrity of your application. If an attacker can control the structure of an XPath query, they could potentially access or manipulate data they should not have access to. This could lead to data breaches or unauthorized changes to your data.
How to remediate
Avoid constructing XPath queries using string concatenation with user-controlled data. Instead, consider safer alternatives, such as parameterized XPath queries or validating user input before including it in an XPath query. For example, you could use regular expressions to ensure the user input only contains characters you expect. If user input must be included in an XPath query, it should be properly escaped or encoded to prevent the input from being interpreted as XPath syntax.
Non-Compliant Code Examples
// test_noncompliant_xpath.csusingSystem;usingSystem.Xml;usingMicrosoft.AspNetCore.Mvc;// For contextpublicclassVulnerableXPathController:Controller{// Noncompliant: Parameters concatenated directly [HttpGet]publicIActionResultAuthenticate(stringuser,stringpass){XmlDocumentdoc=newXmlDocument();// Assume doc is loaded with some XML data here...// doc.Load("users.xml");// Vulnerable concatenationStringexpression="/users/user[@name='"+user+"' and @pass='"+pass+"']";// Method call using the concatenated stringXmlNodeuserNode=doc.SelectSingleNode(expression);// Violation should be reported herereturnJson(userNode!=null);}// Noncompliant: Only one parameter concatenated [HttpGet]publicIActionResultFindUser(stringusername){XmlDocumentdoc=newXmlDocument();// Assume doc is loaded...stringquery="//user[@id='"+username+"']/data";// VulnerableXmlNodeListnodes=doc.SelectNodes(query);// Violation should be reported here// Process nodes...returnOk();}// Noncompliant: Concatenation inside the method call [HttpGet]publicIActionResultFindUserDirect(stringuid){XmlDocumentdoc=newXmlDocument();// Assume doc is loaded...varnode=doc.SelectSingleNode("/items/item[@uid='"+uid+"']");// Violation herereturnJson(node!=null);}}
Compliant Code Examples
// test_compliant_xpath.csusingSystem;usingSystem.Xml;usingMicrosoft.AspNetCore.Mvc;// For contextusingSystem.Text.RegularExpressions;// For validation examplepublicclassSafeXPathController:Controller{// Compliant: Hardcoded XPath query [HttpGet]publicIActionResultGetAdmins(){XmlDocumentdoc=newXmlDocument();// Assume doc is loaded...// Safe: Query is constantStringexpression="/users/user[@role='admin']";XmlNodeListadminNodes=doc.SelectNodes(expression);// OK// Process nodes...returnOk();}}
원활한 통합. Datadog Code Security를 경험해 보세요
Datadog Code Security
이 규칙을 사용해 Datadog Code Security로 코드를 분석하세요
규칙 사용 방법
1
2
rulesets:- csharp-security # Rules to enforce C# security.
리포지토리 루트에 위의 내용을 포함하는 static-analysis.datadog.yml을 만듭니다
무료 IDE 플러그인을 사용하거나 CI 파이프라인에 Code Security 검사를 추가합니다