Opt-outs for the secure defaults; isPathVisibleIn in construction/logic

- setUnknownIpFactor (0 = old free pass), UNKNOWN_IP_FACTOR exported
- createContentHelpers({ settingsDepth }) and markdown/mcp isPathVisible overrides
- <RenderRichText safeLinks={false}>
- resolveRedirect({ draft: true }) for preview
- isPathVisibleIn(mode, path), pathOf, PathVisibility exported; page route uses it

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-22 17:35:08 +02:00
co-authored by Claude Opus 5.5
parent 4585e0fc69
commit 0fd57c1d6a
13 changed files with 144 additions and 24 deletions
+23 -5
View File
@@ -77,10 +77,24 @@ type CheckArgs = { cost?: number } & RateLimitArgs
* capping the flood.
*/
export const UNKNOWN_IP_KEY = 'unknown-ip'
/** Default multiplier for the shared no-IP bucket. */
export const UNKNOWN_IP_FACTOR = 20
function resolveKey(key: string, max: number): { key: string; max: number } {
return key ? { key, max } : { key: UNKNOWN_IP_KEY, max: max * UNKNOWN_IP_FACTOR }
let unknownIpFactor = UNKNOWN_IP_FACTOR
/**
* How requests with no client IP are limited, for every limiter in the plugin:
* the shared bucket's limit is `factor` × max. `0` = let them through
* unlimited (the behaviour before 1.13 — only when a limiter in front, e.g.
* Cloudflare, already covers them). Default UNKNOWN_IP_FACTOR.
*/
export function setUnknownIpFactor(factor: number): void {
unknownIpFactor = Math.max(0, factor)
}
function resolveKey(key: string, max: number): { key: string; max: number } | null {
if (key) {return { key, max }}
return unknownIpFactor > 0 ? { key: UNKNOWN_IP_KEY, max: max * unknownIpFactor } : null
}
function hitMemory(id: string, cost: number, windowMs: number): Bucket {
@@ -102,10 +116,12 @@ function hitMemory(id: string, cost: number, windowMs: number): Bucket {
*
* Returns true when the request is within the limit, false when it should be
* rejected. A missing key (no IP) counts against one shared bucket with
* UNKNOWN_IP_FACTOR × max.
* UNKNOWN_IP_FACTOR × max (setUnknownIpFactor).
*/
export function checkRateLimit({ cost = 1, key: rawKey, max: rawMax = 5, scope = 'form', windowMs = 60_000 }: CheckArgs): boolean {
const { key, max } = resolveKey(rawKey, rawMax)
const resolved = resolveKey(rawKey, rawMax)
if (!resolved) {return true}
const { key, max } = resolved
const id = `${scope}:${key}`
const current = buckets.get(id)
const used = current && current.resetAt > Date.now() ? current.count : 0
@@ -127,7 +143,9 @@ export async function consumeRateLimit({
scope = 'form',
windowMs = 60_000,
}: CheckArgs): Promise<{ ok: boolean; retryAfter: number }> {
const { key, max } = resolveKey(rawKey, rawMax)
const resolved = resolveKey(rawKey, rawMax)
if (!resolved) {return { ok: true, retryAfter: 0 }}
const { key, max } = resolved
const id = `${scope}:${key}`
let bucket: Bucket