diff --git a/change-notes/1.24/analysis-go.md b/change-notes/1.24/analysis-go.md index 2212c4d2e39..9b1c033d18d 100644 --- a/change-notes/1.24/analysis-go.md +++ b/change-notes/1.24/analysis-go.md @@ -19,6 +19,7 @@ The CodeQL library for Go now contains a folder of simple "cookbook" queries tha | Incomplete URL scheme check (`go/incomplete-url-scheme-check`) | correctness, security, external/cwe/cwe-020 | Highlights checks for `javascript` URLs that do not take `data` or `vbscript` URLs into account. Results are shown on LGTM by default. | | Potentially unsafe quoting (`go/unsafe-quoting`) | correctness, security, external/cwe/cwe-078, external/cwe/cwe-089, external/cwe/cwe-094 | Highlights code that constructs a quoted string literal containing data that may itself contain quotes. Results are shown on LGTM by default. | | Size computation for allocation may overflow (`go/allocation-size-overflow`) | correctness, security, external/cwe/cwe-190 | Highlights code that computes the size of an allocation based on the size of a potentially large object. Results are shown on LGTM by default. | +| XPath injection (`go/xml/xpath-injection`) | security, external/cwe/cwe-643 | Highlights code that uses remote input in an XPath expression. Results are shown on LGTM by default. | ## Changes to existing queries diff --git a/ql/src/experimental/Security/CWE-643/XPathInjection.go b/ql/src/Security/CWE-643/XPathInjection.go similarity index 73% rename from ql/src/experimental/Security/CWE-643/XPathInjection.go rename to ql/src/Security/CWE-643/XPathInjection.go index 869c98acb89..2758de5be25 100644 --- a/ql/src/experimental/Security/CWE-643/XPathInjection.go +++ b/ql/src/Security/CWE-643/XPathInjection.go @@ -13,20 +13,18 @@ func main() {} func processRequest(r *http.Request, doc tree.Node) { r.ParseForm() username := r.Form.Get("username") - password := r.Form.Get("password") // BAD: User input used directly in an XPath expression - xPath := goxpath.MustParse("//users/user[login/text()='" + username + "' and password/text() = '" + password + "']/home_dir/text()") + xPath := goxpath.MustParse("//users/user[login/text()='" + username + "']/home_dir/text()") unsafeRes, _ := xPath.ExecBool(doc) fmt.Println(unsafeRes) // GOOD: Value of parameters is defined here instead of directly in the query opt := func(o *goxpath.Opts) { o.Vars["username"] = tree.String(username) - o.Vars["password"] = tree.String(password) } // GOOD: Uses parameters to avoid including user input directly in XPath expression - xPath = goxpath.MustParse("//users/user[login/text()=$username and password/text() = $password]/home_dir/text()") + xPath = goxpath.MustParse("//users/user[login/text()=$username]/home_dir/text()") safeRes, _ := xPath.ExecBool(doc, opt) fmt.Println(safeRes) } diff --git a/ql/src/experimental/Security/CWE-643/XPathInjection.qhelp b/ql/src/Security/CWE-643/XPathInjection.qhelp similarity index 86% rename from ql/src/experimental/Security/CWE-643/XPathInjection.qhelp rename to ql/src/Security/CWE-643/XPathInjection.qhelp index 23d693ac704..4c1d376202e 100644 --- a/ql/src/experimental/Security/CWE-643/XPathInjection.qhelp +++ b/ql/src/Security/CWE-643/XPathInjection.qhelp @@ -15,16 +15,16 @@ If user input must be included in an XPath expression, pre-compile the query and references to include the user input.

-For example, when using the github.com/ChrisTrenkamp/goxpath API, this can be done by creating a function that takes an *goxpath.Opts structure. +For example, when using the github.com/ChrisTrenkamp/goxpath API, you can do this by creating a function that takes an *goxpath.Opts structure. In this structure you can then set the values of the variable references. -This function can then be specified when calling Exec(), Exec{Bool|Num|Node}(), ParseExec() or MustExec(). +This function can then be specified when calling Exec(), Exec{Bool|Num|Node}(), ParseExec(), or MustExec().

