Canvix — Free & open-source graphic design tool. A community-built Canva alternative with a drag-and-drop editor, templates, shapes, text, images & one-click export. Works on desktop, tablet & mobile.
TypeScript canva-alternativecanvasdesigndesign-tooldrag-and-dropeditorgraphic-designkonvanextjsopen-sourcereactself-hostedtemplatestypescript
fix: CANVIX_RATE_LIMITS=off now disables the auth limiter too
Ashiq Hussain Mir4886b6dc2070
diff --git a/src/lib/ai/provider-rate-limit.test.ts b/src/lib/ai/provider-rate-limit.test.tsnew file mode 100644index 0000000..7545e1b--- /dev/null+++ b/src/lib/ai/provider-rate-limit.test.ts@@ -0,0 +1,38 @@+import { afterEach, describe, expect, it } from 'vitest'+import { rateLimit } from './provider'++// The limiter the auth routes use (predates lib/rate-limit.ts).+// v0.18: CANVIX_RATE_LIMITS=off is the documented "turn EVERYTHING+// off" switch — this limiter must honour it too, or CI e2e (which+// registers one account per spec module on one localhost) burns the+// 5/h register cap halfway through the suite.++const req = (headers: Record<string, string> = {}) => ({ headers: new Map(Object.entries(headers)) }) as unknown as Parameters<typeof rateLimit>[1]++describe('rateLimit (ai/provider) — the CANVIX_RATE_LIMITS=off kill switch', () => {+ const ENV = 'CANVIX_RATE_LIMITS'++ afterEach(() => {+ delete process.env[ENV]+ })++ it('limits normally when the env is unset', () => {+ delete process.env[ENV]+ expect(rateLimit('t:on', req(), 2, 60).ok).toBe(true)+ expect(rateLimit('t:on', req(), 2, 60).ok).toBe(true)+ expect(rateLimit('t:on', req(), 2, 60).ok).toBe(false)+ })++ it('CANVIX_RATE_LIMITS=off disables the limiter entirely', () => {+ process.env[ENV] = 'off'+ for (let i = 0; i < 10; i++) {+ expect(rateLimit('t:off', req(), 1, 60).ok).toBe(true)+ }+ })++ it('any other value keeps the limiter on (strict opt-in)', () => {+ process.env[ENV] = '0'+ expect(rateLimit('t:other', req(), 1, 60).ok).toBe(true)+ expect(rateLimit('t:other', req(), 1, 60).ok).toBe(false)+ })+})diff --git a/src/lib/ai/provider.ts b/src/lib/ai/provider.tsindex 77bd3d6..dfe4b8f 100644--- a/src/lib/ai/provider.ts+++ b/src/lib/ai/provider.ts@@ -306,6 +306,13 @@ export interface RateLimitResult {* self-hosted design tool but stop runaway loops and abuse.*/export function rateLimit(feature: string, req: Pick<NextRequest, 'headers'>, limit: number, windowSec: number): RateLimitResult {+ // CANVIX_RATE_LIMITS=off is the documented kill switch ("Turn+ // everything off" — README → Rate limiting), and "everything" must+ // include the auth limits that predate lib/rate-limit.ts: the CI e2e+ // suite registers one account per spec module on a single localhost+ // and would otherwise burn the 5/h register cap halfway through.+ // Opt-in, operator-controlled, same semantics as lib/rate-limit.ts.+ if (process.env.CANVIX_RATE_LIMITS === 'off') return { ok: true, retryAfterSec: 0 }const ip =req.headers.get('x-forwarded-for')?.split(',')[0]?.trim() ||req.headers.get('x-real-ip') ||