0Pricing
AI Powered SaaS: Stripe + Auth + Billing + Deploy · Lektion

Rate Limiting und Schutz vor Brute-Force-Angriffen

Schützen Sie Ihre SaaS-Authentifizierung und APIs mit Rate Limiting, Kontosperren und exponentiellem Backoff unter Verwendung eines schnellen Stores wie Redis vor Missbrauch

Rate Limiting und Schutz vor Brute-Force-Angriffen ist eine kostenlose AI Powered SaaS: Stripe + Auth + Billing + Deploy-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des AI Powered SaaS: Stripe + Auth + Billing + Deploy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der AI Powered SaaS: Stripe + Auth + Billing + Deploy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

Why Rate Limit?

Without limits, attackers can hammer your login endpoint to guess passwords, scrape data, or run up costs on metered APIs. Rate limiting caps how many requests a client can make in a window.

Identifying the Client

Limits are keyed on something that identifies the caller: an IP address, a user ID, or an API key. Choose the key based on what you are protecting.

const key = 'login:' + (userId ?? clientIp);

The Fixed Window Algorithm

The simplest method counts requests per fixed time window. If the count exceeds the limit, reject until the window resets.

// allow 5 requests per 60 seconds
if (count > 5) return reject();

Counting in Redis

Redis is ideal: INCR bumps a counter atomically, and a TTL auto-expires the window. The first request sets the expiry.

const n = await redis.incr(key);
if (n === 1) await redis.expire(key, 60);
if (n > 5) throw new Error('Too many requests');

Sliding Window & Token Bucket

Fixed windows allow bursts at the edges. Sliding window smooths this, and token bucket permits short bursts while enforcing an average rate. Libraries like Upstash Ratelimit implement these for you.

import { Ratelimit } from '@upstash/ratelimit';
const rl = new Ratelimit({ redis, limiter: Ratelimit.slidingWindow(5, '60 s') });

Applying in Middleware

Centralize limiting in Next.js middleware so it runs before every matched request.

export async function middleware(req) {
  const { success } = await rl.limit(req.ip ?? 'anon');
  if (!success) return new Response('Rate limited', { status: 429 });
}

Returning 429 Properly

When limited, respond with status 429 and a Retry-After header telling clients when to try again.

return new Response('Too many requests', {
  status: 429,
  headers: { 'Retry-After': '60' }
});

Account Lockout

For login specifically, track failed attempts per account. After several failures, temporarily lock the account to stop targeted brute force.

const fails = await redis.incr('fail:' + email);
if (fails >= 5) await redis.expire('lock:' + email, 900);

Exponential Backoff

Increase the delay after each failure: 1s, 2s, 4s, 8s. This frustrates automated guessing while barely affecting legitimate users.

const delay = Math.min(2 ** fails, 60) * 1000;

Avoiding False Positives

Be careful not to punish real users:

  • Shared office IPs share a limit — prefer per-user keys when authenticated
  • Reset counters on success
  • Set generous limits for normal usage

Best Practices

Protect endpoints well:

  • Key limits on IP, user, or API key
  • Use Redis with sliding window or token bucket
  • Return 429 with Retry-After
  • Add lockout and backoff for login

Quick Check

Test your rate-limiting knowledge.

Recap

You learned to defend against abuse:

  • Key rate limits on IP, user, or API key
  • Count with Redis INCR and TTL, or use sliding window libraries
  • Return 429 with Retry-After
  • Add account lockout and exponential backoff for logins

Your auth and APIs now resist brute force and flooding.

Häufig gestellte Fragen

Ist die Lektion „Rate Limiting und Schutz vor Brute-Force-Angriffen“ kostenlos?

Ja — der vollständige Text von „Rate Limiting und Schutz vor Brute-Force-Angriffen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des AI Powered SaaS: Stripe + Auth + Billing + Deploy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der AI Powered SaaS: Stripe + Auth + Billing + Deploy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Rate Limiting und Schutz vor Brute-Force-Angriffen“?

Schützen Sie Ihre SaaS-Authentifizierung und APIs mit Rate Limiting, Kontosperren und exponentiellem Backoff unter Verwendung eines schnellen Stores wie Redis vor Missbrauch Du übst AI Powered SaaS: Stripe + Auth + Billing + Deploy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um AI Powered SaaS: Stripe + Auth + Billing + Deploy zu starten?

Keine Vorkenntnisse erforderlich. AI Powered SaaS: Stripe + Auth + Billing + Deploy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.

Wie lange dauert die Lektion „Rate Limiting und Schutz vor Brute-Force-Angriffen“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser AI Powered SaaS: Stripe + Auth + Billing + Deploy-Lektion Code schreiben und ausführen?

Ja. Jede AI Powered SaaS: Stripe + Auth + Billing + Deploy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. OAuth-2.0-Integration
  2. Multi-Faktor-Authentifizierung (MFA)
  3. Rollenbasierte Zugriffskontrolle (RBAC)
  4. Rate Limiting und Schutz vor Brute-Force-Angriffen
← Zurück zu AI Powered SaaS: Stripe + Auth + Billing + Deploy