diff --git a/go/ql/lib/ext/context.model.json b/go/ql/lib/ext/context.model.json index df19e09dc905..40c4d9237b71 100644 --- a/go/ql/lib/ext/context.model.json +++ b/go/ql/lib/ext/context.model.json @@ -6,10 +6,16 @@ "extensible": "summaryModel" }, "data": [ + // AfterFunc should be modeled when callback-based library models are supported. ["context", "", false, "WithCancel", "", "", "Argument[0]", "ReturnValue[0]", "taint", "manual"], ["context", "", false, "WithDeadline", "", "", "Argument[0]", "ReturnValue[0]", "taint", "manual"], + ["context", "", false, "WithDeadlineCause", "", "", "Argument[0]", "ReturnValue[0]", "taint", "manual"], + ["context", "", false, "WithDeadlineCause", "", "", "Argument[2]", "ReturnValue[0]", "taint", "manual"], ["context", "", false, "WithTimeout", "", "", "Argument[0]", "ReturnValue[0]", "taint", "manual"], + ["context", "", false, "WithTimeoutCause", "", "", "Argument[0]", "ReturnValue[0]", "taint", "manual"], + ["context", "", false, "WithTimeoutCause", "", "", "Argument[2]", "ReturnValue[0]", "taint", "manual"], ["context", "", false, "WithValue", "", "", "Argument[0..2]", "ReturnValue", "taint", "manual"], + ["context", "", false, "WithoutCancel", "", "", "Argument[0]", "ReturnValue", "taint", "manual"], ["context", "Context", true, "Value", "", "", "Argument[receiver]", "ReturnValue", "taint", "manual"] ] } diff --git a/go/ql/lib/ext/crypto.tls.model.json b/go/ql/lib/ext/crypto.tls.model.json index f289d1741465..f52467acb382 100644 --- a/go/ql/lib/ext/crypto.tls.model.json +++ b/go/ql/lib/ext/crypto.tls.model.json @@ -7,8 +7,22 @@ }, "data": [ ["crypto/tls", "", false, "Client", "", "", "Argument[0]", "ReturnValue", "taint", "manual"], + ["crypto/tls", "", false, "NewResumptionState", "", "", "Argument[0..1]", "ReturnValue[0]", "taint", "manual"], ["crypto/tls", "", false, "NewListener", "", "", "Argument[0]", "ReturnValue", "taint", "manual"], - ["crypto/tls", "", false, "Server", "", "", "Argument[0]", "ReturnValue", "taint", "manual"] + ["crypto/tls", "", false, "ParseSessionState", "", "", "Argument[0]", "ReturnValue[0]", "taint", "manual"], + ["crypto/tls", "", false, "QUICClient", "", "", "Argument[0]", "ReturnValue", "taint", "manual"], + ["crypto/tls", "", false, "QUICServer", "", "", "Argument[0]", "ReturnValue", "taint", "manual"], + ["crypto/tls", "", false, "Server", "", "", "Argument[0]", "ReturnValue", "taint", "manual"], + ["crypto/tls", "ClientSessionState", true, "ResumptionState", "", "", "Argument[receiver]", "ReturnValue[0..1]", "taint", "manual"], + ["crypto/tls", "Config", true, "DecryptTicket", "", "", "Argument[receiver]", "ReturnValue[0]", "taint", "manual"], + ["crypto/tls", "Config", true, "DecryptTicket", "", "", "Argument[0..1]", "ReturnValue[0]", "taint", "manual"], + ["crypto/tls", "Config", true, "EncryptTicket", "", "", "Argument[receiver]", "ReturnValue[0]", "taint", "manual"], + ["crypto/tls", "Config", true, "EncryptTicket", "", "", "Argument[0..1]", "ReturnValue[0]", "taint", "manual"], + ["crypto/tls", "QUICConn", true, "ConnectionState", "", "", "Argument[receiver]", "ReturnValue", "taint", "manual"], + ["crypto/tls", "QUICConn", true, "HandleData", "", "", "Argument[1]", "Argument[receiver]", "taint", "manual"], + ["crypto/tls", "QUICConn", true, "NextEvent", "", "", "Argument[receiver]", "ReturnValue", "taint", "manual"], + ["crypto/tls", "QUICConn", true, "SetTransportParameters", "", "", "Argument[0]", "Argument[receiver]", "taint", "manual"], + ["crypto/tls", "SessionState", true, "Bytes", "", "", "Argument[receiver]", "ReturnValue[0]", "taint", "manual"] ] } ] diff --git a/go/ql/lib/ext/io.fs.model.json b/go/ql/lib/ext/io.fs.model.json index 394b1e956a8e..29048bedabb5 100644 --- a/go/ql/lib/ext/io.fs.model.json +++ b/go/ql/lib/ext/io.fs.model.json @@ -7,6 +7,8 @@ }, "data": [ ["io/fs", "", false, "FileInfoToDirEntry", "", "", "Argument[0]", "ReturnValue", "taint", "manual"], + ["io/fs", "", false, "FormatDirEntry", "", "", "Argument[0]", "ReturnValue", "taint", "manual"], + ["io/fs", "", false, "FormatFileInfo", "", "", "Argument[0]", "ReturnValue", "taint", "manual"], ["io/fs", "", false, "Glob", "", "", "Argument[0]", "ReturnValue[0]", "taint", "manual"], ["io/fs", "", false, "ReadDir", "", "", "Argument[0]", "ReturnValue[0]", "taint", "manual"], ["io/fs", "", false, "ReadFile", "", "", "Argument[0]", "ReturnValue[0]", "taint", "manual"], diff --git a/go/ql/lib/ext/math.big.model.json b/go/ql/lib/ext/math.big.model.json index fa82de328537..a2f2fea2333a 100644 --- a/go/ql/lib/ext/math.big.model.json +++ b/go/ql/lib/ext/math.big.model.json @@ -6,6 +6,7 @@ "extensible": "summaryModel" }, "data": [ + ["math/big", "Int", true, "Float64", "", "", "Argument[receiver]", "ReturnValue[0]", "taint", "manual"], ["math/big", "Int", true, "Int64", "", "", "Argument[receiver]", "ReturnValue[0]", "taint", "manual"] ] } diff --git a/go/ql/src/change-notes/2026-09-30-model-go1.21-minor-library-changes.md b/go/ql/src/change-notes/2026-09-30-model-go1.21-minor-library-changes.md new file mode 100644 index 000000000000..38fcf403bb04 --- /dev/null +++ b/go/ql/src/change-notes/2026-09-30-model-go1.21-minor-library-changes.md @@ -0,0 +1,4 @@ +--- +category: minorAnalysis +--- +* Added data flow models for APIs mentioned in the minor library changes section of the Go 1.21 release notes. diff --git a/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/Context.go b/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/Context.go index 5b526f3b8c0a..bce42b1ca3fa 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/Context.go +++ b/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/Context.go @@ -26,6 +26,35 @@ func TaintStepTest_ContextWithTimeout_B0I0O0(sourceCQL interface{}) interface{} return intoContext957 } +func TaintStepTest_ContextWithDeadlineCauseContext(sourceCQL interface{}) interface{} { + fromContext := sourceCQL.(context.Context) + intoContext, _ := context.WithDeadlineCause(fromContext, time.Time{}, nil) + return intoContext +} + +func TaintStepTest_ContextWithDeadlineCauseError(sourceCQL interface{}) interface{} { + fromError := sourceCQL.(error) + intoContext, _ := context.WithDeadlineCause(nil, time.Time{}, fromError) + return intoContext +} + +func TaintStepTest_ContextWithTimeoutCauseContext(sourceCQL interface{}) interface{} { + fromContext := sourceCQL.(context.Context) + intoContext, _ := context.WithTimeoutCause(fromContext, 0, nil) + return intoContext +} + +func TaintStepTest_ContextWithTimeoutCauseError(sourceCQL interface{}) interface{} { + fromError := sourceCQL.(error) + intoContext, _ := context.WithTimeoutCause(nil, 0, fromError) + return intoContext +} + +func TaintStepTest_ContextWithoutCancel(sourceCQL interface{}) interface{} { + fromContext := sourceCQL.(context.Context) + return context.WithoutCancel(fromContext) +} + func TaintStepTest_ContextWithValue_B0I0O0(sourceCQL interface{}) interface{} { fromContext520 := sourceCQL.(context.Context) intoContext443 := context.WithValue(fromContext520, nil, nil) @@ -163,4 +192,29 @@ func RunAllTaints_Context() { out := TaintStepTest_OldContextContextValue_B0I0O0(source) sink(13, out) } + { + source := newSource(14) + out := TaintStepTest_ContextWithDeadlineCauseContext(source) + sink(14, out) + } + { + source := newSource(15) + out := TaintStepTest_ContextWithDeadlineCauseError(source) + sink(15, out) + } + { + source := newSource(16) + out := TaintStepTest_ContextWithTimeoutCauseContext(source) + sink(16, out) + } + { + source := newSource(17) + out := TaintStepTest_ContextWithTimeoutCauseError(source) + sink(17, out) + } + { + source := newSource(18) + out := TaintStepTest_ContextWithoutCancel(source) + sink(18, out) + } } diff --git a/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/CryptoTls.go b/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/CryptoTls.go index a35f30a1a991..2a5c81c651f0 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/CryptoTls.go +++ b/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/CryptoTls.go @@ -55,6 +55,71 @@ func TaintStepTest_CryptoTlsConnWrite_B0I0O0(sourceCQL interface{}) interface{} return intoConn584 } +func TaintStepTest_CryptoTlsSessionStateBytes(sourceCQL interface{}) interface{} { + out, _ := sourceCQL.(*tls.SessionState).Bytes() + return out +} + +func TaintStepTest_CryptoTlsParseSessionState(sourceCQL interface{}) interface{} { + out, _ := tls.ParseSessionState(sourceCQL.([]byte)) + return out +} + +func TaintStepTest_CryptoTlsNewResumptionStateTicket(sourceCQL interface{}) interface{} { + out, _ := tls.NewResumptionState(sourceCQL.([]byte), nil) + return out +} + +func TaintStepTest_CryptoTlsNewResumptionStateState(sourceCQL interface{}) interface{} { + out, _ := tls.NewResumptionState(nil, sourceCQL.(*tls.SessionState)) + return out +} + +func TaintStepTest_CryptoTlsClientSessionStateResumptionState(sourceCQL interface{}) interface{} { + ticket, _, _ := sourceCQL.(*tls.ClientSessionState).ResumptionState() + return ticket +} + +func TaintStepTest_CryptoTlsConfigEncryptTicketState(sourceCQL interface{}) interface{} { + var config tls.Config + out, _ := config.EncryptTicket(tls.ConnectionState{}, sourceCQL.(*tls.SessionState)) + return out +} + +func TaintStepTest_CryptoTlsConfigDecryptTicket(sourceCQL interface{}) interface{} { + var config tls.Config + out, _ := config.DecryptTicket(sourceCQL.([]byte), tls.ConnectionState{}) + return out +} + +func TaintStepTest_CryptoTlsQUICClient(sourceCQL interface{}) interface{} { + return tls.QUICClient(sourceCQL.(*tls.QUICConfig)) +} + +func TaintStepTest_CryptoTlsQUICServer(sourceCQL interface{}) interface{} { + return tls.QUICServer(sourceCQL.(*tls.QUICConfig)) +} + +func TaintStepTest_CryptoTlsQUICConnHandleData(sourceCQL interface{}) interface{} { + conn := tls.QUICClient(&tls.QUICConfig{}) + conn.HandleData(tls.QUICEncryptionLevelInitial, sourceCQL.([]byte)) + return conn +} + +func TaintStepTest_CryptoTlsQUICConnNextEvent(sourceCQL interface{}) interface{} { + return sourceCQL.(*tls.QUICConn).NextEvent() +} + +func TaintStepTest_CryptoTlsQUICConnConnectionState(sourceCQL interface{}) interface{} { + return sourceCQL.(*tls.QUICConn).ConnectionState() +} + +func TaintStepTest_CryptoTlsQUICConnSetTransportParameters(sourceCQL interface{}) interface{} { + conn := tls.QUICClient(&tls.QUICConfig{}) + conn.SetTransportParameters(sourceCQL.([]byte)) + return conn +} + func RunAllTaints_CryptoTls() { { source := newSource(0) @@ -91,4 +156,69 @@ func RunAllTaints_CryptoTls() { out := TaintStepTest_CryptoTlsConnWrite_B0I0O0(source) sink(6, out) } + { + source := newSource(8) + out := TaintStepTest_CryptoTlsSessionStateBytes(source) + sink(8, out) + } + { + source := newSource(9) + out := TaintStepTest_CryptoTlsParseSessionState(source) + sink(9, out) + } + { + source := newSource(10) + out := TaintStepTest_CryptoTlsNewResumptionStateTicket(source) + sink(10, out) + } + { + source := newSource(11) + out := TaintStepTest_CryptoTlsNewResumptionStateState(source) + sink(11, out) + } + { + source := newSource(12) + out := TaintStepTest_CryptoTlsClientSessionStateResumptionState(source) + sink(12, out) + } + { + source := newSource(13) + out := TaintStepTest_CryptoTlsConfigEncryptTicketState(source) + sink(13, out) + } + { + source := newSource(14) + out := TaintStepTest_CryptoTlsConfigDecryptTicket(source) + sink(14, out) + } + { + source := newSource(15) + out := TaintStepTest_CryptoTlsQUICClient(source) + sink(15, out) + } + { + source := newSource(16) + out := TaintStepTest_CryptoTlsQUICServer(source) + sink(16, out) + } + { + source := newSource(17) + out := TaintStepTest_CryptoTlsQUICConnHandleData(source) + sink(17, out) + } + { + source := newSource(18) + out := TaintStepTest_CryptoTlsQUICConnNextEvent(source) + sink(18, out) + } + { + source := newSource(19) + out := TaintStepTest_CryptoTlsQUICConnConnectionState(source) + sink(19, out) + } + { + source := newSource(20) + out := TaintStepTest_CryptoTlsQUICConnSetTransportParameters(source) + sink(20, out) + } } diff --git a/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/IoFs.go b/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/IoFs.go index 4b9102008413..e6db16aee2e0 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/IoFs.go +++ b/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/IoFs.go @@ -11,6 +11,16 @@ func walkDirCallback(path string, d fs.DirEntry, _ error) error { } func steps() { + { + source := newSource(17).(fs.DirEntry) + out := fs.FormatDirEntry(source) + sink(17, out) + } + { + source := newSource(18).(fs.FileInfo) + out := fs.FormatFileInfo(source) + sink(18, out) + } { source := newSource(16).(fs.FileInfo) out := fs.FileInfoToDirEntry(source) diff --git a/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/MathBig.go b/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/MathBig.go new file mode 100644 index 000000000000..0be95bb7b223 --- /dev/null +++ b/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/MathBig.go @@ -0,0 +1,14 @@ +package main + +import "math/big" + +func TaintStepTest_MathBigIntFloat64(sourceCQL interface{}) interface{} { + out, _ := sourceCQL.(*big.Int).Float64() + return out +} + +func RunAllTaints_MathBig() { + source := newSource(0) + out := TaintStepTest_MathBigIntFloat64(source) + sink(0, out) +}