Merge pull request #321 from gagliardetto/standard-lib-pt-14

Add taint-tracking for packages inside `mime/*`
This commit is contained in:
Max Schaefer
2020-09-14 09:26:29 +01:00
committed by GitHub
7 changed files with 474 additions and 0 deletions

View File

@@ -12,6 +12,9 @@ import semmle.go.frameworks.stdlib.CompressFlate
import semmle.go.frameworks.stdlib.CompressGzip
import semmle.go.frameworks.stdlib.CompressLzw
import semmle.go.frameworks.stdlib.CompressZlib
import semmle.go.frameworks.stdlib.Mime
import semmle.go.frameworks.stdlib.MimeMultipart
import semmle.go.frameworks.stdlib.MimeQuotedprintable
import semmle.go.frameworks.stdlib.Path
import semmle.go.frameworks.stdlib.PathFilepath
import semmle.go.frameworks.stdlib.Reflect

View File

@@ -0,0 +1,50 @@
/**
* Provides classes modeling security-relevant aspects of the `mime` package.
*/
import go
/** Provides models of commonly used functions in the `mime` package. */
module Mime {
private class FunctionModels extends TaintTracking::FunctionModel {
FunctionInput inp;
FunctionOutput outp;
FunctionModels() {
// signature: func FormatMediaType(t string, param map[string]string) string
hasQualifiedName("mime", "FormatMediaType") and
(inp.isParameter(_) and outp.isResult())
or
// signature: func ParseMediaType(v string) (mediatype string, params map[string]string, err error)
hasQualifiedName("mime", "ParseMediaType") and
(inp.isParameter(0) and outp.isResult([0, 1]))
}
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 (*WordDecoder).Decode(word string) (string, error)
this.hasQualifiedName("mime", "WordDecoder", "Decode") and
(inp.isParameter(0) and outp.isResult(0))
or
// signature: func (*WordDecoder).DecodeHeader(header string) (string, error)
this.hasQualifiedName("mime", "WordDecoder", "DecodeHeader") and
(inp.isParameter(0) and outp.isResult(0))
or
// signature: func (WordEncoder).Encode(charset string, s string) string
this.hasQualifiedName("mime", "WordEncoder", "Encode") and
(inp.isParameter(1) and outp.isResult())
}
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
input = inp and output = outp
}
}
}

View File

@@ -0,0 +1,74 @@
/**
* Provides classes modeling security-relevant aspects of the `mime/multipart` package.
*/
import go
/** Provides models of commonly used functions in the `mime/multipart` package. */
module MimeMultipart {
private class FunctionModels extends TaintTracking::FunctionModel {
FunctionInput inp;
FunctionOutput outp;
FunctionModels() {
// signature: func NewReader(r io.Reader, boundary string) *Reader
hasQualifiedName("mime/multipart", "NewReader") and
(inp.isParameter(0) and outp.isResult())
or
// signature: func NewWriter(w io.Writer) *Writer
hasQualifiedName("mime/multipart", "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 (*FileHeader).Open() (File, error)
this.hasQualifiedName("mime/multipart", "FileHeader", "Open") and
(inp.isReceiver() and outp.isResult(0))
or
// signature: func (*Part).Read(d []byte) (n int, err error)
this.hasQualifiedName("mime/multipart", "Part", "Read") and
(inp.isReceiver() and outp.isParameter(0))
or
// signature: func (*Reader).NextPart() (*Part, error)
this.hasQualifiedName("mime/multipart", "Reader", "NextPart") and
(inp.isReceiver() and outp.isResult(0))
or
// signature: func (*Reader).NextRawPart() (*Part, error)
this.hasQualifiedName("mime/multipart", "Reader", "NextRawPart") and
(inp.isReceiver() and outp.isResult(0))
or
// signature: func (*Reader).ReadForm(maxMemory int64) (*Form, error)
this.hasQualifiedName("mime/multipart", "Reader", "ReadForm") and
(inp.isReceiver() and outp.isResult(0))
or
// signature: func (*Writer).CreateFormField(fieldname string) (io.Writer, error)
this.hasQualifiedName("mime/multipart", "Writer", "CreateFormField") and
(inp.isResult(0) and outp.isReceiver())
or
// signature: func (*Writer).CreateFormFile(fieldname string, filename string) (io.Writer, error)
this.hasQualifiedName("mime/multipart", "Writer", "CreateFormFile") and
(inp.isResult(0) and outp.isReceiver())
or
// signature: func (*Writer).CreatePart(header net/textproto.MIMEHeader) (io.Writer, error)
this.hasQualifiedName("mime/multipart", "Writer", "CreatePart") and
(inp.isResult(0) and outp.isReceiver())
or
// signature: func (*Writer).WriteField(fieldname string, value string) error
this.hasQualifiedName("mime/multipart", "Writer", "WriteField") and
(inp.isParameter(_) and outp.isReceiver())
}
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
input = inp and output = outp
}
}
}

