Repository navigation
Bring v3.14.1 servicing fixes to dev - #3518
Conversation
## Problem The in-process `DurableHttpRequest.TokenSource` converter supports a legacy `$type` payload format for custom `ITokenSource` implementations. That path resolved the supplied CLR type and deserialized the full object graph with `TypeNameHandling.Objects`, without an allowlist for the root type and while honoring nested type metadata. The newer discriminator-based `ManagedIdentityTokenSource` path was already fixed to a known type; the concern was limited to the legacy compatibility path. This servicing change is based on the unchanged v3.14.0 release commit and bumps only the in-process extension to 3.14.1. ## Fix - Continue accepting the built-in `ManagedIdentityTokenSource` through its current `kind` discriminator and legacy `$type` representation. - Require custom token-source roots to use an explicitly configured non-default `ISerializationBinder`; the default binder is not accepted as an allowlist. - Resolve custom root names through `BindToType`, then require the result to be a concrete, non-abstract `ITokenSource`. - Emit custom root names through `BindToName` instead of persisting `AssemblyQualifiedName` directly. - Deserialize custom token-source state with a cloned serializer configured with `TypeNameHandling.None`, so nested `$type` metadata cannot select runtime types. - Route subclasses of `ManagedIdentityTokenSource` through the custom binder path rather than silently treating them as the built-in type. - Parse assembly-qualified generic root names without splitting on commas inside generic argument brackets. The intentional compatibility boundary is that built-in managed identity works without configuration, while custom implementations require an explicit binder allowlist. Concrete nested state continues to deserialize according to its declared type, but nested polymorphic metadata is ignored. ## In-flight compatibility and regression coverage - v3.14.0 built-in managed-identity histories replay unchanged. - Custom histories replay only with an explicit root-type binder; otherwise they fail safely. - Persisted-payload tests cover both paths and prove nested derived type metadata is ignored under TypeNameHandling.Objects. - Coverage is converter-level, not a separate old-host/new-host rolling-upgrade test. ## Rejected approaches 1. **Remove the legacy `$type` path entirely.** This prevents replay of all legacy payloads, including the fixed built-in managed-identity format and safely allowlisted custom implementations. 2. **Allow every concrete `ITokenSource`.** Interface assignability is not an allowlist; an attacker could still select a side-effectful implementation already loaded in the process. 3. **Allowlist only `ManagedIdentityTokenSource` with no custom path.** This is secure but unnecessarily removes the public custom extension point when the application already has a binder-based allowlist configuration surface. 4. **Apply an `ITokenSource`-only binder to every `$type` in the object graph.** Nested state...
Varshitha Bachu (bachuv)
left a comment
There was a problem hiding this comment.
Approved, but please wait for all CI tests to pass before merging. Thanks!
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates DurableHttpRequest token source JSON (de)serialization to be safer and more explicit around type handling, including backward compatibility paths, and adds tests for the supported/unsupported scenarios.
Changes:
- Tightens
ITokenSourceserialization/deserialization to require an explicitSerializationBinderfor custom token sources and to avoid emitting nested$type. - Adds unit coverage for managed identity, legacy history formats, and custom token sources with/without an allowed binder.
- Bumps package patch version to 3.14.1.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| test/FunctionsV2/Tests/Unit/DurableHttpRequestTests.cs | Adds regression tests for token source round-tripping and legacy history deserialization. |
| src/WebJobs.Extensions.DurableTask/WebJobs.Extensions.DurableTask.csproj | Increments patch version to publish the behavior change. |
| src/WebJobs.Extensions.DurableTask/DurableHttpRequest.cs | Refactors token source converter to enforce binder usage for custom types and suppress $type emission except when explicitly allowed. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (4)
src/WebJobs.Extensions.DurableTask/DurableHttpRequest.cs:285
- GetCustomTokenSourceBinder rejects any binder that derives from DefaultSerializationBinder because it uses
is DefaultSerializationBinder. That prevents callers from safely subclassing DefaultSerializationBinder to implement an allowlist. Checking for the exact DefaultSerializationBinder type (or the known default instance) is safer while still enforcing "not the default binder".
{
if (serializer.SerializationBinder == null || serializer.SerializationBinder is DefaultSerializationBinder)
{
throw new JsonSerializationException("Custom token sources require an explicitly configured serialization binder.");
}
src/WebJobs.Extensions.DurableTask/DurableHttpRequest.cs:236
- CreateManagedIdentityTokenSource uses
optionsToken.ToObject<ManagedIdentityOptions>()without an explicit serializer.JToken.ToObject<T>()usesJsonSerializer.CreateDefault(), which respectsJsonConvert.DefaultSettings(and could re-enableTypeNameHandlingglobally), undermining the goal of hardening deserialization. Consider explicitly deserializing options withTypeNameHandling=Noneregardless of ambient defaults.
if (jsonObject.TryGetValue("options", out JToken optionsToken))
{
ManagedIdentityOptions managedIdentityOptions = optionsToken.ToObject<ManagedIdentityOptions>();
return new ManagedIdentityTokenSource(resourceString, managedIdentityOptions);
}
src/WebJobs.Extensions.DurableTask/DurableHttpRequest.cs:149
- TokenSourceConverter.CanConvert is incorrect:
objectTypeis aType, soobjectType is ITokenSourcewill always be false. Even though this converter is applied via attribute, the method should correctly report compatibility (and it may be used in other contexts later).
public override bool CanConvert(Type objectType)
{
return objectType is ITokenSource;
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
test/FunctionsV2/Tests/Unit/DurableHttpRequestTests.cs:146
- This test currently throws because no serialization binder is configured (the converter rejects all non-managed-identity
$typepayloads without a custom binder), so it doesn't actually validate the "type does not implement ITokenSource" branch. Configure a binder for the deserialization path so the converter reaches the!typeof(ITokenSource).IsAssignableFrom(runtimeType)check.
{
["$type"] = typeof(UnsupportedType).AssemblyQualifiedName,
});
Assert.Throws<JsonSerializationException>(() => json.ToObject<DurableHttpRequest>());
Add required category traits to the servicing regression tests and use public PyPI for the Python smoke-test image. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f2f1ee44-0784-4508-b984-3ff2676f8a74
|
This PR now intentionally diverges from the v3.14.1 commit released through ADO in production code and test assets. The production difference corrects a regression found by GitHub E2E validation: The test/configuration differences add the required xUnit category metadata, switch the Python smoke-test Dockerfile to public PyPI, and restore custom-token-source E2E coverage with a binder restricted to |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/WebJobs.Extensions.DurableTask/DurableHttpRequest.cs:236
optionsToken.ToObject<ManagedIdentityOptions>()uses a defaultJsonSerializer(potentially affected byJsonConvert.DefaultSettings, includingTypeNameHandling). To keep legacy history parsing hardened, deserialize options with an explicitTypeNameHandling.Noneserializer.
if (jsonObject.TryGetValue("options", out JToken optionsToken))
{
ManagedIdentityOptions managedIdentityOptions = optionsToken.ToObject<ManagedIdentityOptions>();
return new ManagedIdentityTokenSource(resourceString, managedIdentityOptions);
}
test/FunctionsV2/Tests/Unit/DurableHttpRequestTests.cs:132
- This test name is misleading: with the current converter logic, a
$typevalue that isn’tManagedIdentityTokenSourceis rejected first due to the missing non-defaultSerializationBinder, not specifically because the type doesn’t implementITokenSource. Renaming the test makes the intent/coverage clearer.
public void TokenSource_RejectsTypeThatDoesNotImplementInterface()
Use explicit authorization headers for forwarding tests and remove obsolete custom token source E2E cases now covered by binder-focused unit tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f2f1ee44-0784-4508-b984-3ff2676f8a74
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Suppressed comments (4)
src/WebJobs.Extensions.DurableTask/DurableHttpRequest.cs:285
- GetCustomTokenSourceBinder rejects any binder that inherits from DefaultSerializationBinder because it uses
is DefaultSerializationBinder. That would block callers who implement an allowlist by subclassing DefaultSerializationBinder (still an explicit binder). Consider only rejecting the built-in default binder instance/type, not derived custom binders.
private static ISerializationBinder GetCustomTokenSourceBinder(JsonSerializer serializer)
{
if (serializer.SerializationBinder == null || serializer.SerializationBinder is DefaultSerializationBinder)
{
throw new JsonSerializationException("Custom token sources require an explicitly configured serialization binder.");
}
src/WebJobs.Extensions.DurableTask/DurableHttpRequest.cs:167
- ReadJson throws NotSupportedException for an unsupported
kindvalue. For JSON conversion failures, Json.NET typically expects JsonSerializationException so callers can reliably catch/diagnose deserialization errors.
if (jsonObject.TryGetValue("kind", out JToken kindValue))
{
if (Enum.TryParse((string)kindValue, out TokenSourceType tokenSourceKind) &&
tokenSourceKind == TokenSourceType.AzureManagedIdentity)
{
return CreateManagedIdentityTokenSource(jsonObject);
}
throw new NotSupportedException($"The token source kind '{kindValue.ToString(Formatting.None)}' is not supported.");
}
src/WebJobs.Extensions.DurableTask/DurableHttpRequest.cs:188
- ReadJson throws NotSupportedException when neither
kindnor$typeis present. Since this is a malformed payload scenario, consider throwing JsonSerializationException for consistency with other failure paths and easier exception handling upstream.
}
throw new NotSupportedException("The token source kind is missing.");
}
test/FunctionsV2/Tests/Unit/DurableHttpRequestTests.cs:141
- This test name/intent no longer matches the behavior being validated: with the new converter logic, deserializing any non-managed-identity
$typewithout a custom binder fails because the binder is missing (before the “does not implement interface” check). Either configure a binder that maps to UnsupportedType to validate the interface rejection, or rename the test to reflect the binder requirement.
[Fact]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
public void TokenSource_RejectsTypeThatDoesNotImplementInterface()
{
JObject json = CreateRequestJson(
new JObject
{
["$type"] = typeof(UnsupportedType).AssemblyQualifiedName,
});
Assert.Throws<JsonSerializationException>(() => json.ToObject<DurableHttpRequest>());
}
Restore custom token source end-to-end coverage with a strict test binder so the activity boundary regression remains covered. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f2f1ee44-0784-4508-b984-3ff2676f8a74
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/WebJobs.Extensions.DurableTask/DurableHttpRequest.cs:153
- TokenSourceConverter.CanConvert uses
objectType is ITokenSource, butobjectTypeis aType, so this check is always false. While this converter is currently applied via a[JsonConverter]attribute, the CanConvert implementation is still incorrect and would prevent the converter from being selected if it were ever added viaJsonSerializerSettings.Converters.
Consider updating CanConvert to test assignability from ITokenSource.
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JToken json = JToken.ReadFrom(reader);
if (json.Type == JTokenType.Null)
{
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f2f1ee44-0784-4508-b984-3ff2676f8a74
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/WebJobs.Extensions.DurableTask/DurableHttpRequest.cs:218
- Managed identity options are serialized via
JsonConvert.SerializeObject(...), which ignores the passed-inJsonSerializerand any hardened settings. If an app setsJsonConvert.DefaultSettingswith TypeNameHandling enabled, this can accidentally emit$typeinsideoptions, undermining the intended "no nested polymorphic types" boundary. Serializeoptionsusing the safe serializer derived from the activeJsonSerializerinstead of the static JsonConvert helper.
{
ISerializationBinder binder = GetCustomTokenSourceBinder(serializer);
binder.BindToName(value.GetType(), out string assemblyName, out string typeName);
if (string.IsNullOrWhiteSpace(typeName))
{
src/WebJobs.Extensions.DurableTask/DurableHttpRequest.cs:153
- TokenSourceConverter.CanConvert is incorrect:
objectTypeis aType, soobjectType is ITokenSourceis always false. This makes the converter report it can't handle ITokenSource types (and can break if the converter is ever registered globally).
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JToken json = JToken.ReadFrom(reader);
if (json.Type == JTokenType.Null)
{
Summary
Brings the changes released from the ADO
hotfix/v3.14.1branch ontodevfor 3.15.0. This PR is no longer a straight cherry-pick: GitHub validation exposed a production regression in the released custom-token-source serialization path, so this branch also contains the correction.ITokenSourcedeserialization with an explicit binder allowlistWhy this differs from the ADO release
The 3.14.1 hardening correctly required an explicit, non-default binder for custom
ITokenSourceroots. However,TaskHttpActivityShimreconstructed scheduled requests with the defaultJsonConvertserializer, discarding the binder that had been used when the request was scheduled. As a result, correctly allowlisted custom token sources failed at the built-in HTTP activity boundary.This PR now reconstructs those requests through
DurableTaskExtension.MessageDataConverter, using the application's configured binder consistently at both boundaries. The 3.14.1 security boundary remains intact: applications without an explicit binder still reject custom roots, resolved types must still be concreteITokenSourceimplementations, and nested polymorphic type handling remains disabled.Testing