Skip to content

cf workers secrets update replaces the entire secret set instead of patching a single secret #96

Not planned

Description

@karanbalaji

cf version: 1.0.0-beta.5, macOS

What happens

cf workers secrets update <NAME> --worker <worker> --type secret_text --text <value> sets the named secret, but silently deletes every other secret already on the Worker — it's not a patch, it's a full replace.

Hit this for real while migrating a production Worker (8 secrets already set via wrangler secret put, working fine). Ran cf workers secrets update RUN_TOKEN --worker web-qa-jev-agent --type secret_text --text "<new-token>" to rotate one token. cf workers secrets list --worker web-qa-jev-agent immediately after came back [{"name": "RUN_TOKEN", ...}] — the other 7 (GitHub App auth, webhook secret, target URL) were gone. Broke GitHub App auth and a webhook trigger until manually restored via wrangler secret put.

Repro

cf init repro-cf --package-manager npm
cd repro-cf
cf deploy   # after declaring at least one bindings.secret() per #70/#72's workaround, or use --secrets-file
cf workers secrets update FIRST --worker repro-cf --type secret_text --text a
cf workers secrets list --worker repro-cf     # [FIRST]
cf workers secrets update SECOND --worker repro-cf --type secret_text --text b
cf workers secrets list --worker repro-cf     # [SECOND] -- FIRST is gone

What I found

cf workers secrets update --dry-run shows exactly why:

{
  "command": "cf workers secrets update",
  "method": "PUT",
  "url": "https://api.cloudflare.com/client/v4/accounts/{account}/workers/scripts/{script}/secrets",
  "body": { "name": "SECOND", "type": "secret_text", "text": "b" }
}

It's a PUT to the plain /secrets collection endpoint with only the one secret in the body — a full replace, not a merge. Compare to cf workers secrets bulk --dry-run with the same secret:

{
  "command": "cf workers secrets bulk",
  "method": "PATCH",
  "url": "https://api.cloudflare.com/client/v4/accounts/{account}/workers/scripts/{script}/secrets-bulk",
  "body": { "SECOND": { "type": "secret_text", "text": "b" } }
}

bulk hits a different endpoint (/secrets-bulk) with PATCH/RFC 7396 merge semantics — its own --help text even says "Secrets not included in the request are left unchanged" and recommends it over update for multi-secret changes. But nothing in update's own --help or command name suggests that a single-secret call is just as destructive to every other existing secret. This looks like the same root-cause family as #70/#72/#54 (PUT-only API, no merge-on-single-field-update), specifically for the one command whose entire job description ("Add a secret to a Worker script") implies it should be additive.

Expected

cf workers secrets update either performs a genuine patch (e.g. by using the bulk/secrets-bulk endpoint under the hood when only one secret is given), or its --help/docs state unambiguously that it replaces the whole secret set — right now the command name and description ("Add a secret...") actively suggest the opposite of what it does.

Workaround

Use cf workers secrets bulk --body '{"NAME": {"type": "secret_text", "text": "value"}}' instead of update, always, even for a single secret on a Worker that has others set.

Activity

  1. tonydehnke commented on Oct 1, 2026

    @tonydehnke

    Could not reproduce the single-secret replacement behavior on cf 1.0.0-beta.9 in a disposable Worker test on 2026-10-01 UTC.

    1. Deploy a minimal Worker with workers.dev and preview URLs disabled and no routes/domains.
    2. Add synthetic DUMMY_A separately through the secret API. List confirms [DUMMY_A].
    3. cf deploy with no secret declarations succeeds; list still confirms [DUMMY_A].
    4. cf workers secrets update DUMMY_B --worker <disposable-worker> --type secret_text --text <dummy-value> succeeds; list confirms [DUMMY_A, DUMMY_B].

    Only dummy values were used. The Worker was deleted and subsequent settings read returned 404. This is one tested path, not a claim that every secret-update workflow is fixed. Separate dry-run disclosure #103 still reproduces on beta.9.

  2. MattieTK commented on Oct 9, 2026

    @MattieTK
    Member

    AI-authored follow-up: Prepared by OpenAI Codex at the user's request; the commands were executed against a dedicated Worker using only dummy secrets on October 9, 2026.

    I could not reproduce unrelated-secret deletion with 1.0.0-beta.5, 1.0.0-beta.10, or 1.0.0-beta.13 (npm latest when checked today).

    The Worker was created through cf init and deployed with a dummy BOOTSTRAP secret. Each CLI test reset FIRST and SECOND with a documented wrapped bulk body, then listed secrets to verify that the addition baseline contained only BOOTSTRAP. For beta.5/beta.10 the tests ran inside the beta.10 initialized project; beta.13 ran from a separately initialized beta.13 project, targeting the same dedicated Worker explicitly.

    All three versions observed:

    Initial:       BOOTSTRAP
    Add FIRST:     BOOTSTRAP, FIRST
    Add SECOND:    BOOTSTRAP, FIRST, SECOND
    Rotate FIRST:  BOOTSTRAP, FIRST, SECOND
    Bulk control:  BOOTSTRAP, FIRST, SECOND
    

    Addition/rotation used cf workers secrets update <NAME> --worker <test-worker> --type secret_text --text <dummy-value>. Rotation and bulk-control baselines were explicitly reseeded and checked before each test.

    The secret-list API confirms preservation of unrelated secret names. Runtime values were not read: the test endpoint redirected to Cloudflare Access, and that redirect was not followed. No production Worker or real secret was modified.

    This is a non-reproduction on a newly created Worker in one account against current API behavior, not a claim that the original production incident was impossible or that a particular CLI release fixed it. The dry-run PUT verb by itself does not establish collection-replacement semantics.

    One separate issue does reproduce: the unwrapped bulk --body workaround shown in this report silently no-ops on current beta.13, for both creation and deletion. The documented {"secrets":{...}} form works. Latest canary evidence is being added to existing #102 rather than filing another duplicate; #201 also covers overlapping bulk behavior.

  3. workers-devprod commented on Nov 24, 2026

    @workers-devprod
    Collaborator

    Thanks for the detailed report. cf workers secrets update adds or replaces only the secret you name. It sends the same request as wrangler secret put, and later tests on several versions, including beta.5, kept every other secret. The secrets you lost were most likely dropped by the cf deploy issue in #70, which has since been fixed, so we're closing this for now. If you can reproduce it on the latest release with no deploy in between, reply here and we'll reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions