mirror of
https://github.com/github/codeql.git
synced 2026-01-31 15:22:57 +01:00
Merge pull request #320 from gagliardetto/standard-lib-pt-24
Add taint-tracking for packages inside `text/*`
This commit is contained in:
@@ -15,6 +15,9 @@ import semmle.go.frameworks.stdlib.CompressZlib
|
||||
import semmle.go.frameworks.stdlib.Path
|
||||
import semmle.go.frameworks.stdlib.PathFilepath
|
||||
import semmle.go.frameworks.stdlib.Reflect
|
||||
import semmle.go.frameworks.stdlib.TextScanner
|
||||
import semmle.go.frameworks.stdlib.TextTabwriter
|
||||
import semmle.go.frameworks.stdlib.TextTemplate
|
||||
|
||||
/** A `String()` method. */
|
||||
class StringMethod extends TaintTracking::FunctionModel, Method {
|
||||
@@ -576,48 +579,6 @@ module Strings {
|
||||
}
|
||||
}
|
||||
|
||||
/** Provides models of commonly used functions in the `text/template` package. */
|
||||
module Template {
|
||||
private class TemplateEscape extends EscapeFunction::Range {
|
||||
string kind;
|
||||
|
||||
TemplateEscape() {
|
||||
exists(string fn |
|
||||
fn.matches("HTMLEscape%") and kind = "html"
|
||||
or
|
||||
fn.matches("JSEscape%") and kind = "js"
|
||||
or
|
||||
fn.matches("URLQueryEscape%") and kind = "url"
|
||||
|
|
||||
this.hasQualifiedName("text/template", fn)
|
||||
or
|
||||
this.hasQualifiedName("html/template", fn)
|
||||
)
|
||||
}
|
||||
|
||||
override string kind() { result = kind }
|
||||
}
|
||||
|
||||
private class TextTemplateInstantiation extends TemplateInstantiation::Range,
|
||||
DataFlow::MethodCallNode {
|
||||
int dataArg;
|
||||
|
||||
TextTemplateInstantiation() {
|
||||
exists(string m | getTarget().hasQualifiedName("text/template", "Template", m) |
|
||||
m = "Execute" and
|
||||
dataArg = 1
|
||||
or
|
||||
m = "ExecuteTemplate" and
|
||||
dataArg = 2
|
||||
)
|
||||
}
|
||||
|
||||
override DataFlow::Node getTemplateArgument() { result = this.getReceiver() }
|
||||
|
||||
override DataFlow::Node getADataArgument() { result = this.getArgument(dataArg) }
|
||||
}
|
||||
}
|
||||
|
||||
/** Provides models of commonly used functions in the `net/url` package. */
|
||||
module URL {
|
||||
/** The `PathEscape` or `QueryEscape` function. */
|
||||
|
||||
30
ql/src/semmle/go/frameworks/stdlib/TextScanner.qll
Normal file
30
ql/src/semmle/go/frameworks/stdlib/TextScanner.qll
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Provides classes modeling security-relevant aspects of the `text/scanner` package.
|
||||
*/
|
||||
|
||||
import go
|
||||
|
||||
/** Provides models of commonly used functions in the `text/scanner` package. */
|
||||
module TextScanner {
|
||||
private class MethodModels extends TaintTracking::FunctionModel, Method {
|
||||
FunctionInput inp;
|
||||
FunctionOutput outp;
|
||||
|
||||
MethodModels() {
|
||||
// signature: func (*Scanner).Init(src io.Reader) *Scanner
|
||||
this.hasQualifiedName("text/scanner", "Scanner", "Init") and
|
||||
(
|
||||
inp.isParameter(0) and
|
||||
(outp.isReceiver() or outp.isResult())
|
||||
)
|
||||
or
|
||||
// signature: func (*Scanner).TokenText() string
|
||||
this.hasQualifiedName("text/scanner", "Scanner", "TokenText") and
|
||||
(inp.isReceiver() and outp.isResult())
|
||||
}
|
||||
|
||||
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
|
||||
input = inp and output = outp
|
||||
}
|
||||
}
|
||||
}
|
||||
45
ql/src/semmle/go/frameworks/stdlib/TextTabwriter.qll
Normal file
45
ql/src/semmle/go/frameworks/stdlib/TextTabwriter.qll
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Provides classes modeling security-relevant aspects of the `text/tabwriter` package.
|
||||
*/
|
||||
|
||||
import go
|
||||
|
||||
/** Provides models of commonly used functions in the `text/tabwriter` package. */
|
||||
module TextTabwriter {
|
||||
private class FunctionModels extends TaintTracking::FunctionModel {
|
||||
FunctionInput inp;
|
||||
FunctionOutput outp;
|
||||
|
||||
FunctionModels() {
|
||||
// signature: func NewWriter(output io.Writer, minwidth int, tabwidth int, padding int, padchar byte, flags uint) *Writer
|
||||
hasQualifiedName("text/tabwriter", "NewWriter") and
|
||||
(inp.isResult() and outp.isParameter(0))
|
||||
}
|
||||
|
||||
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
|
||||
input = inp and output = outp
|
||||
}
|
||||
}
|
||||
|
||||
private class MethodModels extends TaintTracking::FunctionModel, Method {
|
||||
FunctionInput inp;
|
||||
FunctionOutput outp;
|
||||
|
||||
MethodModels() {
|
||||
// signature: func (*Writer).Init(output io.Writer, minwidth int, tabwidth int, padding int, padchar byte, flags uint) *Writer
|
||||
this.hasQualifiedName("text/tabwriter", "Writer", "Init") and
|
||||
(
|
||||
(inp.isReceiver() or inp.isResult()) and
|
||||
outp.isParameter(0)
|
||||
)
|
||||
or
|
||||
// signature: func (*Writer).Write(buf []byte) (n int, err error)
|
||||
this.hasQualifiedName("text/tabwriter", "Writer", "Write") and
|
||||
(inp.isParameter(0) and outp.isReceiver())
|
||||
}
|
||||
|
||||
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
|
||||
input = inp and output = outp
|
||||
}
|
||||
}
|
||||
}
|
||||
105
ql/src/semmle/go/frameworks/stdlib/TextTemplate.qll
Normal file
105
ql/src/semmle/go/frameworks/stdlib/TextTemplate.qll
Normal file
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* Provides classes modeling security-relevant aspects of the `text/template` package.
|
||||
*/
|
||||
|
||||
import go
|
||||
|
||||
/** Provides models of commonly used functions in the `text/template` package. */
|
||||
module TextTemplate {
|
||||
private class TemplateEscape extends EscapeFunction::Range {
|
||||
string kind;
|
||||
|
||||
TemplateEscape() {
|
||||
exists(string fn |
|
||||
fn.matches("HTMLEscape%") and kind = "html"
|
||||
or
|
||||
fn.matches("JSEscape%") and kind = "js"
|
||||
or
|
||||
fn.matches("URLQueryEscape%") and kind = "url"
|
||||
|
|
||||
this.hasQualifiedName("text/template", fn)
|
||||
or
|
||||
this.hasQualifiedName("html/template", fn)
|
||||
)
|
||||
}
|
||||
|
||||
override string kind() { result = kind }
|
||||
}
|
||||
|
||||
private class TextTemplateInstantiation extends TemplateInstantiation::Range,
|
||||
DataFlow::MethodCallNode {
|
||||
int dataArg;
|
||||
|
||||
TextTemplateInstantiation() {
|
||||
exists(string m | getTarget().hasQualifiedName("text/template", "Template", m) |
|
||||
m = "Execute" and
|
||||
dataArg = 1
|
||||
or
|
||||
m = "ExecuteTemplate" and
|
||||
dataArg = 2
|
||||
)
|
||||
}
|
||||
|
||||
override DataFlow::Node getTemplateArgument() { result = this.getReceiver() }
|
||||
|
||||
override DataFlow::Node getADataArgument() { result = this.getArgument(dataArg) }
|
||||
}
|
||||
|
||||
private class FunctionModels extends TaintTracking::FunctionModel {
|
||||
FunctionInput inp;
|
||||
FunctionOutput outp;
|
||||
|
||||
FunctionModels() {
|
||||
// signature: func HTMLEscape(w io.Writer, b []byte)
|
||||
hasQualifiedName("text/template", "HTMLEscape") and
|
||||
(inp.isParameter(1) and outp.isParameter(0))
|
||||
or
|
||||
// signature: func HTMLEscapeString(s string) string
|
||||
hasQualifiedName("text/template", "HTMLEscapeString") and
|
||||
(inp.isParameter(0) and outp.isResult())
|
||||
or
|
||||
// signature: func HTMLEscaper(args ...interface{}) string
|
||||
hasQualifiedName("text/template", "HTMLEscaper") and
|
||||
(inp.isParameter(_) and outp.isResult())
|
||||
or
|
||||
// signature: func JSEscape(w io.Writer, b []byte)
|
||||
hasQualifiedName("text/template", "JSEscape") and
|
||||
(inp.isParameter(1) and outp.isParameter(0))
|
||||
or
|
||||
// signature: func JSEscapeString(s string) string
|
||||
hasQualifiedName("text/template", "JSEscapeString") and
|
||||
(inp.isParameter(0) and outp.isResult())
|
||||
or
|
||||
// signature: func JSEscaper(args ...interface{}) string
|
||||
hasQualifiedName("text/template", "JSEscaper") and
|
||||
(inp.isParameter(_) and outp.isResult())
|
||||
or
|
||||
// signature: func URLQueryEscaper(args ...interface{}) string
|
||||
hasQualifiedName("text/template", "URLQueryEscaper") and
|
||||
(inp.isParameter(_) and outp.isResult())
|
||||
}
|
||||
|
||||
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
|
||||
input = inp and output = outp
|
||||
}
|
||||
}
|
||||
|
||||
private class MethodModels extends TaintTracking::FunctionModel, Method {
|
||||
FunctionInput inp;
|
||||
FunctionOutput outp;
|
||||
|
||||
MethodModels() {
|
||||
// signature: func (*Template).Execute(wr io.Writer, data interface{}) error
|
||||
this.hasQualifiedName("text/template", "Template", "Execute") and
|
||||
(inp.isParameter(1) and outp.isParameter(0))
|
||||
or
|
||||
// signature: func (*Template).ExecuteTemplate(wr io.Writer, name string, data interface{}) error
|
||||
this.hasQualifiedName("text/template", "Template", "ExecuteTemplate") and
|
||||
(inp.isParameter(2) and outp.isParameter(0))
|
||||
}
|
||||
|
||||
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
|
||||
input = inp and output = outp
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// Code generated by https://github.com/gagliardetto/codebox. DO NOT EDIT.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"text/scanner"
|
||||
)
|
||||
|
||||
func TaintStepTest_TextScannerScannerInit_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromReader656 := sourceCQL.(io.Reader)
|
||||
var intoScanner414 scanner.Scanner
|
||||
intoScanner414.Init(fromReader656)
|
||||
return intoScanner414
|
||||
}
|
||||
|
||||
func TaintStepTest_TextScannerScannerInit_B0I0O1(sourceCQL interface{}) interface{} {
|
||||
fromReader518 := sourceCQL.(io.Reader)
|
||||
var mediumObjCQL scanner.Scanner
|
||||
intoScanner650 := mediumObjCQL.Init(fromReader518)
|
||||
return intoScanner650
|
||||
}
|
||||
|
||||
func TaintStepTest_TextScannerScannerTokenText_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromScanner784 := sourceCQL.(scanner.Scanner)
|
||||
intoString957 := fromScanner784.TokenText()
|
||||
return intoString957
|
||||
}
|
||||
|
||||
func RunAllTaints_TextScanner() {
|
||||
{
|
||||
source := newSource(0)
|
||||
out := TaintStepTest_TextScannerScannerInit_B0I0O0(source)
|
||||
sink(0, out)
|
||||
}
|
||||
{
|
||||
source := newSource(1)
|
||||
out := TaintStepTest_TextScannerScannerInit_B0I0O1(source)
|
||||
sink(1, out)
|
||||
}
|
||||
{
|
||||
source := newSource(2)
|
||||
out := TaintStepTest_TextScannerScannerTokenText_B0I0O0(source)
|
||||
sink(2, out)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// Code generated by https://github.com/gagliardetto/codebox. DO NOT EDIT.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"text/tabwriter"
|
||||
)
|
||||
|
||||
func TaintStepTest_TextTabwriterNewWriter_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromWriter656 := sourceCQL.(*tabwriter.Writer)
|
||||
var intoWriter414 io.Writer
|
||||
intermediateCQL := tabwriter.NewWriter(intoWriter414, 0, 0, 0, 0, 0)
|
||||
link(fromWriter656, intermediateCQL)
|
||||
return intoWriter414
|
||||
}
|
||||
|
||||
func TaintStepTest_TextTabwriterWriterInit_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromWriter518 := sourceCQL.(tabwriter.Writer)
|
||||
var intoWriter650 io.Writer
|
||||
fromWriter518.Init(intoWriter650, 0, 0, 0, 0, 0)
|
||||
return intoWriter650
|
||||
}
|
||||
|
||||
func TaintStepTest_TextTabwriterWriterInit_B0I1O0(sourceCQL interface{}) interface{} {
|
||||
fromWriter784 := sourceCQL.(*tabwriter.Writer)
|
||||
var intoWriter957 io.Writer
|
||||
var mediumObjCQL tabwriter.Writer
|
||||
intermediateCQL := mediumObjCQL.Init(intoWriter957, 0, 0, 0, 0, 0)
|
||||
link(fromWriter784, intermediateCQL)
|
||||
return intoWriter957
|
||||
}
|
||||
|
||||
func TaintStepTest_TextTabwriterWriterWrite_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromByte520 := sourceCQL.([]byte)
|
||||
var intoWriter443 tabwriter.Writer
|
||||
intoWriter443.Write(fromByte520)
|
||||
return intoWriter443
|
||||
}
|
||||
|
||||
func RunAllTaints_TextTabwriter() {
|
||||
{
|
||||
source := newSource(0)
|
||||
out := TaintStepTest_TextTabwriterNewWriter_B0I0O0(source)
|
||||
sink(0, out)
|
||||
}
|
||||
{
|
||||
source := newSource(1)
|
||||
out := TaintStepTest_TextTabwriterWriterInit_B0I0O0(source)
|
||||
sink(1, out)
|
||||
}
|
||||
{
|
||||
source := newSource(2)
|
||||
out := TaintStepTest_TextTabwriterWriterInit_B0I1O0(source)
|
||||
sink(2, out)
|
||||
}
|
||||
{
|
||||
source := newSource(3)
|
||||
out := TaintStepTest_TextTabwriterWriterWrite_B0I0O0(source)
|
||||
sink(3, out)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
// Code generated by https://github.com/gagliardetto/codebox. DO NOT EDIT.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
func TaintStepTest_TextTemplateHTMLEscape_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromByte656 := sourceCQL.([]byte)
|
||||
var intoWriter414 io.Writer
|
||||
template.HTMLEscape(intoWriter414, fromByte656)
|
||||
return intoWriter414
|
||||
}
|
||||
|
||||
func TaintStepTest_TextTemplateHTMLEscapeString_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromString518 := sourceCQL.(string)
|
||||
intoString650 := template.HTMLEscapeString(fromString518)
|
||||
return intoString650
|
||||
}
|
||||
|
||||
func TaintStepTest_TextTemplateHTMLEscaper_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromInterface784 := sourceCQL.(interface{})
|
||||
intoString957 := template.HTMLEscaper(fromInterface784)
|
||||
return intoString957
|
||||
}
|
||||
|
||||
func TaintStepTest_TextTemplateJSEscape_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromByte520 := sourceCQL.([]byte)
|
||||
var intoWriter443 io.Writer
|
||||
template.JSEscape(intoWriter443, fromByte520)
|
||||
return intoWriter443
|
||||
}
|
||||
|
||||
func TaintStepTest_TextTemplateJSEscapeString_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromString127 := sourceCQL.(string)
|
||||
intoString483 := template.JSEscapeString(fromString127)
|
||||
return intoString483
|
||||
}
|
||||
|
||||
func TaintStepTest_TextTemplateJSEscaper_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromInterface989 := sourceCQL.(interface{})
|
||||
intoString982 := template.JSEscaper(fromInterface989)
|
||||
return intoString982
|
||||
}
|
||||
|
||||
func TaintStepTest_TextTemplateURLQueryEscaper_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromInterface417 := sourceCQL.(interface{})
|
||||
intoString584 := template.URLQueryEscaper(fromInterface417)
|
||||
return intoString584
|
||||
}
|
||||
|
||||
func TaintStepTest_TextTemplateTemplateExecute_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromInterface991 := sourceCQL.(interface{})
|
||||
var intoWriter881 io.Writer
|
||||
var mediumObjCQL template.Template
|
||||
mediumObjCQL.Execute(intoWriter881, fromInterface991)
|
||||
return intoWriter881
|
||||
}
|
||||
|
||||
func TaintStepTest_TextTemplateTemplateExecuteTemplate_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromInterface186 := sourceCQL.(interface{})
|
||||
var intoWriter284 io.Writer
|
||||
var mediumObjCQL template.Template
|
||||
mediumObjCQL.ExecuteTemplate(intoWriter284, "", fromInterface186)
|
||||
return intoWriter284
|
||||
}
|
||||
|
||||
func RunAllTaints_TextTemplate() {
|
||||
{
|
||||
source := newSource(0)
|
||||
out := TaintStepTest_TextTemplateHTMLEscape_B0I0O0(source)
|
||||
sink(0, out)
|
||||
}
|
||||
{
|
||||
source := newSource(1)
|
||||
out := TaintStepTest_TextTemplateHTMLEscapeString_B0I0O0(source)
|
||||
sink(1, out)
|
||||
}
|
||||
{
|
||||
source := newSource(2)
|
||||
out := TaintStepTest_TextTemplateHTMLEscaper_B0I0O0(source)
|
||||
sink(2, out)
|
||||
}
|
||||
{
|
||||
source := newSource(3)
|
||||
out := TaintStepTest_TextTemplateJSEscape_B0I0O0(source)
|
||||
sink(3, out)
|
||||
}
|
||||
{
|
||||
source := newSource(4)
|
||||
out := TaintStepTest_TextTemplateJSEscapeString_B0I0O0(source)
|
||||
sink(4, out)
|
||||
}
|
||||
{
|
||||
source := newSource(5)
|
||||
out := TaintStepTest_TextTemplateJSEscaper_B0I0O0(source)
|
||||
sink(5, out)
|
||||
}
|
||||
{
|
||||
source := newSource(6)
|
||||
out := TaintStepTest_TextTemplateURLQueryEscaper_B0I0O0(source)
|
||||
sink(6, out)
|
||||
}
|
||||
{
|
||||
source := newSource(7)
|
||||
out := TaintStepTest_TextTemplateTemplateExecute_B0I0O0(source)
|
||||
sink(7, out)
|
||||
}
|
||||
{
|
||||
source := newSource(8)
|
||||
out := TaintStepTest_TextTemplateTemplateExecuteTemplate_B0I0O0(source)
|
||||
sink(8, out)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user