Repository navigation
Commit 170f9f8
fix(plugin-auth): Setup → Authentication says which auth rate limit runs while nothing is saved for it (#39329)
Fixes #38608
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:管理员打开「设置 → 身份验证」时,如果从没保存过限流值,页首提示条会多一段说明:页面上的「每 60 秒 10
次」并未生效,实际生效的是认证库自带的按路径限流,或部署配置里声明的限流。
- 为什么做:这是「身份验证设置按实际运行状态显示」工作的最后一处缺口。页面显示的上限没有任何请求真正受它约束,管理员会以为已有这层保护。
- 出错会怎样:最坏情况是提示条把实际限流说错。这只影响管理员读到的说明,任何设置值和保存规则都不变,撤回本改动即可恢复原样。
- 要你做什么:无
## What changes
Option A, as the seat chose it: the page states which rate limit runs.
No value the read returns changes.
- `auth-settings-live-status.ts`: the new `describeRateLimitLiveStatus`
adds an `info` statement whenever neither `rate_limit_max` nor
`rate_limit_window_seconds` resolves from anything but the default. That
is the same test the settings pass uses before it writes the pair
(`isExplicit`). The statement says the cap the fields show is not
applied, then names what the auth instance runs instead. That is one of
three things:
- the auth library's own per-path limits, which run only in production,
when nothing is declared;
- the declared `rateLimit` pair, read the way the library reads it
(`window || 10`, `max || 100`, and an `enabled` left out means
production only), applied on every path without a rule of its own;
- rate limiting turned off by the declaration.
It ends with what a save does. The copy is in all eleven languages on
the table. The statement rides last in `combineAuthLiveStatus`, so any
`warning` keeps the banner title.
- `auth-plugin.ts`: the live-status provider passes the two keys as the
page reads them, plus `declaredAuthOptions.rateLimit`. That is the block
the auth instance receives while nothing is saved, and also the block
the restore arm hands back on a clear. The `warn` line for a failed
registration names the new consequence.
- `auth-settings-declared-defaults.ts`: the header and the
`AUTH_KEYS_NOT_DECLARED` reasons for the pair now say that the banner
states which limit runs. The pair stays out of `AUTH_DECLARED_DEFAULTS`,
and its values still read 10 / 60, `source: 'default'`.
Read first, by risk:
1. `packages/plugins/plugin-auth/src/auth-settings-live-status.ts`,
`rateLimitRunsWhileNothingSaved`: the library-default mirror and the
production-only reading.
2. `packages/plugins/plugin-auth/src/auth-plugin.ts`, the
`registerLiveStatus('auth', …)` provider: what the statement is judged
from.
3. `packages/plugins/plugin-auth/src/auth-settings-live-status.test.ts`,
the new describe block "states the auth rate limit that runs while
nothing is saved for it".
## Tests
These run on a real `AuthPlugin` over the real `SettingsService` and its
`GET /api/settings/:namespace` route. What the page says is checked
against the built auth instance: `options.rateLimit` is what it
receives, and `$context.rateLimit` is the library's own reading of that.
- Nothing declared: the fields read 10 / 60 `default`. The instance
receives no pair and no `customRules`, and its resolved max and window
are not 10 / 60. The page states the library rules, in English and
zh-CN.
- Declared `{ enabled: true, window: 120, max: 5 }`: the page states the
pair taken from `$context.rateLimit` (5 / 120, always on).
- Declared `{ window: 120, max: 5 }` with no `enabled`: production only,
matching `$context.rateLimit.enabled === false` under a non-production
`NODE_ENV`.
- Declared `{ enabled: false }`: the page states rate limiting is off.
- CONTROL: once 7 / 30 is saved, the instance's
`customRules['/sign-in/email']` is `{ window: 30, max: 7 }`, the page
reads 7 / 30 `global`, and the statement is gone. With one key cleared,
the cap runs at the 60 the page shows, still with no statement. Clearing
both brings back the declared pair and the statement.
- Unit cases for `describeRateLimitLiveStatus`: any non-default source
silences it, and each of the three runs is covered. The copy-table test
now composes every rate-limit variant in every language and asserts the
numbers reach the text.
- Existing pins that asserted no banner with nothing saved now assert
this exact statement. The combined-banner pins assert the exact
`combineAuthLiveStatus` output.
Red first: the new and revised cases failed on the test commit
`246f2df867` (15 failed / 23 passed). They pass on the fix.
<details><summary>Ablation (three mutations, each through
scripts/ablation-replace.mjs, restored to the HEAD blob with an empty
git diff HEAD)</summary>
The subject resolves through relative `src` imports, so no build was
involved.
- Deleted the saved-value gate in `describeRateLimitLiveStatus`: 2
failed. Those were the CONTROL case and the unit "states nothing once
either key resolves" case.
- `declared: this.declaredAuthOptions.rateLimit` replaced by `declared:
undefined` in the provider: 5 failed. Those were the four declared
real-plugin cases and the DECLARED-every-key page case.
- `productionOnly: declared.enabled !== true` replaced by
`productionOnly: false`: 2 failed. Those were the
declared-without-`enabled` real-plugin case and the unit case.
</details>
<details><summary>Local runs at the merge head 4a17206</summary>
- `pnpm --filter @objectstack/plugin-auth typecheck`: exit 0. This
includes `check:test-typecheck` over `tsconfig.test.json`, with the debt
ledger unchanged.
- `vitest run` on `auth-settings-live-status`,
`auth-settings-clear.pin`, `auth-settings-ordering.pin`,
`auth-settings-refusal-isolation`, `auth-settings-seeded-boot.pin`,
`auth-plugin`, `audience-posture-setting`, `sign-in-method-floor`,
`settings-copy-locale` and `organization-default-currency`: 10 files,
307 tests passed.
- `dispatch-gates --commands` derived 79 families at this head. `--ran`
gave 75 run with exit 0, 4 NOT-MEASURED and 0 UNRUN.
- The four NOT-MEASURED families are `check-comment-mask-corpus`,
`check:query-options-erasure`, `check:slot-lookup` and
`check:type-check-debt`. Each is a repo-wide scan that the shared box
killed at a 150 to 240 s per-gate timeout. CI runs them.
</details>
## Acceptance notes
- Placement: the live-status seam has one place, the banner at the head
of the page. The statement names the Anti-abuse group, where the two
fields sit. Putting it under the group would need a new field on the
live status, which is a published response shape change, so it is not
done here.
- Reach: nothing saved for the pair is the default state, so this `info`
statement now heads Setup → Authentication on nearly every deployment
until a limit is saved. That is option A as chosen. No value, source,
save rule or field changes, and the banner specifier keeps its shape.
- Precision: with a declared global pair, the library's own special
rules still govern sign-in, sign-up and password reset unless the
declaration has its own rules for those paths. The statement says this
("on every path without a rule of its own"). It does not list a
declaration's own `customRules`.
- The library defaults (10 s / 100) are mirrored in one place. The
real-plugin cases compare the statement with `$context.rateLimit`, so a
library change to those defaults turns them red.
- The full `@objectstack/plugin-auth` suite was not measured locally:
the run was killed inside the foreground window. It is left to `Test
Core`.
## Verification
`pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2
src/auth-settings-live-status.test.ts` should show 38 passed. The
describe block "states the auth rate limit that runs while nothing is
saved for it" holds the declared, undeclared and saved cases.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01TsNV8Bsjqmw7aXCo2QuLU1)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent fde47ef commit 170f9f8
5 files changed
Lines changed: 468 additions & 22 deletions
File tree
- .changeset
- packages/plugins/plugin-auth/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| 164 | + | |
164 | 165 | | |
165 | 166 | | |
166 | 167 | | |
| |||
3234 | 3235 | | |
3235 | 3236 | | |
3236 | 3237 | | |
3237 | | - | |
| 3238 | + | |
| 3239 | + | |
| 3240 | + | |
3238 | 3241 | | |
3239 | 3242 | | |
3240 | 3243 | | |
| |||
3258 | 3261 | | |
3259 | 3262 | | |
3260 | 3263 | | |
| 3264 | + | |
| 3265 | + | |
| 3266 | + | |
| 3267 | + | |
| 3268 | + | |
| 3269 | + | |
3261 | 3270 | | |
3262 | 3271 | | |
3263 | 3272 | | |
3264 | 3273 | | |
3265 | 3274 | | |
3266 | 3275 | | |
3267 | 3276 | | |
3268 | | - | |
| 3277 | + | |
| 3278 | + | |
3269 | 3279 | | |
3270 | 3280 | | |
3271 | 3281 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
63 | 66 | | |
64 | 67 | | |
65 | 68 | | |
| |||
179 | 182 | | |
180 | 183 | | |
181 | 184 | | |
182 | | - | |
183 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
184 | 189 | | |
185 | 190 | | |
186 | 191 | | |
| |||
0 commit comments