Skip to content

Commit e5fe540

Browse files
committed
Apply requested changes
1 parent 03b7c5e commit e5fe540

File tree

6 files changed

+48
-25
lines changed

6 files changed

+48
-25
lines changed

ruby/ql/lib/codeql/ruby/Frameworks.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ private import codeql.ruby.frameworks.Twirp
3434
private import codeql.ruby.frameworks.Sqlite3
3535
private import codeql.ruby.frameworks.Rexml
3636
private import codeql.ruby.frameworks.Nokogiri
37-
private import codeql.ruby.frameworks.Libxml
37+
private import codeql.ruby.frameworks.LibXml

ruby/ql/lib/codeql/ruby/frameworks/Libxml.qll

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ private import codeql.ruby.Concepts
99
/**
1010
* Provides modeling for `libxml`, an XML library for Ruby.
1111
*/
12-
module Libxml {
12+
module LibXml {
1313
/**
1414
* Flow summary for `libxml`. Wraps a string, parsing it as an XML document.
1515
*/
16-
private class XMLSummary extends SummarizedCallable {
17-
XMLSummary() { this = "LibXML::XML" }
16+
private class XmlSummary extends SummarizedCallable {
17+
XmlSummary() { this = "LibXML::XML" }
1818

1919
override MethodCall getACall() { result = any(LibXmlRubyXmlParserCall c).asExpr().getExpr() }
2020

@@ -24,15 +24,35 @@ module Libxml {
2424
}
2525

2626
/** A call that parses XML. */
27-
private class LibXmlRubyXmlParserCall extends DataFlow::CallNode {
28-
LibXmlRubyXmlParserCall() {
27+
abstract private class LibXmlRubyXmlParserCall extends XmlParserCall::Range, DataFlow::CallNode {
28+
}
29+
30+
private class LibXmlRubyXmlParserCallString extends LibXmlRubyXmlParserCall {
31+
LibXmlRubyXmlParserCallString() {
2932
this =
3033
[API::getTopLevelMember("LibXML").getMember("XML"), API::getTopLevelMember("XML")]
3134
.getMember(["Document", "Parser"])
32-
.getAMethodCall(["file", "io", "string"])
35+
.getAMethodCall(["string"])
3336
}
3437

35-
DataFlow::Node getInput() { result = this.getArgument(0) }
38+
override DataFlow::Node getInput() { result = this.getArgument(0) }
39+
40+
/** No option for parsing */
41+
override predicate externalEntitiesEnabled() { none() }
42+
}
43+
44+
private class LibXmlRubyXmlParserCallIoFile extends LibXmlRubyXmlParserCall {
45+
LibXmlRubyXmlParserCallIoFile() {
46+
this =
47+
[API::getTopLevelMember("LibXML").getMember("XML"), API::getTopLevelMember("XML")]
48+
.getMember(["Document", "Parser"])
49+
.getAMethodCall(["file", "io"])
50+
}
51+
52+
override DataFlow::Node getInput() { result = this.getArgument(0) }
53+
54+
/** No option for parsing */
55+
override predicate externalEntitiesEnabled() { none() }
3656
}
3757

3858
/** Execution of a XPath statement. */

ruby/ql/lib/codeql/ruby/frameworks/Nokogiri.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ module Nokogiri {
1313
/**
1414
* Flow summary for `nokogiri`. Wraps a string, parsing it as an XML document.
1515
*/
16-
private class XMLSummary extends SummarizedCallable {
17-
XMLSummary() { this = "Nokogiri::XML.parse" }
16+
private class XmlSummary extends SummarizedCallable {
17+
XmlSummary() { this = "Nokogiri::XML.parse" }
1818

1919
override MethodCall getACall() { result = any(NokogiriXmlParserCall p).asExpr().getExpr() }
2020

ruby/ql/lib/codeql/ruby/frameworks/Rexml.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ module Rexml {
1313
/**
1414
* Flow summary for `REXML::Document.new()`. This method wraps a string, parsing it as an XML document.
1515
*/
16-
private class XMLSummary extends SummarizedCallable {
17-
XMLSummary() { this = "REXML::Document.new()" }
16+
private class XmlSummary extends SummarizedCallable {
17+
XmlSummary() { this = "REXML::Document.new()" }
1818

1919
override MethodCall getACall() { result = any(RexmlParserCall c).asExpr().getExpr() }
2020

ruby/ql/lib/codeql/ruby/security/XpathInjectionQuery.qll

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ private import codeql.ruby.DataFlow
1010
private import codeql.ruby.TaintTracking
1111
import XpathInjectionCustomizations::XpathInjection
1212

13-
/**
14-
* A taint-tracking configuration for detecting "Xpath Injection" vulnerabilities.
15-
*/
16-
class Configuration extends TaintTracking::Configuration {
17-
Configuration() { this = "Xpath Injection" }
13+
/** Provides a taint-tracking configuration for detecting "Xpath Injection" vulnerabilities. */
14+
module XPathInjection {
15+
/**
16+
* A taint-tracking configuration for detecting "Xpath Injection" vulnerabilities.
17+
*/
18+
private module Config implements DataFlow::ConfigSig {
19+
predicate isSource(DataFlow::Node source) { source instanceof Source }
1820

19-
override predicate isSource(DataFlow::Node source) { source instanceof Source }
21+
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
2022

21-
override predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
23+
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
24+
}
2225

23-
override predicate isSanitizer(DataFlow::Node node) { node instanceof Sanitizer }
26+
import TaintTracking::Make<Config>
2427
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @name XPath query built from user-controlled sources
33
* @description Building a XPath query from user-controlled sources is vulnerable to insertion of
4-
* malicious Xpath code by the user.
4+
* malicious XPath code by the user.
55
* @kind path-problem
66
* @problem.severity error
77
* @security-severity 9.8
@@ -13,9 +13,9 @@
1313

1414
import codeql.ruby.DataFlow
1515
import codeql.ruby.security.XpathInjectionQuery
16-
import DataFlow::PathGraph
16+
import XPathInjection::PathGraph
1717

18-
from Configuration config, DataFlow::PathNode source, DataFlow::PathNode sink
19-
where config.hasFlowPath(source, sink)
18+
from XPathInjection::PathNode source, XPathInjection::PathNode sink
19+
where XPathInjection::hasFlowPath(source, sink)
2020
select sink.getNode(), source, sink, "XPath expression depends on a $@.", source.getNode(),
21-
"user-provided value"
21+
"user-provided value"

0 commit comments

Comments
 (0)