Skip to content

Commit 170f9f8

Browse files
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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/plugin-auth': patch
3+
---
4+
5+
fix(plugin-auth): Setup → Authentication says which auth rate limit runs while nothing is saved for it
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Who sees it: an administrator reading Setup → Authentication, Anti-abuse, on a deployment where nothing is saved for the two rate-limit fields.
11+
12+
- **What was wrong.** With nothing saved, the two fields read 10 requests per 60 seconds, the console defaults. No request was held to that cap. Without a `rateLimit` in the server configuration, the auth library's own per-path limits run, and only in production. With one, that limit runs as one limit for every path that has no rule of its own, and the auth library keeps its own rules for sign-in, sign-up and password reset.
13+
- **What the page says now.** While neither field has a saved value or an `OS_*` override, the page's live-status banner states, as an `info`, that the cap the fields show is not applied and which limit runs instead. That is one of: the auth library's own per-path limits; the server configuration's pair, printed as the auth library reads it (an `enabled` left out means production only); or rate limiting turned off by the server configuration. It also says that a saved value applies to sign-in, sign-up, password reset, invitation acceptance and the phone-code endpoints. The statement comes after any `warning` the page already states, in all eleven console languages.
14+
- **What does not change.** The two fields still read 10 and 60 with `source: 'default'`. No value, source or save rule changes. Once either field is saved, the banner drops this statement and the saved pair runs as before.

‎packages/plugins/plugin-auth/src/auth-plugin.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ import {
161161
import {
162162
combineAuthLiveStatus,
163163
describeEmailPasswordLiveStatus,
164+
describeRateLimitLiveStatus,
164165
describeSignUpLiveStatus,
165166
type AuthLiveStatus,
166167
} from './auth-settings-live-status.js';
@@ -3234,7 +3235,9 @@ export class AuthPlugin implements Plugin {
32343235
// Setup → Authentication states what runs when a switch says otherwise:
32353236
// email and password stored on that a cloud-managed runtime does not
32363237
// apply, or any other disagreement; sign-up stored on where the
3237-
// deployment forces it off. See auth-settings-live-status.ts.
3238+
// deployment forces it off; and, while nothing is saved for the
3239+
// rate-limit pair, the limit that runs in place of the 10 / 60 it shows.
3240+
// See auth-settings-live-status.ts.
32383241
if (typeof settings.registerLiveStatus === 'function') {
32393242
const floorDeps = this.signInMethodFloorDeps(ctx, this.authManager);
32403243
try {
@@ -3258,14 +3261,21 @@ export class AuthPlugin implements Plugin {
32583261
emailPasswordShown,
32593262
locale,
32603263
}),
3264+
describeRateLimitLiveStatus({
3265+
shownMax: await settings.get('auth', 'rate_limit_max', pageCtx),
3266+
shownWindow: await settings.get('auth', 'rate_limit_window_seconds', pageCtx),
3267+
declared: this.declaredAuthOptions.rateLimit,
3268+
locale,
3269+
}),
32613270
]);
32623271
});
32633272
} catch (err: any) {
32643273
ctx.logger.warn(
32653274
'[auth] Setup → Authentication: the live status was NOT registered '
32663275
+ `(${String(err?.message ?? err)}), so where a saved email and password or sign-up value is not what `
32673276
+ 'runs (a cloud-managed or single-sign-on-only environment holding it off), the page shows the switch on '
3268-
+ 'with nothing saying it is off.',
3277+
+ 'with nothing saying it is off; and with no rate limit saved, the page shows a cap of 10 requests per 60 '
3278+
+ 'seconds that no request is held to.',
32693279
);
32703280
}
32713281
}

‎packages/plugins/plugin-auth/src/auth-settings-declared-defaults.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@
5959
* sign-in, sign-up and password-reset endpoints run on the auth library's
6060
* own per-path rules (and its production-only switch), or a declared
6161
* `rateLimit` that is not the per-endpoint cap the setting writes, so no
62-
* one number states what runs.
62+
* one number states what runs. The fields keep the manifest default, and
63+
* the page's live-status banner says in words which of the two runs until
64+
* a value is saved (`describeRateLimitLiveStatus`,
65+
* `auth-settings-live-status.ts`).
6366
* - `api_key_policy_started_at`: recorded into the store by the first boot
6467
* that runs the policy, so it is not left unstored.
6568
* - `google_enabled`: an intent toggle whose runtime default is the manifest
@@ -179,8 +182,10 @@ export const AUTH_DECLARED_DEFAULTS: Readonly<Record<string, (facts: AuthDeclare
179182
* setting is either stated or named here, never left out in silence.
180183
*/
181184
export const AUTH_KEYS_NOT_DECLARED: Readonly<Record<string, string>> = {
182-
rate_limit_max: 'the auth library\'s per-path rules run, not one number',
183-
rate_limit_window_seconds: 'the auth library\'s per-path rules run, not one number',
185+
rate_limit_max: 'the auth library\'s per-path rules or a declared global pair run, not one number: '
186+
+ 'the live-status banner states which until a value is saved',
187+
rate_limit_window_seconds: 'the auth library\'s per-path rules or a declared global pair run, not one number: '
188+
+ 'the live-status banner states which until a value is saved',
184189
api_key_policy_started_at: 'recorded into the store by the first boot',
185190
google_enabled: 'an intent toggle whose runtime default is the manifest default',
186191
google_client_id: 'a declared credential outranks a saved one',

0 commit comments

Comments
 (0)