diff --git a/go/ql/lib/ext/context.model.json b/go/ql/lib/ext/context.model.json index df19e09dc905..b29cee16225f 100644 --- a/go/ql/lib/ext/context.model.json +++ b/go/ql/lib/ext/context.model.json @@ -6,10 +6,17 @@ "extensible": "summaryModel" }, "data": [ + // AfterFunc should be modeled when callback-based library models are supported. + ["context", "", false, "Cause", "", "", "Argument[0]", "ReturnValue", "taint", "manual"], ["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..1d893c4466ac 100644 --- a/go/ql/lib/ext/crypto.tls.model.json +++ b/go/ql/lib/ext/crypto.tls.model.json @@ -7,8 +7,26 @@ }, "data": [ ["crypto/tls", "", false, "Client", "", "", "Argument[0]", "ReturnValue", "taint", "manual"], + ["crypto/tls", "", false, "NewResumptionState", "", "", "Argument[0..1]", "ReturnValue[0]", "taint", "manual"], + ["crypto/tls", "", false, "NewResumptionState", "", "", "Argument[1].Dereference.Field[crypto/tls.SessionState.Extra]", "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]", "ReturnValue[0]", "taint", "manual"], + ["crypto/tls", "Config", true, "EncryptTicket", "", "", "Argument[receiver]", "ReturnValue[0]", "taint", "manual"], + ["crypto/tls", "Config", true, "EncryptTicket", "", "", "Argument[1]", "ReturnValue[0]", "taint", "manual"], + ["crypto/tls", "Config", true, "EncryptTicket", "", "", "Argument[1].Dereference.Field[crypto/tls.SessionState.Extra]", "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"], + ["crypto/tls", "SessionState", true, "Bytes", "", "", "Argument[receiver].Dereference.Field[crypto/tls.SessionState.Extra]", "ReturnValue[0]", "taint", "manual"], + ["crypto/tls", "SessionState", true, "Bytes", "", "", "Argument[receiver].Field[crypto/tls.SessionState.Extra]", "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/CONSISTENCY/DataFlowConsistency.expected b/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/CONSISTENCY/DataFlowConsistency.expected new file mode 100644 index 000000000000..3c4f6abe39de --- /dev/null +++ b/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/CONSISTENCY/DataFlowConsistency.expected @@ -0,0 +1,4 @@ +reverseRead +| CryptoTls.go:66:23:66:27 | implicit-deref state | Origin of readStep is missing a PostUpdateNode. | +| CryptoTls.go:73:23:73:27 | state | Origin of readStep is missing a PostUpdateNode. | +| CryptoTls.go:119:23:119:27 | implicit-deref state | Origin of readStep is missing a PostUpdateNode. | 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..a6eac5c61b34 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 @@ -1,4 +1,5 @@ -// Code generated by https://github.com/gagliardetto/codebox. DO NOT EDIT. +// Code partially generated by https://github.com/gagliardetto/codebox, with manual additions +// for context APIs added in Go 1.21. package main @@ -26,6 +27,52 @@ 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_ContextCause(sourceCQL interface{}) interface{} { + fromContext := sourceCQL.(context.Context) + return context.Cause(fromContext) +} + +func TaintStepTest_ContextWithDeadlineCauseRoundTrip(sourceCQL interface{}) interface{} { + fromError := sourceCQL.(error) + ctx, _ := context.WithDeadlineCause(nil, time.Time{}, fromError) + return context.Cause(ctx) +} + +func TaintStepTest_ContextWithTimeoutCauseRoundTrip(sourceCQL interface{}) interface{} { + fromError := sourceCQL.(error) + ctx, _ := context.WithTimeoutCause(nil, 0, fromError) + return context.Cause(ctx) +} + func TaintStepTest_ContextWithValue_B0I0O0(sourceCQL interface{}) interface{} { fromContext520 := sourceCQL.(context.Context) intoContext443 := context.WithValue(fromContext520, nil, nil) @@ -163,4 +210,44 @@ 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) + } + { + source := newSource(19) + out := TaintStepTest_ContextCause(source) + sink(19, out) + } + { + source := newSource(20) + out := TaintStepTest_ContextWithDeadlineCauseRoundTrip(source) + sink(20, out) + } + { + source := newSource(21) + out := TaintStepTest_ContextWithTimeoutCauseRoundTrip(source) + sink(21, 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..010c2b101b13 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 @@ -1,4 +1,5 @@ -// Code generated by https://github.com/gagliardetto/codebox. DO NOT EDIT. +// Code partially generated by https://github.com/gagliardetto/codebox, with manual additions +// for crypto/tls APIs added in Go 1.21. package main @@ -55,6 +56,115 @@ func TaintStepTest_CryptoTlsConnWrite_B0I0O0(sourceCQL interface{}) interface{} return intoConn584 } +func TaintStepTest_CryptoTlsSessionStateBytes(sourceCQL interface{}) interface{} { + out, _ := sourceCQL.(*tls.SessionState).Bytes() + return out +} + +func TaintStepTest_CryptoTlsSessionStateBytesExtra(sourceCQL interface{}) interface{} { + state := &tls.SessionState{} + state.Extra = append(state.Extra, sourceCQL.([]byte)) + out, _ := state.Bytes() + return out +} + +func TaintStepTest_CryptoTlsSessionStateBytesValueExtra(sourceCQL interface{}) interface{} { + var state tls.SessionState + state.Extra = append(state.Extra, sourceCQL.([]byte)) + out, _ := state.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_CryptoTlsClientSessionStateResumptionStateState(sourceCQL interface{}) interface{} { + _, state, _ := sourceCQL.(*tls.ClientSessionState).ResumptionState() + return state +} + +func TaintStepTest_CryptoTlsResumptionStateExtraRoundTrip(sourceCQL interface{}) interface{} { + state := &tls.SessionState{Extra: [][]byte{sourceCQL.([]byte)}} + cs, _ := tls.NewResumptionState(nil, state) + _, resumed, _ := cs.ResumptionState() + return resumed.Extra[0] +} + +func TaintStepTest_CryptoTlsConfigEncryptTicketState(sourceCQL interface{}) interface{} { + var config tls.Config + out, _ := config.EncryptTicket(tls.ConnectionState{}, sourceCQL.(*tls.SessionState)) + return out +} + +func TaintStepTest_CryptoTlsConfigEncryptTicketStateExtra(sourceCQL interface{}) interface{} { + var config tls.Config + state := &tls.SessionState{} + state.Extra = append(state.Extra, sourceCQL.([]byte)) + out, _ := config.EncryptTicket(tls.ConnectionState{}, state) + return out +} + +func TaintStepTest_CryptoTlsConfigEncryptTicketReceiver(sourceCQL interface{}) interface{} { + out, _ := sourceCQL.(*tls.Config).EncryptTicket(tls.ConnectionState{}, nil) + return out +} + +func TaintStepTest_CryptoTlsConfigDecryptTicket(sourceCQL interface{}) interface{} { + var config tls.Config + out, _ := config.DecryptTicket(sourceCQL.([]byte), tls.ConnectionState{}) + return out +} + +func TaintStepTest_CryptoTlsConfigDecryptTicketReceiver(sourceCQL interface{}) interface{} { + out, _ := sourceCQL.(*tls.Config).DecryptTicket(nil, 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 +201,104 @@ 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) + } + { + source := newSource(21) + out := TaintStepTest_CryptoTlsClientSessionStateResumptionStateState(source) + sink(21, out) + } + { + source := newSource(22) + out := TaintStepTest_CryptoTlsConfigEncryptTicketReceiver(source) + sink(22, out) + } + { + source := newSource(23) + out := TaintStepTest_CryptoTlsConfigDecryptTicketReceiver(source) + sink(23, out) + } + { + source := newSource(24) + out := TaintStepTest_CryptoTlsSessionStateBytesExtra(source) + sink(24, out) + } + { + source := newSource(25) + out := TaintStepTest_CryptoTlsSessionStateBytesValueExtra(source) + sink(25, out) + } + { + source := newSource(26) + out := TaintStepTest_CryptoTlsResumptionStateExtraRoundTrip(source) + sink(26, out) + } + { + source := newSource(27) + out := TaintStepTest_CryptoTlsConfigEncryptTicketStateExtra(source) + sink(27, 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) +}