Preserve member types through open-object union() and spreads instead of rebuilding them in secret analysis

Open
#20,558 1 comment 0 reactions 1 assignee View on GitHub

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

AI Triaged enhancement linter-false-positive Needs: Triage :mag: story: linter type system

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 FindPossibleSecretsVisitor still has to stay for untyped secrets. stg.listKeys().keys[0].value, base64(secret), and secObj.port (on @secure() param secObj { port: int }) have concrete non-secure types (string and int, not any). In union({ key: stg.listKeys().keys[0].value, sku: 'S' }, { sku: 'P' }).key, the read is typed string, so the visitor still needs its syntax-level spread, union(), and nested-access resolution (ResolveObjectPropertyInitializers, ResolveUnionPropertyInitializers, ResolveMergedPropertyInitializers) rather than trusting every non-any type.
  • SecureAny cannot mean both "maybe secure" and "guaranteed secure". #20520 kept (@secure() string) | string uncollapsed in TypeCollapser because leak rules warn if any branch is secure while use-secure-value-for-secure-inputs warns if any branch is not secure. Collapsing (@secure() string) | any into a single AnyType(IsSecure) would make union(cfg, plainExtra).password satisfy @secure() param p string without warning even when plainExtra is an insecure object parameter. We either need a separate MayContainSecrets flag or need to keep SecureAny | any uncollapsed so both directions stay honest.
  • Member and index access on AnyType currently strips flags. TypeAssignmentVisitor (case AnyType and maybeObject => LanguageConstants.Any), TypeHelper.GetNamedPropertyType, TypeHelper.GetArrayItemTypeOrAny, TypeFactory.CreateArrayType, and TypedArrayType return or check singleton LanguageConstants.Any, which would drop IsSecure on nested reads like merged.credentials.token or merged.items[0].
  • Widening dictionaries and object literals has compatibility tradeoffs. Widening MergeObjectTypes when merging with { *: any } only refines today's object fallback. Widening across typed dictionaries (union({ count: 3 }, strMap) where strMap is { *: string } -> count: int | string instead of any) or widening earlier named properties in TypeAssignmentVisitor.VisitObjectSyntax after spreads/dynamic keys ({ kind: 'V2', ...extra } losing literal 'V2') can introduce new BCP036/BCP070 errors and would need a corpus check. Also note MergeObjectTypes currently uses additionalProperties ??= obj.AdditionalProperties, which would need to union AdditionalProperties once 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

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Azure/bicep

All issues in Azure/bicep

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.