Skip to content

Improve Environment Variable & Secret Redaction Behavior in Wrangler CLI #15167

Description

@dimilau

Problem Statement

Currently, wrangler dev unexpectedly hides plain environment variable values when they are overridden in .dev.vars / .env, even when they are not secrets. Additionally, build logs during Cloudflare Worker deployments do not list configured secrets.

Current Behavior vs. Issue

Environment / Context Configuration Observed Output Issue / Ambiguity
Local Dev (wrangler dev) Variable defined in wrangler.toml only env.MY_VAR ("100900") Works as expected.
Local Dev (wrangler dev) Variable defined in both wrangler.toml AND .dev.vars / .env env.MY_VAR ("(hidden)") Unexpected: Value is hidden even though it is a standard local environment variable, not a secret.
Worker Deployment Build Secrets bound to the Worker (Secrets not listed) Secrets attached to the Worker environment are omitted from build output logs entirely.

Proposed Solution & Expected Behavior

We propose refining how Wrangler handles string visibility in output logs for both local development and deployment builds.

1. Local Development (wrangler dev)

Scenario A: Standard Setup (No secrets key in configuration file)

  • Overridden Environment Variables: If a variable is present in both wrangler.toml and .dev.vars / .env, Wrangler should display the active value from .dev.vars / .env rather than hiding it.
  • Fallback Unbound Variables: If a variable is defined in .dev.vars / .env but not declared in wrangler.toml, treat it as a potential secret and display (hidden).

Scenario B: Explicit secrets Schema (If secrets config property is defined)

  • Overridden Environment Variables: If a variable is defined in both wrangler.toml and .dev.vars / .env, show the resolved value from .dev.vars / .env.
  • Required Secrets: If a key is explicitly declared under the secrets configuration property (e.g., set as required), mark it clearly as (hidden secret) during local execution.

2. Cloudflare Worker Deployment Build

When running deployment builds, Wrangler should list all secrets attached to the target Worker environment in the binding output summary, explicitly masking their values:

Your Worker has access to the following bindings:
Binding								Resource
env.MY\_VARIABLE\_A("10900")		Environment Variable 
env.MY\_SECRET\_KEY(hidden secret)	Secret

Comparison Matrix (Expected Output)

Variable Source Defined in wrangler.toml Defined in .dev.vars Defined in secrets Config Expected wrangler dev Output
Standard Env Var Yes No No env.MY_VAR ("<value_from_toml>")
Overridden Env Var Yes Yes No env.MY_VAR ("<value_from_dev_vars>")
Undeclared Local Var No Yes No env.MY_VAR ("(hidden)")
Explicit Secret Optional Optional Yes (Required) env.MY_VAR ("(hidden secret)")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Untriaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions