Skip to content

Add Secrets Store secrets and rate limits to wrangler.json configs - #8647

Merged
ry merged 11 commits into
mainfrom
ry/secrets-ratelimit
Nov 20, 2026
Merged

ry merged 11 commits into
mainfrom
ry/secrets-ratelimit

Conversation

@ry

@ry ry commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

workerd serve wrangler.jsonc could not run Workers that use Secrets Store secrets or rate limits. With --experimental, both now work. Each is a bundled Worker with a JS RPC entrypoint, and each binding is a service binding with its settings in props, the shape the KV and Queues ports use.

Secrets Store. /workerd/secrets-store.js exports SecretsStoreSecret, with {store_id, secret_name} in props. A secret's value is the environment variable WORKERD_SECRET_<NAME> (api-key is WORKERD_SECRET_API_KEY), bound fromEnvironment on the Secrets Store Worker, so it is read at startup and never written to disk; an unset one is a warning at startup. This is how Kubernetes and most container platforms pass secrets. As on Cloudflare, a Worker can only get() a secret: there is no store to write and no admin API. A secret name has one value in every store; Cloudflare allows one store per account today.

Rate limits. /workerd/ratelimit.js exports RateLimit, with {namespace, limit, period} in props and the same checks and error messages as Cloudflare's binding. Counts are in memory, and a restart forgets them.

Both are called over JS RPC, so a Worker needs a compatibility date of 2024-04-03 or later, or the rpc flag; for secrets before 2024-03-26 it also needs fetcher_no_get_put_delete. Cluster deployments cannot use either yet.

Miniflare test Status
ratelimit ported
ratelimit validation ported
ratelimit counters are keyed by namespace_id ported
ratelimit counters are scoped per period ported
ratelimit counters survive a workerd restart not ported: counts are in memory
ratelimit persists on file-system not ported: counts are in memory
ratelimit creates no storage directory when unconfigured not ported: rate limits have no storage
single secret-store ported, the value from the environment instead of the admin API
multiple secret-store ported, values from the environment; one name in two stores is one secret here

Rate-limit counts stay in memory on purpose. Miniflare stores them in SQLite because its counter is a Durable Object, which is evicted after about 10 seconds idle. Here the counter is a plain Worker, whose memory lasts as long as the process. In cluster mode every Durable Object commit is a bucket write, so a SQLite count would cost a bucket PUT per allowed request.

Tests beyond Miniflare's: weighted delta and the next window for rate limits; an unset or missing secret, and that a secret is not stored across a restart, for secrets.

ry added 2 commits November 18, 2026 21:39
`secrets_store_secrets` in a wrangler.json, with --experimental, bind
each secret to its value in the environment: the variable
WORKERD_SECRET_ plus the secret_name, upper-cased, with other characters
than letters and digits as `_` (`api-key` is WORKERD_SECRET_API_KEY).
This is how Kubernetes and most container platforms hand secrets to a
process. The binding has the one method Workers have, get(), which
throws `Secret "<name>" not found` when the variable is not set, as
Miniflare does; the server also says so at startup.

The binding is a wrapped binding over the new internal module
cloudflare-internal:secrets-store-api, with the secret's name as text
and its value as a fromEnvironment binding, so the value is read when
the server starts and is never written into the config. The prefix
keeps every other variable, such as the node's own bucket credentials,
out of a Worker's reach. store_id is ignored: a secret name means the
same secret in every store, and two names that would read the same
variable are an error. A cluster deployment cannot have them yet, as
it cannot have fromEnvironment bindings.
`ratelimits` in a wrangler.json, with --experimental, bind the rate
limit API: `limit({ key, delta })` answers `{ success }`. Counts are per
namespace, period and key in fixed windows of `period` seconds (10 or
60, checked when the config loads); a call succeeds while the window's
count is below the limit, and only a call that succeeds adds its delta.
Bindings that share a namespace_id share counts, each against its own
limit. The checks and their error messages are Miniflare's, which match
Cloudflare's binding, and its rate-limit tests are ported.