View File

@@ -0,0 +1,46 @@
/**
* Provides classes modeling security-relevant aspects of the `mime/quotedprintable` package.
*/
import go
/** Provides models of commonly used functions in the `mime/quotedprintable` package. */
module MimeQuotedprintable {
private class FunctionModels extends TaintTracking::FunctionModel {
FunctionInput inp;
FunctionOutput outp;
FunctionModels() {
// signature: func NewReader(r io.Reader) *Reader
hasQualifiedName("mime/quotedprintable", "NewReader") and
(inp.isParameter(0) and outp.isResult())
or
// signature: func NewWriter(w io.Writer) *Writer
hasQualifiedName("mime/quotedprintable", "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 (*Reader).Read(p []byte) (n int, err error)
this.hasQualifiedName("mime/quotedprintable", "Reader", "Read") and
(inp.isReceiver() and outp.isParameter(0))
or
// signature: func (*Writer).Write(p []byte) (n int, err error)
this.hasQualifiedName("mime/quotedprintable", "Writer", "Write") and
(inp.isParameter(0) and outp.isReceiver())
}
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
input = inp and output = outp
}
}
}

View File

@@ -0,0 +1,88 @@
// Code generated by https://github.com/gagliardetto/codebox. DO NOT EDIT.
package main
import "mime"
func TaintStepTest_MimeFormatMediaType_B0I0O0(sourceCQL interface{}) interface{} {
fromString656 := sourceCQL.(string)
intoString414 := mime.FormatMediaType(fromString656, nil)
return intoString414
}
func TaintStepTest_MimeFormatMediaType_B0I1O0(sourceCQL interface{}) interface{} {
fromMapstringstring518 := sourceCQL.(map[string]string)
intoString650 := mime.FormatMediaType("", fromMapstringstring518)
return intoString650
}
func TaintStepTest_MimeParseMediaType_B0I0O0(sourceCQL interface{}) interface{} {
fromString784 := sourceCQL.(string)
intoString957, _, _ := mime.ParseMediaType(fromString784)
return intoString957
}
func TaintStepTest_MimeParseMediaType_B0I0O1(sourceCQL interface{}) interface{} {
fromString520 := sourceCQL.(string)
_, intoMapstringstring443, _ := mime.ParseMediaType(fromString520)
return intoMapstringstring443
}
func TaintStepTest_MimeWordDecoderDecode_B0I0O0(sourceCQL interface{}) interface{} {
fromString127 := sourceCQL.(string)
var mediumObjCQL mime.WordDecoder
intoString483, _ := mediumObjCQL.Decode(fromString127)
return intoString483
}
func TaintStepTest_MimeWordDecoderDecodeHeader_B0I0O0(sourceCQL interface{}) interface{} {
fromString989 := sourceCQL.(string)
var mediumObjCQL mime.WordDecoder
intoString982, _ := mediumObjCQL.DecodeHeader(fromString989)
return intoString982
}
func TaintStepTest_MimeWordEncoderEncode_B0I0O0(sourceCQL interface{}) interface{} {
fromString417 := sourceCQL.(string)
var mediumObjCQL mime.WordEncoder
intoString584 := mediumObjCQL.Encode("", fromString417)
return intoString584
}
func RunAllTaints_Mime() {
{
source := newSource(0)
out := TaintStepTest_MimeFormatMediaType_B0I0O0(source)
sink(0, out)
}
{
source := newSource(1)
out := TaintStepTest_MimeFormatMediaType_B0I1O0(source)
sink(1, out)
}
{
source := newSource(2)
out := TaintStepTest_MimeParseMediaType_B0I0O0(source)
sink(2, out)
}
{
source := newSource(3)
out := TaintStepTest_MimeParseMediaType_B0I0O1(source)
sink(3, out)
}
{
source := newSource(4)
out := TaintStepTest_MimeWordDecoderDecode_B0I0O0(source)
sink(4, out)
}
{
source := newSource(5)
out := TaintStepTest_MimeWordDecoderDecodeHeader_B0I0O0(source)
sink(5, out)
}
{
source := newSource(6)
out := TaintStepTest_MimeWordEncoderEncode_B0I0O0(source)
sink(6, out)
}
}

