Preserve member types through open-object union() and spreads instead of rebuilding them in secret analysis
Maintainers usually reply within 1 day
@andyleejordan is already working on this.
Since Nov 12, 2026.
Assessment
This issue has not been assessed yet.
Description
Bicep version
main at 0812c832f (after #20553)
Describe the bug
In #20553 (review comment), @shenglol noted that TypeHelper.MergeObjectTypes drops the entire object shape to plain object whenever an open input (object or an unsealed user-defined type) or dictionary ({ *: T }) could override earlier named properties. To keep union(cfg, extra).password from losing its secret warning while keeping union(cfg, extra).name quiet, #20553 taught FindPossibleSecretsVisitor to re-project parameter and array-item types from syntax (PropertyValue.Type, ResolveTypedProperty, ResolveTypedArrayItem) and added a ReferenceEquals(source, LanguageConstants.Object) special case in SecureAssignmentChecker.
That leaves union() and spread semantics split across the type system and the linter, and it still misses whole-object module assignments: when union(cfg, extra) is passed directly to a typed module parameter whose .password property is already @secure(), merged has type object, so SecureAssignmentChecker promotes the whole expression to secure and warns no-secure-values-in-insecure-inputs on the public container anyway.
To Reproduce
// child.bicep
param settings {
@secure()
password: string
}
// main.bicep
param cfg {
name: string
@secure()
password: string
}
param extra object
var merged = union(cfg, extra)
module m 'child.bicep' = {
name: 'm'
params: {
settings: merged
}
}
// Warning no-secure-values-in-insecure-inputs: Module parameter 'settings' is not secure, but is assigned secure value 'cfg.password'.
merged can only carry cfg.password under .password, which child.bicep already marks @secure(). Because MergeObjectTypes falls back to object (!IsOrContainsSecureType(source)), SecureAssignmentChecker treats the secret found by FindPossibleSecretsVisitor as untrackable by member and flags the whole settings parameter.
Additional context
@shenglol sketched widening known properties against obj.AdditionalProperties in MergeObjectTypes (recursively for nested objects) instead of falling back to object, paired with a SecureAny (new AnyType(TypeSymbolValidationFlags.IsSecure)) so CreateTypeUnion(@secure() string, any) doesn't collapse to plain any. That would give merged a shape like { name: any, password: secure any, *: any }, fixing whole-object forwarding, improving hover types, and letting us delete the parallel type-projection helpers from FindPossibleSecretsVisitor (~65 lines) and the LanguageConstants.Object workaround in SecureAssignmentChecker.
A few constraints came up when checking the sketch against main:
- Syntax resolution in
FindPossibleSecretsVisitorstill has to stay for untyped secrets.stg.listKeys().keys[0].value,base64(secret), andsecObj.port(on@secure() param secObj { port: int }) have concrete non-secure types (stringandint, notany). Inunion({ key: stg.listKeys().keys[0].value, sku: 'S' }, { sku: 'P' }).key, the read is typedstring, so the visitor still needs its syntax-level spread,union(), and nested-access resolution (ResolveObjectPropertyInitializers,ResolveUnionPropertyInitializers,ResolveMergedPropertyInitializers) rather than trusting every non-anytype. SecureAnycannot mean both "maybe secure" and "guaranteed secure". #20520 kept(@secure() string) | stringuncollapsed inTypeCollapserbecause leak rules warn if any branch is secure whileuse-secure-value-for-secure-inputswarns if any branch is not secure. Collapsing(@secure() string) | anyinto a singleAnyType(IsSecure)would makeunion(cfg, plainExtra).passwordsatisfy@secure() param p stringwithout warning even whenplainExtrais an insecureobjectparameter. We either need a separateMayContainSecretsflag or need to keepSecureAny | anyuncollapsed so both directions stay honest.- Member and index access on
AnyTypecurrently strips flags.TypeAssignmentVisitor(case AnyTypeandmaybeObject => LanguageConstants.Any),TypeHelper.GetNamedPropertyType,TypeHelper.GetArrayItemTypeOrAny,TypeFactory.CreateArrayType, andTypedArrayTypereturn or check singletonLanguageConstants.Any, which would dropIsSecureon nested reads likemerged.credentials.tokenormerged.items[0]. - Widening dictionaries and object literals has compatibility tradeoffs. Widening
MergeObjectTypeswhen merging with{ *: any }only refines today'sobjectfallback. Widening across typed dictionaries (union({ count: 3 }, strMap)wherestrMapis{ *: string }->count: int | stringinstead ofany) or widening earlier named properties inTypeAssignmentVisitor.VisitObjectSyntaxafter spreads/dynamic keys ({ kind: 'V2', ...extra }losing literal'V2') can introduce newBCP036/BCP070errors and would need a corpus check. Also noteMergeObjectTypescurrently usesadditionalProperties ??= obj.AdditionalProperties, which would need to unionAdditionalPropertiesonce open inputs stay in the loop.
Split out from #20552 and #20553.
Drafted by Copilot with Gemini 4 Carbon.
- Dominant language
- Bicep
- Stars
- 3.7k
- Forks
- 833
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 81
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Azure/bicep
-
AI Triaged bug Needs: Triage :mag: story: bicep parameters
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Azure/bicep#20654 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement Needs: Upvote VisualStudio
Difficulty 1/5 Under an hour Newbie friendliness 72/100
Azure/bicep#17997 · 1 reaction ·
Maintainers usually reply within 1 day
-
AI Triaged Needs: Triage :mag: OnlyifNotExists
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Azure/bicep#20634 · 2 comments ·
Maintainers usually reply within 1 day
-
AI Triaged bug Needs: Triage :mag:
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Azure/bicep#20584 · 2 comments ·
Maintainers usually reply within 1 day
-
AI Triaged investigate Needs: Triage :mag: revisit
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Azure/bicep#20556 · 2 comments ·
Maintainers usually reply within 1 day