-In the first example, the code accepts a user name specified by the user, and uses this +In the first example, the code accepts a username specified by the user, and uses this unvalidated and unsanitized value in an XPath expression. This is vulnerable to the user providing special characters or string sequences that change the meaning of the XPath expression to search for different values. diff --git a/ql/src/Security/CWE-643/XPathInjection.ql b/ql/src/Security/CWE-643/XPathInjection.ql new file mode 100644 index 00000000000..ca6df0ff004 --- /dev/null +++ b/ql/src/Security/CWE-643/XPathInjection.ql @@ -0,0 +1,27 @@ +/** + * @name XPath injection + * @description Building an XPath expression from user-controlled sources is vulnerable to insertion of + * malicious code by the user. + * @kind path-problem + * @problem.severity error + * @precision high + * @id go/xml/xpath-injection + * @tags security + * external/cwe/cwe-643 + */ + +import go +import semmle.go.security.XPathInjection::XPathInjection +import DataFlow::PathGraph + +/** Holds if `node` is either a string or a byte slice */ +predicate isStringOrByte(DataFlow::PathNode node) { + exists(Type t | t = node.getNode().getType().getUnderlyingType() | + t instanceof StringType or t instanceof ByteSliceType + ) +} + +from Configuration config, DataFlow::PathNode source, DataFlow::PathNode sink +where config.hasFlowPath(source, sink) and isStringOrByte(sink) +select sink.getNode(), source, sink, "$@ flows here and is used in an XPath expression.", + source.getNode(), "A user-provided value" diff --git a/ql/src/experimental/Security/CWE-643/XPathInjection.ql b/ql/src/experimental/Security/CWE-643/XPathInjection.ql deleted file mode 100644 index 453710d71e0..00000000000 --- a/ql/src/experimental/Security/CWE-643/XPathInjection.ql +++ /dev/null @@ -1,188 +0,0 @@ -/** - * @name XPath injection - * @description Building an XPath expression from user-controlled sources is vulnerable to insertion of - * malicious code by the user. - * @kind path-problem - * @problem.severity error - * @id go/xml/xpath-injection - * @tags security - * external/cwe/cwe-643 - */ - -import go -import DataFlow::PathGraph - -class ByteSliceType extends SliceType { - ByteSliceType() { this.getElementType() instanceof Uint8Type } -} - -class XPathInjectionConfiguration extends TaintTracking::Configuration { - XPathInjectionConfiguration() { this = "XPathInjectionConfiguration" } - - override predicate isSource(DataFlow::Node source) { source instanceof UntrustedFlowSource } - - override predicate isSink(DataFlow::Node sink) { sink instanceof XPathInjectionSink } - - override predicate isSanitizer(DataFlow::Node node) { - exists(Type t | t = node.getType().getUnderlyingType() | - not t instanceof StringType or not t instanceof ByteSliceType - ) - } -} - -abstract class XPathInjectionSink extends DataFlow::Node { } - -// https://github.com/antchfx/xpath -class XPathSink extends XPathInjectionSink { - XPathSink() { - exists(Function f, string name | name.matches("Compile%") | - f.hasQualifiedName("github.com/antchfx/xpath", name) and - this = f.getACall().getArgument(0) - ) - or - exists(Function f, string name | name.matches("MustCompile%") | - f.hasQualifiedName("github.com/antchfx/xpath", name) and - this = f.getACall().getArgument(0) - ) - or - exists(Function f, string name | name.matches("Select%") | - f.hasQualifiedName("github.com/antchfx/xpath", name) and - this = f.getACall().getArgument(1) - ) - } -} - -// https://github.com/antchfx/htmlquery -class HtmlQuerySink extends XPathInjectionSink { - HtmlQuerySink() { - exists(Function f, string name | name.matches("Find%") | - f.hasQualifiedName("github.com/antchfx/htmlquery", name) and - this = f.getACall().getArgument(1) - ) - or - exists(Function f, string name | name.matches("Query%") | - f.hasQualifiedName("github.com/antchfx/htmlquery", name) and - this = f.getACall().getArgument(1) - ) - or - exists(Function f | - f.hasQualifiedName("github.com/antchfx/htmlquery", "getQuery") and - this = f.getACall().getArgument(0) - ) - } -} - -// https://github.com/antchfx/xmlquery -class XmlQuerySink extends XPathInjectionSink { - XmlQuerySink() { - exists(Function f, string name | name.matches("Find%") | - f.hasQualifiedName("github.com/antchfx/xmlquery", name) and - this = f.getACall().getArgument(1) - ) - or - exists(Function f, string name | name.matches("Query%") | - f.hasQualifiedName("github.com/antchfx/xmlquery", name) and - this = f.getACall().getArgument(1) - ) - or - exists(Function f, string name | name.matches("Select%") | - f.hasQualifiedName("github.com/antchfx/xmlquery", name) and - this = f.getACall().getArgument(0) - ) - or - exists(Function f | - f.hasQualifiedName("github.com/antchfx/xmlquery", "getQuery") and - this = f.getACall().getArgument(0) - ) - } -} - -// https://github.com/antchfx/jsonquery -class JsonQuerySink extends XPathInjectionSink { - JsonQuerySink() { - exists(Function f, string name | name.matches("Find%") | - f.hasQualifiedName("github.com/antchfx/jsonquery", name) and - this = f.getACall().getArgument(1) - ) - or - exists(Function f, string name | name.matches("Query%") | - f.hasQualifiedName("github.com/antchfx/jsonquery", name) and - this = f.getACall().getArgument(1) - ) - or - exists(Function f | - f.hasQualifiedName("github.com/antchfx/jsonquery", "getQuery") and - this = f.getACall().getArgument(0) - ) - } -} - -// https://github.com/go-xmlpath/xmlpath -class XmlPathSink extends XPathInjectionSink { - XmlPathSink() { - exists(Function f, string name | name.matches("Compile%") | - f.hasQualifiedName("github.com/go-xmlpath/xmlpath", name) and - this = f.getACall().getArgument(0) - ) - or - exists(Function f, string name | name.matches("MustCompile%") | - f.hasQualifiedName("github.com/go-xmlpath/xmlpath", name) and - this = f.getACall().getArgument(0) - ) - } -} - -// https://github.com/ChrisTrenkamp/goxpath -class GoXPathSink extends XPathInjectionSink { - GoXPathSink() { - exists(Function f, string name | name.matches("Parse%") | - f.hasQualifiedName("github.com/ChrisTrenkamp/goxpath", name) and - this = f.getACall().getArgument(0) - ) - or - exists(Function f, string name | name.matches("MustParse%") | - f.hasQualifiedName("github.com/ChrisTrenkamp/goxpath", name) and - this = f.getACall().getArgument(0) - ) - } -} - -// https://github.com/santhosh-tekuri/xpathparser -class XPathParserSink extends XPathInjectionSink { - XPathParserSink() { - exists(Function f, string name | name.matches("Parse%") | - f.hasQualifiedName("github.com/santhosh-tekuri/xpathparser", name) and - this = f.getACall().getArgument(0) - ) - or - exists(Function f, string name | name.matches("MustParse%") | - f.hasQualifiedName("github.com/santhosh-tekuri/xpathparser", name) and - this = f.getACall().getArgument(0) - ) - } -} - -// https://github.com/moovweb/gokogiri -class GokogiriSink extends XPathInjectionSink { - GokogiriSink() { - exists(Function f, string name | name.matches("Compile%") | - f.hasQualifiedName("github.com/moovweb/gokogiri/xpath", name) and - this = f.getACall().getArgument(0) - ) - or - exists(Function f, string name | name.matches("Search%") | - f.hasQualifiedName("github.com/moovweb/gokogiri/xml", name) and - this = f.getACall().getArgument(0) - ) - or - exists(Function f, string name | name.matches("EvalXPath%") | - f.hasQualifiedName("github.com/moovweb/gokogiri/xml", name) and - this = f.getACall().getArgument(0) - ) - } -} - -from DataFlow::PathNode source, DataFlow::PathNode sink, XPathInjectionConfiguration c -where c.hasFlowPath(source, sink) -select sink.getNode(), source, sink, "$@ flows here and is used in an XPath expression.", - source.getNode(), "A user-provided value" diff --git a/ql/src/go.qll b/ql/src/go.qll index dfdd54726cf..c176857a282 100644 --- a/ql/src/go.qll +++ b/ql/src/go.qll @@ -26,6 +26,7 @@ import semmle.go.dataflow.SSA import semmle.go.frameworks.HTTP import semmle.go.frameworks.SystemCommandExecutors import semmle.go.frameworks.SQL +import semmle.go.frameworks.XPath import semmle.go.frameworks.Stdlib import semmle.go.security.FlowSources import semmle.go.Util diff --git a/ql/src/semmle/go/Types.qll b/ql/src/semmle/go/Types.qll index ad87b688fea..c68df092675 100644 --- a/ql/src/semmle/go/Types.qll +++ b/ql/src/semmle/go/Types.qll @@ -328,6 +328,11 @@ class SliceType extends @slicetype, CompositeType { override string toString() { result = "slice type" } } +/** A byte slice type */ +class ByteSliceType extends SliceType { + ByteSliceType() { this.getElementType() instanceof Uint8Type } +} + /** A struct type. */ class StructType extends @structtype, CompositeType { /** diff --git a/ql/src/semmle/go/frameworks/XPath.qll b/ql/src/semmle/go/frameworks/XPath.qll new file mode 100644 index 00000000000..932d0b04cd5 --- /dev/null +++ b/ql/src/semmle/go/frameworks/XPath.qll @@ -0,0 +1,153 @@ +/** + * Provides classes for working with XPath-related concepts such as XPath expressions. + */ + +import go + +/** Provides classes for working with XPath-related APIs. */ +module XPath { + /** Provides classes for working with XPath expression strings. */ + module XPathExpressionString { + /** + * A data-flow node whose string value is interpreted as (part of) an XPath expression. + * + * Extend this class to model new APIs. + */ + abstract class Range extends DataFlow::Node { } + + /** An XPath expression string used in an API function of the https://github.com/antchfx/xpath package. */ + private class AntchfxXpathXPathExpressionString extends Range { + AntchfxXpathXPathExpressionString() { + exists(Function f, string name | name.matches("Compile%") | + f.hasQualifiedName("github.com/antchfx/xpath", name) and + this = f.getACall().getArgument(0) + ) + or + exists(Function f, string name | name.matches("MustCompile%") | + f.hasQualifiedName("github.com/antchfx/xpath", name) and + this = f.getACall().getArgument(0) + ) + or + exists(Function f, string name | name.matches("Select%") | + f.hasQualifiedName("github.com/antchfx/xpath", name) and + this = f.getACall().getArgument(1) + ) + } + } + + /** An XPath expression string used in an API function of the https://github.com/antchfx/htmlquery package. */ + private class AntchfxHtmlqueryXPathExpressionString extends Range { + AntchfxHtmlqueryXPathExpressionString() { + exists(Function f, string name | name.matches("Find%") | + f.hasQualifiedName("github.com/antchfx/htmlquery", name) and + this = f.getACall().getArgument(1) + ) + or + exists(Function f, string name | name.matches("Query%") | + f.hasQualifiedName("github.com/antchfx/htmlquery", name) and + this = f.getACall().getArgument(1) + ) + } + } + + /** An XPath expression string used in an API function of the https://github.com/antchfx/xmlquery package. */ + private class AntchfxXmlqueryXPathExpressionString extends Range { + AntchfxXmlqueryXPathExpressionString() { + exists(Function f, string name | name.matches("Find%") | + f.hasQualifiedName("github.com/antchfx/xmlquery", name) and + this = f.getACall().getArgument(1) + ) + or + exists(Function f, string name | name.matches("Query%") | + f.hasQualifiedName("github.com/antchfx/xmlquery", name) and + this = f.getACall().getArgument(1) + ) + or + exists(Method m, string name | name.matches("Select%") | + m.hasQualifiedName("github.com/antchfx/xmlquery", "Node", name) and + this = m.getACall().getArgument(0) + ) + } + } + + /** An XPath expression string used in an API function of the https://github.com/antchfx/jsonquery package. */ + private class AntchfxJsonqueryXPathExpressionString extends Range { + AntchfxJsonqueryXPathExpressionString() { + exists(Function f, string name | name.matches("Find%") | + f.hasQualifiedName("github.com/antchfx/jsonquery", name) and + this = f.getACall().getArgument(1) + ) + or + exists(Function f, string name | name.matches("Query%") | + f.hasQualifiedName("github.com/antchfx/jsonquery", name) and + this = f.getACall().getArgument(1) + ) + } + } + + /** An XPath expression string used in an API function of the https://github.com/go-xmlpath/xmlpath package. */ + private class GoXmlpathXmlpathXPathExpressionString extends Range { + GoXmlpathXmlpathXPathExpressionString() { + exists(Function f, string name | name.matches("Compile%") | + f.hasQualifiedName("github.com/go-xmlpath/xmlpath", name) and + this = f.getACall().getArgument(0) + ) + or + exists(Function f, string name | name.matches("MustCompile%") | + f.hasQualifiedName("github.com/go-xmlpath/xmlpath", name) and + this = f.getACall().getArgument(0) + ) + } + } + + /** An XPath expression string used in an API function of the https://github.com/ChrisTrenkamp/goxpath package. */ + private class ChrisTrenkampGoxpathXPathExpressionString extends Range { + ChrisTrenkampGoxpathXPathExpressionString() { + exists(Function f, string name | name.matches("Parse%") | + f.hasQualifiedName("github.com/ChrisTrenkamp/goxpath", name) and + this = f.getACall().getArgument(0) + ) + or + exists(Function f, string name | name.matches("MustParse%") | + f.hasQualifiedName("github.com/ChrisTrenkamp/goxpath", name) and + this = f.getACall().getArgument(0) + ) + } + } + + /** An XPath expression string used in an API function of the https://github.com/santhosh-tekuri/xpathparser package. */ + private class SanthoshTekuriXpathparserXPathExpressionString extends Range { + SanthoshTekuriXpathparserXPathExpressionString() { + exists(Function f, string name | name.matches("Parse%") | + f.hasQualifiedName("github.com/santhosh-tekuri/xpathparser", name) and + this = f.getACall().getArgument(0) + ) + or + exists(Function f, string name | name.matches("MustParse%") | + f.hasQualifiedName("github.com/santhosh-tekuri/xpathparser", name) and + this = f.getACall().getArgument(0) + ) + } + } + + /** An XPath expression string used in an API function of the https://github.com/jbowtie/gokogiri package. */ + private class JbowtieGokogiriXPathExpressionString extends Range { + JbowtieGokogiriXPathExpressionString() { + exists(Function f, string name | name.matches("Compile%") | + f.hasQualifiedName("github.com/jbowtie/gokogiri/xpath", name) and + this = f.getACall().getArgument(0) + ) + or + exists(Method m, string name | name.matches("Search%") | + m.hasQualifiedName("github.com/jbowtie/gokogiri/xml", "Node", name) and + this = m.getACall().getArgument(0) + ) + or + exists(Method m, string name | name.matches("EvalXPath%") | + m.hasQualifiedName("github.com/jbowtie/gokogiri/xml", "Node", name) and + this = m.getACall().getArgument(0) + ) + } + } + } +} diff --git a/ql/src/semmle/go/security/XPathInjection.qll b/ql/src/semmle/go/security/XPathInjection.qll new file mode 100644 index 00000000000..dedaa16575f --- /dev/null +++ b/ql/src/semmle/go/security/XPathInjection.qll @@ -0,0 +1,35 @@ +/** + * Provides a taint tracking configuration for reasoning about untrusted user input used in an XPath expression. + * + * Note: for performance reasons, only import this file if `XPathInjection::Configuration` is needed, + * otherwise `XPathInjectionCustomizations` should be imported instead. + */ + +import go + +/** + * Provides a taint tracking configuration for reasoning about untrusted user input used in an XPath expression. + */ +module XPathInjection { + import XPathInjectionCustomizations::XPathInjection + + /** + * A taint-tracking configuration for reasoning about untrusted user input used in an XPath expression. + */ + class Configuration extends TaintTracking::Configuration { + Configuration() { this = "XPathInjection" } + + override predicate isSource(DataFlow::Node source) { source instanceof Source } + + override predicate isSink(DataFlow::Node sink) { sink instanceof Sink } + + override predicate isSanitizer(DataFlow::Node node) { + super.isSanitizer(node) or + node instanceof Sanitizer + } + + override predicate isSanitizerGuard(DataFlow::BarrierGuard guard) { + guard instanceof SanitizerGuard + } + } +} diff --git a/ql/src/semmle/go/security/XPathInjectionCustomizations.qll b/ql/src/semmle/go/security/XPathInjectionCustomizations.qll new file mode 100644 index 00000000000..b3a25fc2857 --- /dev/null +++ b/ql/src/semmle/go/security/XPathInjectionCustomizations.qll @@ -0,0 +1,41 @@ +/** + * Provides default sources, sinks and sanitizers for reasoning about untrusted user input used in an XPath expression, + * as well as extension points for adding your own. + */ + +import go + +/** + * Provides extension points for reasoning about untrusted user input used in an XPath expression. + */ +module XPathInjection { + /** + * A data flow source for untrusted user input used in an XPath expression. + */ + abstract class Source extends DataFlow::Node { } + + /** + * A data flow sink for untrusted user input used in an XPath expression. + */ + abstract class Sink extends DataFlow::ExprNode { } + + /** + * A sanitizer for untrusted user input used in an XPath expression. + */ + abstract class Sanitizer extends DataFlow::ExprNode { } + + /** + * A sanitizer guard for untrusted user input used in an XPath expression. + */ + abstract class SanitizerGuard extends DataFlow::BarrierGuard { } + + /** A source of untrusted data, used in an XPath expression. */ + class UntrustedFlowAsSource extends Source { + UntrustedFlowAsSource() { this instanceof UntrustedFlowSource } + } + + /** An XPath expression string, considered as a taint sink for XPath injection. */ + class XPathExpressionStringAsSink extends Sink { + XPathExpressionStringAsSink() { this instanceof XPath::XPathExpressionString::Range } + } +} diff --git a/ql/test/query-tests/Security/CWE-643/XPathInjection.expected b/ql/test/query-tests/Security/CWE-643/XPathInjection.expected new file mode 100644 index 00000000000..c9ca557e59e --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/XPathInjection.expected @@ -0,0 +1,122 @@ +edges +| XPathInjection.go:21:14:21:19 | selection of Form : Values | XPathInjection.go:24:23:24:85 | ...+... | +| XPathInjection.go:21:14:21:19 | selection of Form : Values | XPathInjection.go:27:24:27:86 | ...+... | +| XPathInjection.go:21:14:21:19 | selection of Form : Values | XPathInjection.go:30:24:30:82 | ...+... | +| XPathInjection.go:35:14:35:19 | selection of Form : Values | XPathInjection.go:38:26:38:84 | ...+... | +| XPathInjection.go:35:14:35:19 | selection of Form : Values | XPathInjection.go:41:29:41:87 | ...+... | +| XPathInjection.go:35:14:35:19 | selection of Form : Values | XPathInjection.go:44:33:44:91 | ...+... | +| XPathInjection.go:35:14:35:19 | selection of Form : Values | XPathInjection.go:47:30:47:88 | ...+... | +| XPathInjection.go:52:14:52:19 | selection of Form : Values | XPathInjection.go:55:25:55:83 | ...+... | +| XPathInjection.go:52:14:52:19 | selection of Form : Values | XPathInjection.go:58:28:58:86 | ...+... | +| XPathInjection.go:52:14:52:19 | selection of Form : Values | XPathInjection.go:61:25:61:83 | ...+... | +| XPathInjection.go:52:14:52:19 | selection of Form : Values | XPathInjection.go:64:34:64:92 | ...+... | +| XPathInjection.go:52:14:52:19 | selection of Form : Values | XPathInjection.go:67:32:67:90 | ...+... | +| XPathInjection.go:52:14:52:19 | selection of Form : Values | XPathInjection.go:70:29:70:87 | ...+... | +| XPathInjection.go:52:14:52:19 | selection of Form : Values | XPathInjection.go:73:23:73:85 | ...+... | +| XPathInjection.go:52:14:52:19 | selection of Form : Values | XPathInjection.go:76:22:76:84 | ...+... | +| XPathInjection.go:81:14:81:19 | selection of Form : Values | XPathInjection.go:84:26:84:84 | ...+... | +| XPathInjection.go:81:14:81:19 | selection of Form : Values | XPathInjection.go:87:29:87:87 | ...+... | +| XPathInjection.go:81:14:81:19 | selection of Form : Values | XPathInjection.go:90:33:90:91 | ...+... | +| XPathInjection.go:81:14:81:19 | selection of Form : Values | XPathInjection.go:93:30:93:88 | ...+... | +| XPathInjection.go:98:14:98:19 | selection of Form : Values | XPathInjection.go:101:25:101:87 | ...+... | +| XPathInjection.go:98:14:98:19 | selection of Form : Values | XPathInjection.go:104:26:104:88 | ...+... | +| XPathInjection.go:109:14:109:19 | selection of Form : Values | XPathInjection.go:113:23:113:126 | ...+... | +| XPathInjection.go:109:14:109:19 | selection of Form : Values | XPathInjection.go:116:24:116:127 | ...+... | +| XPathInjection.go:109:14:109:19 | selection of Form : Values | XPathInjection.go:119:27:119:122 | ...+... | +| XPathInjection.go:110:14:110:19 | selection of Form : Values | XPathInjection.go:113:23:113:126 | ...+... | +| XPathInjection.go:110:14:110:19 | selection of Form : Values | XPathInjection.go:116:24:116:127 | ...+... | +| XPathInjection.go:110:14:110:19 | selection of Form : Values | XPathInjection.go:119:27:119:122 | ...+... | +| XPathInjection.go:127:14:127:19 | selection of Form : Values | XPathInjection.go:130:27:130:89 | ...+... | +| XPathInjection.go:127:14:127:19 | selection of Form : Values | XPathInjection.go:133:28:133:90 | ...+... | +| XPathInjection.go:138:14:138:19 | selection of Form : Values | XPathInjection.go:142:33:142:136 | ...+... | +| XPathInjection.go:138:14:138:19 | selection of Form : Values | XPathInjection.go:145:18:145:121 | ...+... | +| XPathInjection.go:138:14:138:19 | selection of Form : Values | XPathInjection.go:151:31:151:126 | ...+... | +| XPathInjection.go:138:14:138:19 | selection of Form : Values | XPathInjection.go:160:21:160:116 | ...+... | +| XPathInjection.go:138:14:138:19 | selection of Form : Values | XPathInjection.go:169:27:169:122 | ...+... | +| XPathInjection.go:139:14:139:19 | selection of Form : Values | XPathInjection.go:142:33:142:136 | ...+... | +| XPathInjection.go:139:14:139:19 | selection of Form : Values | XPathInjection.go:145:18:145:121 | ...+... | +| XPathInjection.go:139:14:139:19 | selection of Form : Values | XPathInjection.go:151:31:151:126 | ...+... | +| XPathInjection.go:139:14:139:19 | selection of Form : Values | XPathInjection.go:160:21:160:116 | ...+... | +| XPathInjection.go:139:14:139:19 | selection of Form : Values | XPathInjection.go:169:27:169:122 | ...+... | +nodes +| XPathInjection.go:21:14:21:19 | selection of Form : Values | semmle.label | selection of Form : Values | +| XPathInjection.go:24:23:24:85 | ...+... | semmle.label | ...+... | +| XPathInjection.go:27:24:27:86 | ...+... | semmle.label | ...+... | +| XPathInjection.go:30:24:30:82 | ...+... | semmle.label | ...+... | +| XPathInjection.go:35:14:35:19 | selection of Form : Values | semmle.label | selection of Form : Values | +| XPathInjection.go:38:26:38:84 | ...+... | semmle.label | ...+... | +| XPathInjection.go:41:29:41:87 | ...+... | semmle.label | ...+... | +| XPathInjection.go:44:33:44:91 | ...+... | semmle.label | ...+... | +| XPathInjection.go:47:30:47:88 | ...+... | semmle.label | ...+... | +| XPathInjection.go:52:14:52:19 | selection of Form : Values | semmle.label | selection of Form : Values | +| XPathInjection.go:55:25:55:83 | ...+... | semmle.label | ...+... | +| XPathInjection.go:58:28:58:86 | ...+... | semmle.label | ...+... | +| XPathInjection.go:61:25:61:83 | ...+... | semmle.label | ...+... | +| XPathInjection.go:64:34:64:92 | ...+... | semmle.label | ...+... | +| XPathInjection.go:67:32:67:90 | ...+... | semmle.label | ...+... | +| XPathInjection.go:70:29:70:87 | ...+... | semmle.label | ...+... | +| XPathInjection.go:73:23:73:85 | ...+... | semmle.label | ...+... | +| XPathInjection.go:76:22:76:84 | ...+... | semmle.label | ...+... | +| XPathInjection.go:81:14:81:19 | selection of Form : Values | semmle.label | selection of Form : Values | +| XPathInjection.go:84:26:84:84 | ...+... | semmle.label | ...+... | +| XPathInjection.go:87:29:87:87 | ...+... | semmle.label | ...+... | +| XPathInjection.go:90:33:90:91 | ...+... | semmle.label | ...+... | +| XPathInjection.go:93:30:93:88 | ...+... | semmle.label | ...+... | +| XPathInjection.go:98:14:98:19 | selection of Form : Values | semmle.label | selection of Form : Values | +| XPathInjection.go:101:25:101:87 | ...+... | semmle.label | ...+... | +| XPathInjection.go:104:26:104:88 | ...+... | semmle.label | ...+... | +| XPathInjection.go:109:14:109:19 | selection of Form : Values | semmle.label | selection of Form : Values | +| XPathInjection.go:110:14:110:19 | selection of Form : Values | semmle.label | selection of Form : Values | +| XPathInjection.go:113:23:113:126 | ...+... | semmle.label | ...+... | +| XPathInjection.go:116:24:116:127 | ...+... | semmle.label | ...+... | +| XPathInjection.go:119:27:119:122 | ...+... | semmle.label | ...+... | +| XPathInjection.go:127:14:127:19 | selection of Form : Values | semmle.label | selection of Form : Values | +| XPathInjection.go:130:27:130:89 | ...+... | semmle.label | ...+... | +| XPathInjection.go:133:28:133:90 | ...+... | semmle.label | ...+... | +| XPathInjection.go:138:14:138:19 | selection of Form : Values | semmle.label | selection of Form : Values | +| XPathInjection.go:139:14:139:19 | selection of Form : Values | semmle.label | selection of Form : Values | +| XPathInjection.go:142:33:142:136 | ...+... | semmle.label | ...+... | +| XPathInjection.go:145:18:145:121 | ...+... | semmle.label | ...+... | +| XPathInjection.go:151:31:151:126 | ...+... | semmle.label | ...+... | +| XPathInjection.go:160:21:160:116 | ...+... | semmle.label | ...+... | +| XPathInjection.go:169:27:169:122 | ...+... | semmle.label | ...+... | +#select +| XPathInjection.go:24:23:24:85 | ...+... | XPathInjection.go:21:14:21:19 | selection of Form : Values | XPathInjection.go:24:23:24:85 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:21:14:21:19 | selection of Form | A user-provided value | +| XPathInjection.go:27:24:27:86 | ...+... | XPathInjection.go:21:14:21:19 | selection of Form : Values | XPathInjection.go:27:24:27:86 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:21:14:21:19 | selection of Form | A user-provided value | +| XPathInjection.go:30:24:30:82 | ...+... | XPathInjection.go:21:14:21:19 | selection of Form : Values | XPathInjection.go:30:24:30:82 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:21:14:21:19 | selection of Form | A user-provided value | +| XPathInjection.go:38:26:38:84 | ...+... | XPathInjection.go:35:14:35:19 | selection of Form : Values | XPathInjection.go:38:26:38:84 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:35:14:35:19 | selection of Form | A user-provided value | +| XPathInjection.go:41:29:41:87 | ...+... | XPathInjection.go:35:14:35:19 | selection of Form : Values | XPathInjection.go:41:29:41:87 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:35:14:35:19 | selection of Form | A user-provided value | +| XPathInjection.go:44:33:44:91 | ...+... | XPathInjection.go:35:14:35:19 | selection of Form : Values | XPathInjection.go:44:33:44:91 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:35:14:35:19 | selection of Form | A user-provided value | +| XPathInjection.go:47:30:47:88 | ...+... | XPathInjection.go:35:14:35:19 | selection of Form : Values | XPathInjection.go:47:30:47:88 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:35:14:35:19 | selection of Form | A user-provided value | +| XPathInjection.go:55:25:55:83 | ...+... | XPathInjection.go:52:14:52:19 | selection of Form : Values | XPathInjection.go:55:25:55:83 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:52:14:52:19 | selection of Form | A user-provided value | +| XPathInjection.go:58:28:58:86 | ...+... | XPathInjection.go:52:14:52:19 | selection of Form : Values | XPathInjection.go:58:28:58:86 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:52:14:52:19 | selection of Form | A user-provided value | +| XPathInjection.go:61:25:61:83 | ...+... | XPathInjection.go:52:14:52:19 | selection of Form : Values | XPathInjection.go:61:25:61:83 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:52:14:52:19 | selection of Form | A user-provided value | +| XPathInjection.go:64:34:64:92 | ...+... | XPathInjection.go:52:14:52:19 | selection of Form : Values | XPathInjection.go:64:34:64:92 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:52:14:52:19 | selection of Form | A user-provided value | +| XPathInjection.go:67:32:67:90 | ...+... | XPathInjection.go:52:14:52:19 | selection of Form : Values | XPathInjection.go:67:32:67:90 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:52:14:52:19 | selection of Form | A user-provided value | +| XPathInjection.go:70:29:70:87 | ...+... | XPathInjection.go:52:14:52:19 | selection of Form : Values | XPathInjection.go:70:29:70:87 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:52:14:52:19 | selection of Form | A user-provided value | +| XPathInjection.go:73:23:73:85 | ...+... | XPathInjection.go:52:14:52:19 | selection of Form : Values | XPathInjection.go:73:23:73:85 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:52:14:52:19 | selection of Form | A user-provided value | +| XPathInjection.go:76:22:76:84 | ...+... | XPathInjection.go:52:14:52:19 | selection of Form : Values | XPathInjection.go:76:22:76:84 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:52:14:52:19 | selection of Form | A user-provided value | +| XPathInjection.go:84:26:84:84 | ...+... | XPathInjection.go:81:14:81:19 | selection of Form : Values | XPathInjection.go:84:26:84:84 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:81:14:81:19 | selection of Form | A user-provided value | +| XPathInjection.go:87:29:87:87 | ...+... | XPathInjection.go:81:14:81:19 | selection of Form : Values | XPathInjection.go:87:29:87:87 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:81:14:81:19 | selection of Form | A user-provided value | +| XPathInjection.go:90:33:90:91 | ...+... | XPathInjection.go:81:14:81:19 | selection of Form : Values | XPathInjection.go:90:33:90:91 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:81:14:81:19 | selection of Form | A user-provided value | +| XPathInjection.go:93:30:93:88 | ...+... | XPathInjection.go:81:14:81:19 | selection of Form : Values | XPathInjection.go:93:30:93:88 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:81:14:81:19 | selection of Form | A user-provided value | +| XPathInjection.go:101:25:101:87 | ...+... | XPathInjection.go:98:14:98:19 | selection of Form : Values | XPathInjection.go:101:25:101:87 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:98:14:98:19 | selection of Form | A user-provided value | +| XPathInjection.go:104:26:104:88 | ...+... | XPathInjection.go:98:14:98:19 | selection of Form : Values | XPathInjection.go:104:26:104:88 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:98:14:98:19 | selection of Form | A user-provided value | +| XPathInjection.go:113:23:113:126 | ...+... | XPathInjection.go:109:14:109:19 | selection of Form : Values | XPathInjection.go:113:23:113:126 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:109:14:109:19 | selection of Form | A user-provided value | +| XPathInjection.go:113:23:113:126 | ...+... | XPathInjection.go:110:14:110:19 | selection of Form : Values | XPathInjection.go:113:23:113:126 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:110:14:110:19 | selection of Form | A user-provided value | +| XPathInjection.go:116:24:116:127 | ...+... | XPathInjection.go:109:14:109:19 | selection of Form : Values | XPathInjection.go:116:24:116:127 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:109:14:109:19 | selection of Form | A user-provided value | +| XPathInjection.go:116:24:116:127 | ...+... | XPathInjection.go:110:14:110:19 | selection of Form : Values | XPathInjection.go:116:24:116:127 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:110:14:110:19 | selection of Form | A user-provided value | +| XPathInjection.go:119:27:119:122 | ...+... | XPathInjection.go:109:14:109:19 | selection of Form : Values | XPathInjection.go:119:27:119:122 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:109:14:109:19 | selection of Form | A user-provided value | +| XPathInjection.go:119:27:119:122 | ...+... | XPathInjection.go:110:14:110:19 | selection of Form : Values | XPathInjection.go:119:27:119:122 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:110:14:110:19 | selection of Form | A user-provided value | +| XPathInjection.go:130:27:130:89 | ...+... | XPathInjection.go:127:14:127:19 | selection of Form : Values | XPathInjection.go:130:27:130:89 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:127:14:127:19 | selection of Form | A user-provided value | +| XPathInjection.go:133:28:133:90 | ...+... | XPathInjection.go:127:14:127:19 | selection of Form : Values | XPathInjection.go:133:28:133:90 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:127:14:127:19 | selection of Form | A user-provided value | +| XPathInjection.go:142:33:142:136 | ...+... | XPathInjection.go:138:14:138:19 | selection of Form : Values | XPathInjection.go:142:33:142:136 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:138:14:138:19 | selection of Form | A user-provided value | +| XPathInjection.go:142:33:142:136 | ...+... | XPathInjection.go:139:14:139:19 | selection of Form : Values | XPathInjection.go:142:33:142:136 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:139:14:139:19 | selection of Form | A user-provided value | +| XPathInjection.go:145:18:145:121 | ...+... | XPathInjection.go:138:14:138:19 | selection of Form : Values | XPathInjection.go:145:18:145:121 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:138:14:138:19 | selection of Form | A user-provided value | +| XPathInjection.go:145:18:145:121 | ...+... | XPathInjection.go:139:14:139:19 | selection of Form : Values | XPathInjection.go:145:18:145:121 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:139:14:139:19 | selection of Form | A user-provided value | +| XPathInjection.go:151:31:151:126 | ...+... | XPathInjection.go:138:14:138:19 | selection of Form : Values | XPathInjection.go:151:31:151:126 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:138:14:138:19 | selection of Form | A user-provided value | +| XPathInjection.go:151:31:151:126 | ...+... | XPathInjection.go:139:14:139:19 | selection of Form : Values | XPathInjection.go:151:31:151:126 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:139:14:139:19 | selection of Form | A user-provided value | +| XPathInjection.go:160:21:160:116 | ...+... | XPathInjection.go:138:14:138:19 | selection of Form : Values | XPathInjection.go:160:21:160:116 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:138:14:138:19 | selection of Form | A user-provided value | +| XPathInjection.go:160:21:160:116 | ...+... | XPathInjection.go:139:14:139:19 | selection of Form : Values | XPathInjection.go:160:21:160:116 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:139:14:139:19 | selection of Form | A user-provided value | +| XPathInjection.go:169:27:169:122 | ...+... | XPathInjection.go:138:14:138:19 | selection of Form : Values | XPathInjection.go:169:27:169:122 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:138:14:138:19 | selection of Form | A user-provided value | +| XPathInjection.go:169:27:169:122 | ...+... | XPathInjection.go:139:14:139:19 | selection of Form : Values | XPathInjection.go:169:27:169:122 | ...+... | $@ flows here and is used in an XPath expression. | XPathInjection.go:139:14:139:19 | selection of Form | A user-provided value | diff --git a/ql/test/query-tests/Security/CWE-643/XPathInjection.go b/ql/test/query-tests/Security/CWE-643/XPathInjection.go new file mode 100644 index 00000000000..75ca454bd5d --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/XPathInjection.go @@ -0,0 +1,176 @@ +package main + +import ( + "net/http" + + "github.com/ChrisTrenkamp/goxpath" + "github.com/antchfx/htmlquery" + "github.com/antchfx/jsonquery" + "github.com/antchfx/xmlquery" + "github.com/antchfx/xpath" + "github.com/go-xmlpath/xmlpath" + gokogiriXml "github.com/jbowtie/gokogiri/xml" + gokogiriXpath "github.com/jbowtie/gokogiri/xpath" + "github.com/santhosh-tekuri/xpathparser" +) + +func main() {} + +func testAntchfxXpath(r *http.Request) { + r.ParseForm() + username := r.Form.Get("username") + + // BAD: User input used directly in an XPath expression + _, _ = xpath.Compile("//users/user[login/text()='" + username + "']/home_dir/text()") + + // BAD: User input used directly in an XPath expression + _ = xpath.MustCompile("//users/user[login/text()='" + username + "']/home_dir/text()") + + // BAD: User input used directly in an XPath expression + _ = xpath.Select(nil, "//users/user[login/text()='"+username+"']/home_dir/text()") +} + +func testAntchfxHtmlquery(r *http.Request) { + r.ParseForm() + username := r.Form.Get("username") + + // BAD: User input used directly in an XPath expression + _ = htmlquery.Find(nil, "//users/user[login/text()='"+username+"']/home_dir/text()") + + // BAD: User input used directly in an XPath expression + _ = htmlquery.FindOne(nil, "//users/user[login/text()='"+username+"']/home_dir/text()") + + // BAD: User input used directly in an XPath expression + _, _ = htmlquery.QueryAll(nil, "//users/user[login/text()='"+username+"']/home_dir/text()") + + // BAD: User input used directly in an XPath expression + _, _ = htmlquery.Query(nil, "//users/user[login/text()='"+username+"']/home_dir/text()") +} + +func testAntchfxXmlquery(r *http.Request, n *xmlquery.Node) { + r.ParseForm() + username := r.Form.Get("username") + + // BAD: User input used directly in an XPath expression + _ = xmlquery.Find(nil, "//users/user[login/text()='"+username+"']/home_dir/text()") + + // BAD: User input used directly in an XPath expression + _ = xmlquery.FindOne(nil, "//users/user[login/text()='"+username+"']/home_dir/text()") + + // BAD: User input used directly in an XPath expression + xmlquery.FindEach(nil, "//users/user[login/text()='"+username+"']/home_dir/text()", nil) + + // BAD: User input used directly in an XPath expression + xmlquery.FindEachWithBreak(nil, "//users/user[login/text()='"+username+"']/home_dir/text()", nil) + + // BAD: User input used directly in an XPath expression + _, _ = xmlquery.QueryAll(nil, "//users/user[login/text()='"+username+"']/home_dir/text()") + + // BAD: User input used directly in an XPath expression + _, _ = xmlquery.Query(nil, "//users/user[login/text()='"+username+"']/home_dir/text()") + + // BAD: User input used directly in an XPath expression + _ = n.SelectElements("//users/user[login/text()='" + username + "']/home_dir/text()") + + // BAD: User input used directly in an XPath expression + _ = n.SelectElement("//users/user[login/text()='" + username + "']/home_dir/text()") +} + +func testAntchfxJsonquery(r *http.Request) { + r.ParseForm() + username := r.Form.Get("username") + + // BAD: User input used directly in an XPath expression + _ = jsonquery.Find(nil, "//users/user[login/text()='"+username+"']/home_dir/text()") + + // BAD: User input used directly in an XPath expression + _ = jsonquery.FindOne(nil, "//users/user[login/text()='"+username+"']/home_dir/text()") + + // BAD: User input used directly in an XPath expression + _, _ = jsonquery.QueryAll(nil, "//users/user[login/text()='"+username+"']/home_dir/text()") + + // BAD: User input used directly in an XPath expression + _, _ = jsonquery.Query(nil, "//users/user[login/text()='"+username+"']/home_dir/text()") +} + +func testGoXmlpathXmlpath(r *http.Request) { + r.ParseForm() + username := r.Form.Get("username") + + // BAD: User input used directly in an XPath expression + _, _ = xmlpath.Compile("//users/user[login/text()='" + username + "']/home_dir/text()") + + // BAD: User input used directly in an XPath expression + _ = xmlpath.MustCompile("//users/user[login/text()='" + username + "']/home_dir/text()") +} + +func testChrisTrenkampGoxpath(r *http.Request) { + r.ParseForm() + username := r.Form.Get("username") + password := r.Form.Get("password") + + // BAD: User input used directly in an XPath expression + _, _ = goxpath.Parse("//users/user[login/text()='" + username + "' and password/text() = '" + password + "']/home_dir/text()") + + // BAD: User input used directly in an XPath expression + _ = goxpath.MustParse("//users/user[login/text()='" + username + "' and password/text() = '" + password + "']/home_dir/text()") + + // BAD: User input used directly in an XPath expression + _, _ = goxpath.ParseExec("//users/user[login/text()='"+username+"' and password/text() = '"+password+"']/home_dir/text()", nil) + + // GOOD: Uses parameters to avoid including user input directly in XPath expression + _ = goxpath.MustParse("//users/user[login/text()=$username and password/text() = $password]/home_dir/text()") +} + +func testSanthoshTekuriXpathparser(r *http.Request) { + r.ParseForm() + username := r.Form.Get("username") + + // BAD: User input used directly in an XPath expression + _, _ = xpathparser.Parse("//users/user[login/text()='" + username + "']/home_dir/text()") + + // BAD: User input used directly in an XPath expression + _ = xpathparser.MustParse("//users/user[login/text()='" + username + "']/home_dir/text()") +} + +func testJbowtieGokogiri(r *http.Request, n gokogiriXml.Node) { + r.ParseForm() + username := r.Form.Get("username") + password := r.Form.Get("password") + + // BAD: User input used directly in an XPath expression + xpath := gokogiriXpath.Compile("//users/user[login/text()='" + username + "' and password/text() = '" + password + "']/home_dir/text()") + + // BAD: User input used directly in an XPath expression + _, _ = n.Search("//users/user[login/text()='" + username + "' and password/text() = '" + password + "']/home_dir/text()") + + // OK: This is not flagged, since the creation of `xpath` is already flagged. + _, _ = n.Search(xpath) + + // BAD: User input used directly in an XPath expression + _, _ = n.SearchWithVariables("//users/user[login/text()='"+username+"' and password/text() = '"+password+"']/home_dir/text()", nil) + + // GOOD: Uses parameters to avoid including user input directly in XPath expression + _, _ = n.SearchWithVariables("//users/user[login/text()=$username and password/text() = $password]/home_dir/text()", nil) + + // OK: This is not flagged, since the creation of `xpath` is already flagged. + _, _ = n.SearchWithVariables(xpath, nil) + + // BAD: User input used directly in an XPath expression + _, _ = n.EvalXPath("//users/user[login/text()='"+username+"' and password/text() = '"+password+"']/home_dir/text()", nil) + + // GOOD: Uses parameters to avoid including user input directly in XPath expression + _, _ = n.EvalXPath("//users/user[login/text()=$username and password/text() = $password]/home_dir/text()", nil) + + // OK: This is not flagged, since the creation of `xpath` is already flagged. + _, _ = n.EvalXPath(xpath, nil) + + // BAD: User input used directly in an XPath expression + _ = n.EvalXPathAsBoolean("//users/user[login/text()='"+username+"' and password/text() = '"+password+"']/home_dir/text()", nil) + + // GOOD: Uses parameters to avoid including user input directly in XPath expression + _ = n.EvalXPathAsBoolean("//users/user[login/text()=$username and password/text() = $password]/home_dir/text()", nil) + + // OK: This is not flagged, since the creation of `xpath` is already flagged. + _ = n.EvalXPathAsBoolean(xpath, nil) +} diff --git a/ql/test/query-tests/Security/CWE-643/XPathInjection.qlref b/ql/test/query-tests/Security/CWE-643/XPathInjection.qlref new file mode 100644 index 00000000000..c48e056141c --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/XPathInjection.qlref @@ -0,0 +1 @@ +Security/CWE-643/XPathInjection.ql diff --git a/ql/test/query-tests/Security/CWE-643/go.mod b/ql/test/query-tests/Security/CWE-643/go.mod new file mode 100644 index 00000000000..f274ed45000 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/go.mod @@ -0,0 +1,16 @@ +module main + +go 1.13 + +require ( + github.com/ChrisTrenkamp/goxpath v0.0.0-20190607011252-c5096ec8773d + github.com/antchfx/htmlquery v1.2.2 + github.com/antchfx/jsonquery v1.1.2 + github.com/antchfx/xmlquery v1.2.3 + github.com/antchfx/xpath v1.1.4 + github.com/go-xmlpath/xmlpath v0.0.0-20150820204837-860cbeca3ebc + github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e + github.com/jbowtie/gokogiri v0.0.0-20190301021639-37f655d3078f + github.com/santhosh-tekuri/xpathparser v1.0.0 + golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e +) diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/ChrisTrenkamp/goxpath/LICENSE b/ql/test/query-tests/Security/CWE-643/vendor/github.com/ChrisTrenkamp/goxpath/LICENSE new file mode 100644 index 00000000000..2afe88a6155 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/ChrisTrenkamp/goxpath/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 ChrisTrenkamp + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/ChrisTrenkamp/goxpath/README.md b/ql/test/query-tests/Security/CWE-643/vendor/github.com/ChrisTrenkamp/goxpath/README.md new file mode 100644 index 00000000000..4812afac396 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/ChrisTrenkamp/goxpath/README.md @@ -0,0 +1,3 @@ +This is a simple stub for https://github.com/ChrisTrenkamp/goxpath, strictly for use in query testing. + +See the LICENSE file in this folder for information about the licensing of the original library. diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/ChrisTrenkamp/goxpath/goxpath.go b/ql/test/query-tests/Security/CWE-643/vendor/github.com/ChrisTrenkamp/goxpath/goxpath.go new file mode 100644 index 00000000000..1867a462121 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/ChrisTrenkamp/goxpath/goxpath.go @@ -0,0 +1,10 @@ +package goxpath + +type Opts struct{} +type FuncOpts func(*Opts) + +type XPathExec struct{} + +func Parse(xp string) (XPathExec, error) +func MustParse(xp string) XPathExec +func ParseExec(xpstr string, t tree.Node, opts ...FuncOpts) (tree.Result, error) diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/htmlquery/LICENSE b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/htmlquery/LICENSE new file mode 100644 index 00000000000..e14c37141c5 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/htmlquery/LICENSE @@ -0,0 +1,17 @@ +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/htmlquery/README.md b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/htmlquery/README.md new file mode 100644 index 00000000000..34024e519bf --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/htmlquery/README.md @@ -0,0 +1,3 @@ +This is a simple stub for https://github.com/antchfx/htmlquery, strictly for use in query testing. + +See the LICENSE file in this folder for information about the licensing of the original library. diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/htmlquery/query.go b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/htmlquery/query.go new file mode 100644 index 00000000000..f3f88db24c5 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/htmlquery/query.go @@ -0,0 +1,6 @@ +package htmlquery + +func Find(top *html.Node, expr string) []*html.Node +func FindOne(top *html.Node, expr string) *html.Node +func QueryAll(top *html.Node, expr string) ([]*html.Node, error) +func Query(top *html.Node, expr string) (*html.Node, error) diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/jsonquery/LICENSE b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/jsonquery/LICENSE new file mode 100644 index 00000000000..e14c37141c5 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/jsonquery/LICENSE @@ -0,0 +1,17 @@ +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/jsonquery/README.md b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/jsonquery/README.md new file mode 100644 index 00000000000..533b3887b0a --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/jsonquery/README.md @@ -0,0 +1,3 @@ +This is a simple stub for https://github.com/antchfx/jsonquery, strictly for use in query testing. + +See the LICENSE file in this folder for information about the licensing of the original library. diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/jsonquery/node.go b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/jsonquery/node.go new file mode 100644 index 00000000000..b09fb54a83f --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/jsonquery/node.go @@ -0,0 +1,3 @@ +package jsonquery + +type Node struct{} diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/jsonquery/query.go b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/jsonquery/query.go new file mode 100644 index 00000000000..d3a43a46f77 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/jsonquery/query.go @@ -0,0 +1,6 @@ +package jsonquery + +func Find(top *Node, expr string) []*Node +func FindOne(top *Node, expr string) *Node +func QueryAll(top *Node, expr string) ([]*Node, error) +func Query(top *Node, expr string) (*Node, error) diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xmlquery/LICENSE b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xmlquery/LICENSE new file mode 100644 index 00000000000..e14c37141c5 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xmlquery/LICENSE @@ -0,0 +1,17 @@ +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xmlquery/README.md b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xmlquery/README.md new file mode 100644 index 00000000000..da531d361a9 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xmlquery/README.md @@ -0,0 +1,3 @@ +This is a simple stub for https://github.com/antchfx/xmlquery, strictly for use in query testing. + +See the LICENSE file in this folder for information about the licensing of the original library. diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xmlquery/node.go b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xmlquery/node.go new file mode 100644 index 00000000000..8bb284f174e --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xmlquery/node.go @@ -0,0 +1,4 @@ +package xmlquery + +type Node struct { +} diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xmlquery/query.go b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xmlquery/query.go new file mode 100644 index 00000000000..28e85185ed9 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xmlquery/query.go @@ -0,0 +1,10 @@ +package xmlquery + +func (n *Node) SelectElements(name string) []*Node +func (n *Node) SelectElement(name string) *Node +func Find(top *Node, expr string) []*Node +func FindOne(top *Node, expr string) *Node +func QueryAll(top *Node, expr string) ([]*Node, error) +func Query(top *Node, expr string) (*Node, error) +func FindEach(top *Node, expr string, cb func(int, *Node)) +func FindEachWithBreak(top *Node, expr string, cb func(int, *Node) bool) diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xpath/LICENSE b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xpath/LICENSE new file mode 100644 index 00000000000..e14c37141c5 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xpath/LICENSE @@ -0,0 +1,17 @@ +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xpath/README.md b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xpath/README.md new file mode 100644 index 00000000000..4d741a91818 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xpath/README.md @@ -0,0 +1,3 @@ +This is a simple stub for https://github.com/antchfx/xpath, strictly for use in query testing. + +See the LICENSE file in this folder for information about the licensing of the original library. diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xpath/xpath.go b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xpath/xpath.go new file mode 100644 index 00000000000..538a3abb871 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/antchfx/xpath/xpath.go @@ -0,0 +1,16 @@ +package xpath + +type NodeNavigator interface { +} + +type NodeIterator struct { +} + +func Select(root NodeNavigator, expr string) *NodeIterator + +type Expr struct { +} + +func Compile(expr string) (*Expr, error) + +func MustCompile(expr string) *Expr diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/go-xmlpath/xmlpath/LICENSE b/ql/test/query-tests/Security/CWE-643/vendor/github.com/go-xmlpath/xmlpath/LICENSE new file mode 100644 index 00000000000..4ccd784ba7b --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/go-xmlpath/xmlpath/LICENSE @@ -0,0 +1,187 @@ +Copyright (c) 2013-2014 Canonical Inc. + +This software is licensed under the LGPLv3, included below. + +As a special exception to the GNU Lesser General Public License version 3 +("LGPL3"), the copyright holders of this Library give you permission to +convey to a third party a Combined Work that links statically or dynamically +to this Library without providing any Minimal Corresponding Source or +Minimal Application Code as set out in 4d or providing the installation +information set out in section 4e, provided that you comply with the other +provisions of LGPL3 and provided that you meet, for the Application the +terms and conditions of the license(s) which apply to the Application. + +Except as stated in this special exception, the provisions of LGPL3 will +continue to comply in full to this Library. If you modify this Library, you +may apply this exception to your version of this Library, but you are not +obliged to do so. If you do not wish to do so, delete this exception +statement from your version. This exception does not (and cannot) modify any +license terms which apply to the Application, with which you must still +comply. + + + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/go-xmlpath/xmlpath/README.md b/ql/test/query-tests/Security/CWE-643/vendor/github.com/go-xmlpath/xmlpath/README.md new file mode 100644 index 00000000000..3584c6f7343 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/go-xmlpath/xmlpath/README.md @@ -0,0 +1,3 @@ +This is a simple stub for https://github.com/go-xmlpath/xmlpath, strictly for use in query testing. + +See the LICENSE file in this folder for information about the licensing of the original library. diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/go-xmlpath/xmlpath/path.go b/ql/test/query-tests/Security/CWE-643/vendor/github.com/go-xmlpath/xmlpath/path.go new file mode 100644 index 00000000000..ffa658413a7 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/go-xmlpath/xmlpath/path.go @@ -0,0 +1,7 @@ +package xmlpath + +type Path struct { +} + +func MustCompile(path string) *Path +func Compile(path string) (*Path, error) diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/jbowtie/gokogiri/LICENSE b/ql/test/query-tests/Security/CWE-643/vendor/github.com/jbowtie/gokogiri/LICENSE new file mode 100644 index 00000000000..eb094e44412 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/jbowtie/gokogiri/LICENSE @@ -0,0 +1,7 @@ +Copyright (c) 2011-2012 Zhigang Chen and Hampton Catlin + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/jbowtie/gokogiri/README.md b/ql/test/query-tests/Security/CWE-643/vendor/github.com/jbowtie/gokogiri/README.md new file mode 100644 index 00000000000..0feacaef87b --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/jbowtie/gokogiri/README.md @@ -0,0 +1,3 @@ +This is a simple stub for https://github.com/jbowtie/gokogiri, strictly for use in query testing. + +See the LICENSE file in this folder for information about the licensing of the original library. diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/jbowtie/gokogiri/xml/node.go b/ql/test/query-tests/Security/CWE-643/vendor/github.com/jbowtie/gokogiri/xml/node.go new file mode 100644 index 00000000000..6ae0dc780b6 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/jbowtie/gokogiri/xml/node.go @@ -0,0 +1,8 @@ +package xml + +type Node interface { + Search(interface{}) ([]Node, error) + SearchWithVariables(interface{}, xpath.VariableScope) ([]Node, error) + EvalXPath(interface{}, xpath.VariableScope) (interface{}, error) + EvalXPathAsBoolean(interface{}, xpath.VariableScope) bool +} diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/jbowtie/gokogiri/xpath/expression.go b/ql/test/query-tests/Security/CWE-643/vendor/github.com/jbowtie/gokogiri/xpath/expression.go new file mode 100644 index 00000000000..9166459815b --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/jbowtie/gokogiri/xpath/expression.go @@ -0,0 +1,6 @@ +package xpath + +type Expression struct { +} + +func Compile(path string) (expr *Expression) diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/jbowtie/gokogiri/xpath/xpath.go b/ql/test/query-tests/Security/CWE-643/vendor/github.com/jbowtie/gokogiri/xpath/xpath.go new file mode 100644 index 00000000000..0de126bee56 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/jbowtie/gokogiri/xpath/xpath.go @@ -0,0 +1,3 @@ +package xpath + +type VariableScope interface{} diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/santhosh-tekuri/xpathparser/LICENSE b/ql/test/query-tests/Security/CWE-643/vendor/github.com/santhosh-tekuri/xpathparser/LICENSE new file mode 100644 index 00000000000..65cd403ab0e --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/santhosh-tekuri/xpathparser/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2017 Santhosh Kumar Tekuri. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/santhosh-tekuri/xpathparser/README.md b/ql/test/query-tests/Security/CWE-643/vendor/github.com/santhosh-tekuri/xpathparser/README.md new file mode 100644 index 00000000000..a806adde588 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/santhosh-tekuri/xpathparser/README.md @@ -0,0 +1,3 @@ +This is a simple stub for https://github.com/santhosh-tekuri/xpathparser, strictly for use in query testing. + +See the LICENSE file in this folder for information about the licensing of the original library. diff --git a/ql/test/query-tests/Security/CWE-643/vendor/github.com/santhosh-tekuri/xpathparser/xpath.go b/ql/test/query-tests/Security/CWE-643/vendor/github.com/santhosh-tekuri/xpathparser/xpath.go new file mode 100644 index 00000000000..099d1e84d80 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/github.com/santhosh-tekuri/xpathparser/xpath.go @@ -0,0 +1,6 @@ +package xpathparser + +type Expr interface{} + +func MustParse(xpath string) Expr +func Parse(xpath string) (expr Expr, err error) diff --git a/ql/test/query-tests/Security/CWE-643/vendor/golang.org/x/net/AUTHORS b/ql/test/query-tests/Security/CWE-643/vendor/golang.org/x/net/AUTHORS new file mode 100644 index 00000000000..15167cd746c --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/golang.org/x/net/AUTHORS @@ -0,0 +1,3 @@ +# This source code refers to The Go Authors for copyright purposes. +# The master list of authors is in the main Go distribution, +# visible at http://tip.golang.org/AUTHORS. diff --git a/ql/test/query-tests/Security/CWE-643/vendor/golang.org/x/net/CONTRIBUTORS b/ql/test/query-tests/Security/CWE-643/vendor/golang.org/x/net/CONTRIBUTORS new file mode 100644 index 00000000000..1c4577e9680 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/golang.org/x/net/CONTRIBUTORS @@ -0,0 +1,3 @@ +# This source code was written by the Go contributors. +# The master list of contributors is in the main Go distribution, +# visible at http://tip.golang.org/CONTRIBUTORS. diff --git a/ql/test/query-tests/Security/CWE-643/vendor/golang.org/x/net/LICENSE b/ql/test/query-tests/Security/CWE-643/vendor/golang.org/x/net/LICENSE new file mode 100644 index 00000000000..6a66aea5eaf --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/golang.org/x/net/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2009 The Go Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/ql/test/query-tests/Security/CWE-643/vendor/golang.org/x/net/PATENTS b/ql/test/query-tests/Security/CWE-643/vendor/golang.org/x/net/PATENTS new file mode 100644 index 00000000000..733099041f8 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/golang.org/x/net/PATENTS @@ -0,0 +1,22 @@ +Additional IP Rights Grant (Patents) + +"This implementation" means the copyrightable works distributed by +Google as part of the Go project. + +Google hereby grants to You a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable (except as stated in this section) +patent license to make, have made, use, offer to sell, sell, import, +transfer and otherwise run, modify and propagate the contents of this +implementation of Go, where such license applies only to those patent +claims, both currently owned or controlled by Google and acquired in +the future, licensable by Google that are necessarily infringed by this +implementation of Go. This grant does not include claims that would be +infringed only as a consequence of further modification of this +implementation. If you or your agent or exclusive licensee institute or +order or agree to the institution of patent litigation against any +entity (including a cross-claim or counterclaim in a lawsuit) alleging +that this implementation of Go or any code incorporated within this +implementation of Go constitutes direct or contributory patent +infringement, or inducement of patent infringement, then any patent +rights granted to you under this License for this implementation of Go +shall terminate as of the date such litigation is filed. diff --git a/ql/test/query-tests/Security/CWE-643/vendor/golang.org/x/net/README.md b/ql/test/query-tests/Security/CWE-643/vendor/golang.org/x/net/README.md new file mode 100644 index 00000000000..dcae7bfe502 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/golang.org/x/net/README.md @@ -0,0 +1,3 @@ +This is a simple stub for https://golang.org/x/net, strictly for use in query testing. + +See the LICENSE file in this folder for information about the licensing of the original library. diff --git a/ql/test/query-tests/Security/CWE-643/vendor/golang.org/x/net/html/node.go b/ql/test/query-tests/Security/CWE-643/vendor/golang.org/x/net/html/node.go new file mode 100644 index 00000000000..04e99a9cd49 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/golang.org/x/net/html/node.go @@ -0,0 +1,4 @@ +package html + +type Node struct { +} diff --git a/ql/test/query-tests/Security/CWE-643/vendor/modules.txt b/ql/test/query-tests/Security/CWE-643/vendor/modules.txt new file mode 100644 index 00000000000..7e9be09392f --- /dev/null +++ b/ql/test/query-tests/Security/CWE-643/vendor/modules.txt @@ -0,0 +1,28 @@ +# github.com/ChrisTrenkamp/goxpath v0.0.0-20190607011252-c5096ec8773d +## explicit +github.com/ChrisTrenkamp/goxpath +# github.com/antchfx/htmlquery v1.2.2 +## explicit +github.com/antchfx/htmlquery +# github.com/antchfx/jsonquery v1.1.2 +## explicit +github.com/antchfx/jsonquery +# github.com/antchfx/xmlquery v1.2.3 +## explicit +github.com/antchfx/xmlquery +# github.com/antchfx/xpath v1.1.4 +## explicit +github.com/antchfx/xpath +# github.com/go-xmlpath/xmlpath v0.0.0-20150820204837-860cbeca3ebc +## explicit +github.com/go-xmlpath/xmlpath +# github.com/jbowtie/gokogiri v0.0.0-20190301021639-37f655d3078f +## explicit +github.com/jbowtie/gokogiri/xml +github.com/jbowtie/gokogiri/xpath +# github.com/santhosh-tekuri/xpathparser v1.0.0 +## explicit +github.com/santhosh-tekuri/xpathparser +# golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e +## explicit +golang.org/x/net/html \ No newline at end of file