View File

@@ -0,0 +1,154 @@
// Code generated by https://github.com/gagliardetto/codebox. DO NOT EDIT.
package main
import (
"io"
"mime/multipart"
)
func TaintStepTest_MimeMultipartNewReader_B0I0O0(sourceCQL interface{}) interface{} {
fromReader656 := sourceCQL.(io.Reader)
intoReader414 := multipart.NewReader(fromReader656, "")
return intoReader414
}
func TaintStepTest_MimeMultipartNewWriter_B0I0O0(sourceCQL interface{}) interface{} {
fromWriter518 := sourceCQL.(*multipart.Writer)
var intoWriter650 io.Writer
intermediateCQL := multipart.NewWriter(intoWriter650)
link(fromWriter518, intermediateCQL)
return intoWriter650
}
func TaintStepTest_MimeMultipartFileHeaderOpen_B0I0O0(sourceCQL interface{}) interface{} {
fromFileHeader784 := sourceCQL.(multipart.FileHeader)
intoFile957, _ := fromFileHeader784.Open()
return intoFile957
}
func TaintStepTest_MimeMultipartPartRead_B0I0O0(sourceCQL interface{}) interface{} {
fromPart520 := sourceCQL.(multipart.Part)
var intoByte443 []byte
fromPart520.Read(intoByte443)
return intoByte443
}
func TaintStepTest_MimeMultipartReaderNextPart_B0I0O0(sourceCQL interface{}) interface{} {
fromReader127 := sourceCQL.(multipart.Reader)
intoPart483, _ := fromReader127.NextPart()
return intoPart483
}
func TaintStepTest_MimeMultipartReaderNextRawPart_B0I0O0(sourceCQL interface{}) interface{} {
fromReader989 := sourceCQL.(multipart.Reader)
intoPart982, _ := fromReader989.NextRawPart()
return intoPart982
}
func TaintStepTest_MimeMultipartReaderReadForm_B0I0O0(sourceCQL interface{}) interface{} {
fromReader417 := sourceCQL.(multipart.Reader)
intoForm584, _ := fromReader417.ReadForm(0)
return intoForm584
}
func TaintStepTest_MimeMultipartWriterCreateFormField_B0I0O0(sourceCQL interface{}) interface{} {
fromWriter991 := sourceCQL.(io.Writer)
var intoWriter881 multipart.Writer
intermediateCQL, _ := intoWriter881.CreateFormField("")
link(fromWriter991, intermediateCQL)
return intoWriter881
}
func TaintStepTest_MimeMultipartWriterCreateFormFile_B0I0O0(sourceCQL interface{}) interface{} {
fromWriter186 := sourceCQL.(io.Writer)
var intoWriter284 multipart.Writer
intermediateCQL, _ := intoWriter284.CreateFormFile("", "")
link(fromWriter186, intermediateCQL)
return intoWriter284
}
func TaintStepTest_MimeMultipartWriterCreatePart_B0I0O0(sourceCQL interface{}) interface{} {
fromWriter908 := sourceCQL.(io.Writer)
var intoWriter137 multipart.Writer
intermediateCQL, _ := intoWriter137.CreatePart(nil)
link(fromWriter908, intermediateCQL)
return intoWriter137
}
func TaintStepTest_MimeMultipartWriterWriteField_B0I0O0(sourceCQL interface{}) interface{} {
fromString494 := sourceCQL.(string)
var intoWriter873 multipart.Writer
intoWriter873.WriteField(fromString494, "")
return intoWriter873
}
func TaintStepTest_MimeMultipartWriterWriteField_B0I1O0(sourceCQL interface{}) interface{} {
fromString599 := sourceCQL.(string)
var intoWriter409 multipart.Writer
intoWriter409.WriteField("", fromString599)
return intoWriter409
}
func RunAllTaints_MimeMultipart() {
{
source := newSource(0)
out := TaintStepTest_MimeMultipartNewReader_B0I0O0(source)
sink(0, out)
}
{
source := newSource(1)
out := TaintStepTest_MimeMultipartNewWriter_B0I0O0(source)
sink(1, out)
}
{
source := newSource(2)
out := TaintStepTest_MimeMultipartFileHeaderOpen_B0I0O0(source)
sink(2, out)
}
{
source := newSource(3)
out := TaintStepTest_MimeMultipartPartRead_B0I0O0(source)
sink(3, out)
}
{
source := newSource(4)
out := TaintStepTest_MimeMultipartReaderNextPart_B0I0O0(source)
sink(4, out)
}
{
source := newSource(5)
out := TaintStepTest_MimeMultipartReaderNextRawPart_B0I0O0(source)
sink(5, out)
}
{
source := newSource(6)
out := TaintStepTest_MimeMultipartReaderReadForm_B0I0O0(source)
sink(6, out)
}
{
source := newSource(7)
out := TaintStepTest_MimeMultipartWriterCreateFormField_B0I0O0(source)
sink(7, out)
}
{
source := newSource(8)
out := TaintStepTest_MimeMultipartWriterCreateFormFile_B0I0O0(source)
sink(8, out)
}
{
source := newSource(9)
out := TaintStepTest_MimeMultipartWriterCreatePart_B0I0O0(source)
sink(9, out)
}
{
source := newSource(10)
out := TaintStepTest_MimeMultipartWriterWriteField_B0I0O0(source)
sink(10, out)
}
{
source := newSource(11)
out := TaintStepTest_MimeMultipartWriterWriteField_B0I1O0(source)
sink(11, out)
}
}