Each binding is a wrapped binding over the new internal module
cloudflare-internal:ratelimit-api, which checks the arguments in the
caller's isolate and POSTs the count to the Worker <name>-ratelimit,
the new bundled module /workerd/ratelimit.js. It goes over fetch, not
JS RPC, so Workers with a compatibility date before RPC can call it.

The counts are in that Worker's memory, unlike Miniflare's, which keeps
them in a Durable Object on disk: a restart, including a --watch reload,
forgets them, and each node of a cluster counts on its own, so a cluster
of n nodes allows up to n times the limit where Cloudflare counts once
per location. A cluster deployment cannot have them yet.

set_bindings passed clippy's line limit, so the Secrets Store and rate
limit binding writers are functions of their own, and the wrangler.json
tests of both share one serve() helper.
@ry
ry requested review from a team as code owners November 19, 2026 05:41

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of c69bae9d.

This review, of 0ffde2c5

💬 Approved with comments — No blocking issues. One WARNING: the README implies that rate limits work on a cluster, but workerd deploy rejects them. The other comments are minor robustness notes.

Findings: 1 warning · 2 info · 1 suggestion (4 are inline comments on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #8647.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Documentation] The README describes per-node rate-limit counting on a cluster, but cluster deployments reject `ratelimits`.
- **File:** README.md:124

## INFO (2)

### [Code Quality] The test helper resolves on `exit`, which can fire before the child's stderr is fully read.
- **File:** src/workerd/server/tests/wrangler-serve.mjs:34

### [Performance] The per-window key map in the rate-limit Worker has no cap on distinct keys.
- **File:** src/workerd/server/ratelimit/ratelimit.js:45

## SUGGESTION (1)

### [Code Quality] The rate-limit binding does not check the counter Worker's response status before parsing it.
- **File:** src/cloudflare/internal/ratelimit-api.ts:93

📋 Code Quality: 💬 1 info · 1 suggestion

The change is correct and well tested; there are two minor robustness points.

Recommendation: 💬 Optional Nits

  • [INFO] The test helper resolves on exit, which can fire before the child's stderr is fully read. (src/workerd/server/tests/wrangler-serve.mjs:34)
  • [SUGGESTION] The rate-limit binding does not check the counter Worker's response status before parsing it. (src/cloudflare/internal/ratelimit-api.ts:93)
View full review
  • src/cloudflare/internal/ratelimit-api.ts:93 passes the counter Worker's response straight to res.json() without checking the status. A failure in the counter Worker therefore shows up as a JSON parse error, or as { success: undefined }.
  • src/workerd/server/tests/wrangler-serve.mjs:34 resolves when the child emits exit. That event can fire before stderr has been fully read, so the assertions on the stderr of a refused start can occasionally see truncated text.

⚡ Performance: 💬 1 info

One low-priority memory note on the in-memory counter.

Recommendation: 💬 Optional Nits

  • [INFO] The per-window key map in the rate-limit Worker has no cap on distinct keys. (src/workerd/server/ratelimit/ratelimit.js:45)
View full review
  • Each window's key map grows with the number of distinct keys until the window rolls over (10 or 60 seconds).
  • This is acceptable at this scope.

📝 Documentation: ⚠️ 1 warning

The README implies that rate limits run on a cluster, which deployment rejects.

Recommendation: 📝 Minor Comments

  • [WARNING] The README describes per-node rate-limit counting on a cluster, but cluster deployments reject ratelimits. (README.md:124)
View full review
  • README.md:122-124 says that each node of a cluster counts rate limits on its own.
  • workerd deploy rejects configs with ratelimits or secrets_store_secrets (src/workerd/server/cli/wrangler.rs:51, :598-611).

✅ All other checks passed

🔒 Security: ✅ LGTM

  • Secrets are read only from environment variables prefixed WORKERD_SECRET_, and they are bound through fromEnvironment, so their values are never written into the config.
  • Two secret names that would map to the same variable are rejected.
  • The rate-limit counter Worker has no socket and is reachable only through the wrapped binding. Its /clock route needs a TEST_CLOCK binding that the wrangler translation never sets.

📖 AGENTS.md: ✅ LGTM

The AGENTS.md update matches the change.


Reviewed commit: 0ffde2c5

Comment thread README.md Resolved

@danlapid danlapid left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

Rate limits: we don't want new wrapped bindings, only JSRPC ones. I'd make /workerd/ratelimit.js a WorkerEntrypoint with a limit({ key }) method, put namespace, limit and period in the binding's props, and check the arguments there. A thrown TypeError reaches the caller over RPC, just as it does today. Then ratelimits is a plain service binding with props, the same shape KV and R2 use, and ratelimit-api.ts can go.

About using fetch so Workers with older compatibility dates can call it: the fetcher inside a wrapped binding already skips the rpc compat gate (Fetcher::deserializeForWrappedBinding), so that alone wasn't a reason to avoid JSRPC. Without a wrapper, callers older than 2024-04-03 that lack the rpc flag can't call RPC methods on a service binding. KV and R2 will hit the same limit when they move to JSRPC. If we need those callers, let's fix it once: add a config field that marks a service binding as a product binding and skips the gate, rather than adding a wrapper per product. Accepting the 2024-04-03 floor for now is fine too.

Miniflare also keeps the counts in a Durable Object with SQLite (RateLimiterObject), so they survive a restart and are shared across processes. That would be worth porting too.

Secrets Store is where I got confused. As written, it isn't really Secrets Store: only get() matches. Each secret is the environment variable WORKERD_SECRET_<NAME>, read once at startup, and store_id is ignored. So:

  • Stores don't exist: two stores with a secret of the same name collide.
  • There's nowhere to write: no store means no management API. Miniflare's SecretsStoreSecret has an admin API (create, update, duplicate, delete, list, get by id), which local tooling uses to manage secrets. If Miniflare moves to workerd's version, as it did for KV, secrets created locally would have nowhere to be stored.
  • Values are fixed: changing a secret means restarting the process.
  • It mostly duplicates fromEnvironment: the new parts are the .get() wrapper and the WORKERD_SECRET_ prefix.

I'd do it the way KV and R2 went: a bundled /workerd/secrets-store.js, a JSRPC WorkerEntrypoint like Miniflare's, with {store_id, secret_name} in props. Store each store's secrets in the existing KV namespace object, so writes from local tooling and the admin API work, and local data lives under .wrangler/state like everything else. Environment variables are a good source for self-hosting on Kubernetes, so keep them as an optional way to seed or override values in that worker, rather than the whole implementation. That also removes the need for a special wrapped binding for secrets.

Happy to talk it through if env-only was a deliberate scope cut for a first step 🙂

@codecov-commenter

codecov-commenter commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 31.17647% with 117 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.28%. Comparing base (0efc13c) to head (4994778).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
src/workerd/server/cli/wrangler.rs 0.00% 117 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8647      +/-   ##
==========================================
- Coverage   67.30%   67.28%   -0.03%     
==========================================
  Files         814      816       +2     
  Lines      210410   210539     +129     
  Branches    32465    32436      -29     
==========================================
+ Hits       141624   141665      +41     
- Misses      49746    49847     +101     
+ Partials    19040    19027      -13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

ry added 2 commits November 18, 2026 22:43
A rate limit is now a service binding to the `RateLimit` entrypoint
of `/workerd/ratelimit.js`, with the namespace, limit and period in
its props, instead of a wrapped binding over fetch. The argument
checks move into the entrypoint, and their errors reach the caller
over RPC. `cloudflare-internal:ratelimit-api` is removed.

Callers need JS RPC: a compatibility date of 2024-04-03 or later, or
the `rpc` flag. The wrangler.json test now uses a 2026 date.

The serve test helper now waits for `close`, so stderr is complete.
The README no longer describes rate limits in a cluster, since
deployments refuse them.
A secret is now a service binding to the `SecretsStoreSecret`
entrypoint of `/workerd/secrets-store.js`, with its `store_id` and
`secret_name` in its props, instead of a wrapped binding over an
environment variable. As in Miniflare, each store is a KV namespace
of a separate kv.js Worker, with its own Durable Object unique key,
so a Worker's KV bindings cannot read secrets. wrangler.json configs
keep it in `.wrangler/state/workerd/secrets-store/`, mode 0700.
`get()` and Miniflare's admin API (`SecretsStoreSecret::admin_api`:
create, update, duplicate, delete, list, get) behave as Miniflare's.

