Skip to content

Commit 9f88a72

Browse files
committed
C#: Make cs/web/debug-binary respect transformation file RemoveAttribute.
1 parent c68c83c commit 9f88a72

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

csharp/ql/lib/semmle/code/asp/WebConfig.qll

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ class WebConfigXml extends XmlFile {
1111
WebConfigXml() { this.getName().matches("%Web.config") }
1212
}
1313

14+
/**
15+
* A `Web.config` transformation file.
16+
*/
17+
class WebConfigReleaseTransformXml extends XmlFile {
18+
WebConfigReleaseTransformXml() { this.getName().matches("%Web.Release.config") }
19+
}
20+
1421
/** DEPRECATED: Alias for WebConfigXml */
1522
deprecated class WebConfigXML = WebConfigXml;
1623

@@ -19,6 +26,11 @@ class ConfigurationXmlElement extends XmlElement {
1926
ConfigurationXmlElement() { this.getName().toLowerCase() = "configuration" }
2027
}
2128

29+
/** A `<compilation>` tag in an ASP.NET configuration file. */
30+
class CompilationXmlElement extends XmlElement {
31+
CompilationXmlElement() { this.getName().toLowerCase() = "compilation" }
32+
}
33+
2234
/** DEPRECATED: Alias for ConfigurationXmlElement */
2335
deprecated class ConfigurationXMLElement = ConfigurationXmlElement;
2436

@@ -149,3 +161,15 @@ class HttpCookiesElement extends XmlElement {
149161
/** DEPRECATED: Alias for isRequireSsl */
150162
deprecated predicate isRequireSSL() { this.isRequireSsl() }
151163
}
164+
165+
/** A `Transform` attribute in a Web.config transformation file. */
166+
class TransformXmlAttribute extends XmlAttribute {
167+
TransformXmlAttribute() { this.getName().toLowerCase() = "transform" }
168+
169+
/**
170+
* Gets the list of attribute removals in `Transform=RemoveAttributes(list)`.
171+
*/
172+
string getRemoveAttributes() {
173+
result = this.getValue().regexpCapture("RemoveAttributes\\((.*)\\)", 1).splitAt(",")
174+
}
175+
}

csharp/ql/src/Security Features/CWE-011/ASPNetDebug.ql

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ import semmle.code.asp.WebConfig
1919

2020
from SystemWebXmlElement web, XmlAttribute debugAttribute
2121
where
22-
debugAttribute = web.getAChild("compilation").getAttribute("debug") and
23-
not debugAttribute.getValue().toLowerCase() = "false"
22+
exists(CompilationXmlElement compilation | compilation.getParent() = web |
23+
debugAttribute = compilation.getAttribute("debug") and
24+
not debugAttribute.getValue().toLowerCase() = "false"
25+
) and
26+
not exists(
27+
TransformXmlAttribute attribute, CompilationXmlElement compilation,
28+
WebConfigReleaseTransformXml file
29+
|
30+
compilation = attribute.getElement() and
31+
file = compilation.getFile() and
32+
attribute.getRemoveAttributes() = "debug" and
33+
file.getParentContainer() = web.getFile().getParentContainer()
34+
)
2435
select debugAttribute, "The 'debug' flag is set for an ASP.NET configuration file."

0 commit comments

Comments
 (0)