Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 742319c

Browse files
committed
Move to stdlib and expand crypto/cypher package taint-tracking
1 parent 434c4bc commit 742319c

File tree

3 files changed

+109
-12
lines changed

3 files changed

+109
-12
lines changed

ql/src/semmle/go/frameworks/Stdlib.qll

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import semmle.go.frameworks.stdlib.CompressLzw
1414
import semmle.go.frameworks.stdlib.CompressZlib
1515
import semmle.go.frameworks.stdlib.Fmt
1616
import semmle.go.frameworks.stdlib.Crypto
17+
import semmle.go.frameworks.stdlib.CryptoCipher
1718
import semmle.go.frameworks.stdlib.Mime
1819
import semmle.go.frameworks.stdlib.MimeMultipart
1920
import semmle.go.frameworks.stdlib.MimeQuotedprintable
@@ -509,15 +510,3 @@ module Log {
509510
override predicate mayReturnNormally() { none() }
510511
}
511512
}
512-
513-
/** Provides models of some functions in the `crypto/cipher` package. */
514-
module CryptoCipher {
515-
private class AeadOpenFunction extends TaintTracking::FunctionModel, Method {
516-
AeadOpenFunction() { this.hasQualifiedName("crypto/cipher", "AEAD", "Open") }
517-
518-
override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) {
519-
inp.isParameter(2) and
520-
outp.isResult(0)
521-
}
522-
}
523-
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `crypto/cipher` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `crypto/cipher` package. */
8+
module CryptoCipher {
9+
private class MethodModels extends TaintTracking::FunctionModel, Method {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
MethodModels() {
14+
// signature: func (StreamReader).Read(dst []byte) (n int, err error)
15+
this.hasQualifiedName("crypto/cipher", "StreamReader", "Read") and
16+
(inp.isReceiver() and outp.isParameter(0))
17+
or
18+
// signature: func (StreamWriter).Write(src []byte) (n int, err error)
19+
this.hasQualifiedName("crypto/cipher", "StreamWriter", "Write") and
20+
(inp.isParameter(0) and outp.isReceiver())
21+
or
22+
// signature: func (Block).Decrypt(dst []byte, src []byte)
23+
this.implements("crypto/cipher", "Block", "Decrypt") and
24+
(inp.isParameter(1) and outp.isParameter(0))
25+
or
26+
// signature: func (AEAD).Open(dst []byte, nonce []byte, ciphertext []byte, additionalData []byte) ([]byte, error)
27+
this.implements("crypto/cipher", "AEAD", "Open") and
28+
(
29+
inp.isParameter(2) and
30+
(outp.isParameter(0) or outp.isResult(0))
31+
)
32+
}
33+
34+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
35+
input = inp and output = outp
36+
}
37+
}
38+
}

ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/CryptoCipher.go

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)