`WORKERD_SECRET_<NAME>` still works: bound `fromEnvironment`, it
overrides the secret in every store and is never written to disk.
`store_id` is no longer ignored. The startup warning for an unset
variable is gone, since a secret may be stored instead.

`bundled_worker` takes the Durable Object unique key, which alarms
and cluster ownership are keyed by. The wrapper module
`cloudflare-internal:secrets-store-api` is removed. Miniflare's two
Secrets Store tests are ported, with tests for the override, the rest
of the admin API, and a restart.
@ry

ry commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

[AI] Sorry for the sloppy first version. Reworked both as you suggested, in be7a9ff and c69bae9.

  • Rate limits: a RateLimit WorkerEntrypoint in ratelimit.js, with settings in props and the checks in the entrypoint. The TypeErrors reach the caller over RPC, as you said. ratelimit-api.ts is gone, and we accept the 2024-04-03 floor for now.
  • Secrets Store: secrets-store.js with {store_id, secret_name} props, each store a KV namespace of a separate kv.js Worker (its own unique key and a 0700 directory), Miniflare's admin API, and both Miniflare tests ported. WORKERD_SECRET_<NAME> overrides a secret and is never stored.
  • I kept rate-limit counts in memory rather than SQLite. Miniflare stores them because its counter is a DO that gets evicted; this one is a plain Worker, so its memory lasts as long as the process. In cluster mode each DO commit is a bucket PUT, so counting in SQLite would cost a PUT per allowed request. The description now lists every Miniflare test as ported or not, with the reason.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of eb47fae0.