View File

@@ -0,0 +1,59 @@
// Code generated by https://github.com/gagliardetto/codebox. DO NOT EDIT.
package main
import (
"io"
"mime/quotedprintable"
)
func TaintStepTest_MimeQuotedprintableNewReader_B0I0O0(sourceCQL interface{}) interface{} {
fromReader656 := sourceCQL.(io.Reader)
intoReader414 := quotedprintable.NewReader(fromReader656)
return intoReader414
}
func TaintStepTest_MimeQuotedprintableNewWriter_B0I0O0(sourceCQL interface{}) interface{} {
fromWriter518 := sourceCQL.(*quotedprintable.Writer)
var intoWriter650 io.Writer
intermediateCQL := quotedprintable.NewWriter(intoWriter650)
link(fromWriter518, intermediateCQL)
return intoWriter650
}
func TaintStepTest_MimeQuotedprintableReaderRead_B0I0O0(sourceCQL interface{}) interface{} {
fromReader784 := sourceCQL.(quotedprintable.Reader)
var intoByte957 []byte
fromReader784.Read(intoByte957)
return intoByte957
}
func TaintStepTest_MimeQuotedprintableWriterWrite_B0I0O0(sourceCQL interface{}) interface{} {
fromByte520 := sourceCQL.([]byte)
var intoWriter443 quotedprintable.Writer
intoWriter443.Write(fromByte520)
return intoWriter443
}
func RunAllTaints_MimeQuotedprintable() {
{
source := newSource(0)
out := TaintStepTest_MimeQuotedprintableNewReader_B0I0O0(source)
sink(0, out)
}
{
source := newSource(1)
out := TaintStepTest_MimeQuotedprintableNewWriter_B0I0O0(source)
sink(1, out)
}
{
source := newSource(2)
out := TaintStepTest_MimeQuotedprintableReaderRead_B0I0O0(source)
sink(2, out)
}
{
source := newSource(3)
out := TaintStepTest_MimeQuotedprintableWriterWrite_B0I0O0(source)
sink(3, out)
}
}