Open robcao opened 1 month ago
You are returning Task<WorkflowHandle>
which is then serialized.
WorkflowHandle
is not meant to be serializable (just coincidence that it works with System.Text.Json
). This would be the same as if you returned Task<MyDatabaseOrmEntity>
that contains a property with the database that had its initial options. That the return type is Task
does not mean the result is expected to automatically be removed, Task
is just a supertype of Task<TResult>
and return covariance applies and we do support caller specifying the result-type for upcasting. This information would leak if you just called the method regularly and not through Temporal.
You should not return the workflow handle from the activity if you do not want it to be serialized. If you cannot await
, then you can do something like startTask.ContinueWith(_ => Task.CompletedTask), TaskContinuationOptions.OnlyOnRanToCompletion)
.
What are you really trying to do?
I have a use case where I am invoking signal from start in an activity. I stumbled across a scenario where Temporal client credentials can potentially get leaked in workflow history.
Describe the bug
When executing an activity that returns a
Task
, if you instead return aTask<T>
, the value ofT
is stored in workflow history. This can lead to unexpected leakage of Temporal server credentials whenT
is aWorkflowHandle
.Consider the following activity. The activity returns
Task<WorkflowHandle>
, and the workflow handle gets stored in workflow history.The issue here is that
WorkflowHandle
has a reference to the Temporal client, which leaks sensitive information like the api key or TLS certificate into the workflow history.Minimal Reproduction
I have a code sample here: https://github.com/robcao/temporal-client-serialization
To reproduce:
Start a dev server:
temporal server start-dev
.Start the worker:
dotnet run
.Execute a workflow:
temporal workflow start --task-queue=my-tq --type=Example
.Navigate to the temporal ui and click the
Example
workflow. If you look at the workflow history, you'll see that the entire workflow handle was stored.Environment/Versions
Additional context
This can be fixed by re-writing the activity like this, so it's fairly minor. However, perhaps serialization of the
TemporalClient
should be changed to omit theApiKey
,TlsOptions
, and other potentially sensitive values?