This review, of c69bae9d

💬 Approved with comments — No blocking issues. One documentation WARNING: the README says the secrets directory is readable only by the user, but that is enforced only on Unix. The two INFO notes are about hardening.

Findings: 1 warning · 2 info (3 are inline comments on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #8647.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Documentation] The README says the secrets directory is readable only by the user, but 0700 is set only on Unix.
- **File:** README.md:121

## INFO (2)

### [Security] The admin API on one secret's binding can list, copy and delete any secret in the same store.
- **File:** src/workerd/server/secrets-store/secrets-store.js:67

### [Performance] The per-window key map in the rate-limit Worker has no cap on distinct keys.
- **File:** src/workerd/server/ratelimit/ratelimit.js:102

🔒 Security: 💬 1 info

The secrets KV is isolated correctly. One INFO: the admin API acts on the whole store.

Recommendation: 💬 Optional Nits

  • [INFO] The admin API on one secret's binding can list, copy and delete any secret in the same store. (src/workerd/server/secrets-store/secrets-store.js:67)
View full review
  • The secrets KV Worker (<name>-secrets-kv, unique key SecretsStoreKV) is separate from the user's KV Worker. Only <name>-secrets-store holds the store:<id> bindings, so a Worker's kv_namespaces bindings cannot read secrets.
  • Values from the environment are bound fromEnvironment and are never written to disk. Names that map to the same variable are rejected.
  • SecretsStoreSecret::admin_api acts on the whole store, not only on the bound secret. This matches Miniflare, and the file header says so.

⚡ Performance: 💬 1 info

The per-window key map still has no cap (low risk).

Recommendation: 💬 Optional Nits

  • [INFO] The per-window key map in the rate-limit Worker has no cap on distinct keys. (src/workerd/server/ratelimit/ratelimit.js:102)
View full review
  • Each namespace/period window keeps a Map of every distinct key until the window rolls over (10 or 60 seconds). Many unique keys in one window make memory grow. This is acceptable at the current scope.

📝 Documentation: ⚠️ 1 warning

The cluster-mode WARNING is fixed. New WARNING: the README's 'only the user can read' holds only on Unix.

Recommendation: 📝 Minor Comments

  • [WARNING] The README says the secrets directory is readable only by the user, but 0700 is set only on Unix. (README.md:121)
View full review
  • The earlier WARNING about per-node rate-limit counting on a cluster is fixed: the README no longer says it.
  • README.md:120-121 says the secrets directory is one "which only the user can read". secrets_services in src/workerd/server/cli/wrangler.rs:866-871 sets mode 0700 only under #[cfg(unix)], so on Windows the directory keeps the default permissions.

✅ All other checks passed

📖 AGENTS.md: ✅ LGTM

The src/workerd/server/AGENTS.md update matches the change.


📋 Code Quality: ✅ LGTM

🔄 Since last review: 3 findings resolved, 1 preserved, 2 new

  • src/workerd/server/tests/wrangler-serve.mjs now waits for close, which fires after the stdio streams end. The earlier note about truncated stderr is fixed.
  • ratelimit-api.ts is no longer part of the change, so the earlier note about the unchecked response status no longer applies.
  • The binding, service-count and index arithmetic in wrangler.rs checks out, and wrangler-test.rs pins the layout, the 0700 mode, the variable-collision check and the period check.
  • The README now says that secrets need fetcher_no_get_put_delete before 2024-03-26. The pull request description still gives only the 2024-04-03 / rpc floor, so the description is a little out of date there.

Reviewed commit: c69bae9d

Comment thread README.md Resolved
ry added 3 commits November 19, 2026 07:42
# Conflicts:
#	README.md
#	src/workerd/server/AGENTS.md
#	src/workerd/server/BUILD.bazel
#	src/workerd/server/cli/wrangler.rs
#	src/workerd/server/workerd-api.c++
#	src/workerd/server/workerd.capnp
They run one at a time (RUST_TEST_THREADS=1), and on Windows CI they
took longer than the 15 s a medium test gets. build/wd_rust_crate.bzl
recommends "large" for such crates.
wrangler.rs sets the mode under #[cfg(unix)]; on Windows the
directory keeps its inherited ACLs.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of d07d495f.

This review, of eb47fae0

💬 Approved with comments — Nothing blocks the merge. Two INFO notes remain: comments in wrangler.rs overstate the secrets directory permissions on Windows, and the admin API on one secret's binding reaches every secret in its store, as in Miniflare.

Findings: 2 info (1 is an inline comment on the diff)

Not opened by the correctness review: 4 changed files it was meant to read
  • src/workerd/server/BUILD.bazel
  • src/workerd/server/cli/wrangler.rs
  • src/workerd/server/workerd-api.c++
  • src/workerd/server/workerd.capnp

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


🔒 Security: 💬 1 info

The admin API on one secret's binding can act on every secret in its store (carried over, INFO).

Recommendation: 💬 Optional Nits

  • [INFO] The admin API on one secret's binding can list, copy and delete any secret in the same store. This matches Miniflare. (src/workerd/server/secrets-store/secrets-store.js:67)
View full review
  • SecretsStoreSecret::admin_api is reachable by any Worker that holds a secret binding. Its list, get, duplicate and delete act on the whole store, so a Worker bound to one secret can read every other secret in that store. This matches Miniflare, and the file header says so.
  • Props are built with serde_json::json!, so store_id and secret_name cannot inject into the config. The WORKERD_SECRET_ prefix keeps a Worker from reading arbitrary environment variables. Values taken from the environment are bound fromEnvironment and never written to disk. The secrets KV Worker has its own unique key and is not bound to user Workers.

📝 Documentation: 💬 1 info

The README is fixed. Two comments in wrangler.rs still say only this user may read the secrets directory, which holds only on Unix.

Recommendation: 💬 Optional Nits

  • [INFO] Comments in wrangler.rs say only this user may read the secrets directory, but mode 0700 is set only on Unix. (src/workerd/server/cli/wrangler.rs:882)
View full review
  • The README now says "mode 0700 on Unix", so the earlier WARNING is resolved.
  • src/workerd/server/cli/wrangler.rs:44 and :881-883 still say the secrets directory is one "which only this user may read". secrets_services sets mode 0700 only under #[cfg(unix)].

✅ All other checks passed

📖 AGENTS.md: ✅ LGTM

The update to src/workerd/server/AGENTS.md matches the change.


📋 Code Quality: ✅ LGTM

  • In secrets_services, the services come out in the order translate reserves for them: the secrets-store Worker, then the KV Worker, its disk and its blobs. The rate-limit Worker comes after them. wrangler-test.rs pins the service names and their order.
  • In set_bindings, the binding offsets (D1, then secrets, then rate limits, then assets) do not overlap.
  • Two secret names that map to the same WORKERD_SECRET_* variable are rejected, and a test covers it.
  • Changing the CLI unit tests to test_size = "large" is justified in its commit message.

⚡ Performance: ✅ LGTM

The new code in wrangler.rs runs once when the config loads and does a constant amount of work for each binding. None of the changes adds cost on a hot path.


Reviewed commit: eb47fae0

Comment thread src/workerd/server/cli/wrangler.rs Resolved

@danlapid danlapid left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is exactly the shape I was hoping for! Both are now plain JSRPC entrypoints with props, there's no wrapper, and secrets-store.js is a faithful port of Miniflare's, admin API included.

One small thing for self-hosting: the admin API is callable by any Worker that holds a secret binding, so on a self-hosted server a Worker can overwrite or delete secrets in its store. That's fine for Miniflare, which is local-only. Here I'd turn it on with a JSON binding on the secrets-store Worker that wrangler.rs sets for local dev, so self-hosted configs that leave it out get get() only.

Besides this, LGTM to land 🙂

A symlink at .wrangler/state/workerd/secrets-store would have had its
target chmod'd and filled with secrets; refuse it before creating
anything, as Miniflare does.

A unit test now binds vars, KV, R2, D1, a secret, a rate limit and
assets in one config and checks every service's and binding's place,
since each field's own test leaves the offsets of the others at zero.

The rate-limit wrangler test checks for a minute boundary after the
server starts, so a slow start cannot split its calls across windows.
Docs: the secrets directory is user-only on Unix; wrangler's local
secrets-store commands do not reach this store; the not-found message
is Miniflare's.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 32ca1bd0.

This review, of d07d495f

💬 Approved with comments — Nothing blocks the merge. Two INFO notes remain: the symlink refusal checks only the final path component, and the admin API reaches every secret in its store, as in Miniflare.

Findings: 2 info (2 are inline comments on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


🔒 Security: 💬 2 info

Two INFO notes, neither exploitable without write access to the project directory or a secret binding.

Recommendation: 💬 Optional Nits

  • [INFO] The symlink refusal checks only the final path component, and the check and the later directory calls are not atomic. (src/workerd/server/cli/wrangler.rs:893)
  • [INFO] The admin API on one secret's binding can list, read, copy and delete any secret in the same store, as in Miniflare. (src/workerd/server/secrets-store/secrets-store.js:48)
View full review
  • Symlink refusal. The check runs symlink_metadata on .wrangler/state/workerd/secrets-store only.
    • A symlinked parent (.wrangler, state or workerd) is still followed by create_dir_all and set_permissions.
    • The check and the later directory calls are not atomic.
    • Exploiting either takes write access to the operator's own project tree, so this is hardening only.
    • Two fixes would close it: canonicalize the path and require that it stays under the config root, or create the directory with DirBuilder::mode(0o700).
  • Admin API. SecretsStoreSecret::admin_api acts on the whole store from any one secret's binding, as in Miniflare. @​danlapid [approver] suggested turning it on with a binding for self-hosted servers, and the code does not do that yet.
  • No injection. Props are built with serde_json::json!. The WORKERD_SECRET_ prefix limits which environment variables a Worker can read. Values from the environment are never written to disk.

✅ All other checks passed

📖 AGENTS.md: ✅ LGTM

The update to src/workerd/server/AGENTS.md matches the change.


📋 Code Quality: ✅ LGTM

  • translate reserves service slots for secrets and rate limits, and those counts match what bundled_services writes.
  • The binding offsets in set_bindings do not overlap, and bindings_of_every_kind_keep_their_places pins them.
  • The symlink check runs before any directory is created.
  • Both new fields are rejected without --experimental, in a deployment, and in assets-only mode.
  • The rate-limit window arithmetic is correct, and only an allowed call adds its delta.
  • The new embeds in workerd-api.c++ and workerd.capnp match the registered module names.

⚡ Performance: ✅ LGTM

The config translation runs once at startup. Nothing on a hot path changed.


📝 Documentation: ✅ LGTM

The comments at wrangler.rs:44 and :883 now say the directory is limited to this user "on Unix", which matches the code.


Reviewed commit: d07d495f

Comment thread src/workerd/server/cli/wrangler.rs Resolved
On Cloudflare a Secrets Store binding can only get() its secret; writes
go through the dashboard, the API or wrangler. Miniflare's admin API on
the binding could list, copy and delete every secret in the store. It is
now off unless the Secrets Store Worker has the JSON binding ADMIN set
to true, for tests and local tools. cli/wrangler.rs never sets it, so a
wrangler.json config gets get() only.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 0564873a.

This review, of 32ca1bd0

💬 Approved with comments — No BLOCKING or WARNING findings. The admin API is now off unless ADMIN is set, and one hardening INFO remains on the symlink check for the secrets directory.

Findings: 1 info

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


🔒 Security: 💬 1 info

Admin API concern fixed; one hardening INFO remains on the symlink check

Recommendation: 💬 Optional Nits

  • [INFO] The symlink check covers only the last path component, and the check and the later directory calls are not atomic. (src/workerd/server/cli/wrangler.rs:894)
View full review
  • Admin API (fixed). admin_api now throws unless the Secrets Store Worker has ADMIN set to true. wrangler.json configs never set it, so a Worker with a secret binding can only call get().
  • Symlink check (INFO). symlink_metadata checks only .wrangler/state/workerd/secrets-store itself. If .wrangler, state or workerd is a symlink, create_dir_all and set_permissions still follow it, and the check and those calls are not atomic. Exploiting this takes write access to the operator's own project tree.
  • No injection or leaks. Props are built with serde_json::json!. The WORKERD_SECRET_ prefix limits which environment variables can be read, and values from the environment are never written to disk.

✅ All other checks passed

📖 AGENTS.md: ✅ LGTM

The update to src/workerd/server/AGENTS.md matches the change.


📋 Code Quality: ✅ LGTM

  • Admin API check (secrets-store.js): the test is this.env.ADMIN !== true, so only the JSON value true turns the API on. secrets_services never sets ADMIN.
  • Service slots and binding offsets: the four slots reserved for secrets match what bundled_services writes. bindings_of_every_kind_keep_their_places pins the binding offsets.
  • Environment overrides: ?? lets an unset fromEnvironment binding, which is null, fall back to the stored value. Two secret names that map to the same variable are rejected.
  • Rate-limit windows: the window math is correct, and only an allowed call adds its delta.

⚡ Performance: ✅ LGTM

Config translation runs once at startup. Nothing on a hot path changed.


📝 Documentation: ✅ LGTM

The README and code comments match the behaviour at this commit, including the ADMIN gate.


Reviewed commit: 32ca1bd0

On Cloudflare a Secrets Store binding can only get() its secret; writes
go through the control plane. A self-hosted server's control plane is
whatever starts it, and that passes secrets in the environment. So the
KV-backed store and Miniflare's admin API go: a secret's value is its
WORKERD_SECRET_<NAME> variable, bound fromEnvironment on the Secrets
Store Worker and never stored. The secrets KV Worker and its disks, the
0700 directory and its symlink check, and the unique key bundled_worker
took for that KV Worker go with them.
@ry

ry commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

[AI] Two commits since your approval; the second replaces the first. 0564873 takes Secrets Store back to environment variables only, without the KV store or the admin API. The JS RPC entrypoint you asked for stays. On Cloudflare a binding can only get(), and writes go through the control plane. For a self-hosted server the control plane is whatever starts workerd, such as Kubernetes, Docker or systemd, and those pass secrets in the environment. Nothing in a wrangler.json config could write the store, so it goes, along with about 250 lines and three services per config.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 49947785.

This review, of 0564873a

✅ Approved — No findings. The earlier note on the secrets directory no longer applies, because secrets are now read only from the environment and nothing is written to disk.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

The secrets directory and its symlink check are gone, and secrets are read only from WORKERD_SECRET_* environment variables. SecretsStoreSecret exposes only get(). Props are built with serde_json::json!.


📖 AGENTS.md: ✅ LGTM

The update to src/workerd/server/AGENTS.md matches the change.


📋 Code Quality: ✅ LGTM

Service slots and binding offsets match what bundled_services and set_bindings write. Secret-name collisions are rejected, a name used in several stores is deduplicated, and an unset variable throws Secret "<name>" not found.


⚡ Performance: ✅ LGTM

Config translation runs once at startup, and nothing on a hot path changed.


📝 Documentation: ✅ LGTM

The README and code comments match the environment-only secrets behaviour.


Reviewed commit: 0564873a

With values only from the environment, a misspelled WORKERD_SECRET_
variable would otherwise show only as a failed get() at request time.
Also run the rate-limit wrangler test as large, since it may wait up to
5 s for a minute boundary, and reflow the module doc.

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — No findings. The startup warning names only the variable, never its value, and the test changes make the stderr assertions reliable.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

  • secret_variable always adds the WORKERD_SECRET_ prefix and replaces every character other than letters and digits with _. A config therefore cannot make a Worker read arbitrary environment variables.
  • SecretsStoreSecret exposes only get().
  • Props are built with serde_json::json!, so config values are escaped.
  • The startup warning names the variable, never its value.

📖 AGENTS.md: ✅ LGTM

The update to src/workerd/server/AGENTS.md matches the change.


📋 Code Quality: ✅ LGTM

  • check_bindings in wrangler.rs warns about an unset WORKERD_SECRET_* variable only for --experimental serve configs.
    • Two names that map to the same variable are still an error.
    • The same name in two stores is deduplicated.
    • Binding offsets still match set_bindings.
  • wrangler-serve.mjs now resolves on close, so stderr is complete before the tests assert on the startup warning.
  • size = "large" fits the rate-limit wrangler test, which may wait up to 5 s for a minute boundary.

⚡ Performance: ✅ LGTM

Config translation runs once at startup, and the rate-limit check costs O(1) per call. The per-window key map is uncapped by design, as discussed earlier, and is dropped when its window rolls over.


📝 Documentation: ✅ LGTM

The README and the code comments match the environment-only secrets behaviour and the in-memory rate-limit counts.


Reviewed commit: 49947785

@ry
ry merged commit ba00fd8 into main Nov 20, 2026
24 checks passed
@ry
ry deleted the ry/secrets-ratelimit branch November 20, 2026 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants