Zum Hauptinhalt springen
LIVE Intel Feed
"Not a Pentest" Notice: Rate Limiting schützt eigene APIs vor Überlastung. Kein Angriffswerkzeug.
Moltbot AI Security · API Rate Limiting

Moltbot API Rate Limiting: Redis Sliding Window & DDoS Protection 2026

Ohne Rate Limiting sind APIs anfällig für DDoS und Abuse. Redis-basierte Sliding Window Algorithmen sind heute State-of-the-Art für hochverfügbare Systeme.

Was ist API Rate Limiting? Einfach erklärt

Stell dir eine Schalterkabine vor, die nur 100 Kunden pro Minute hereinlässt. Wer zu schnell too often klopft, muss kurz warten. Rate Limiting funktioniert genau so: Es begrenzt, wie oft ein Nutzer (oder eine IP) deine API in einem Zeitfenster aufrufen darf. Das verhindert DDoS-Angriffe, API-Abuse (z.B. konkurrierende Scraper) und Modell-Extraktion (jemand ruft dein LLM systematisch ab, um es zu klonen).

↓ Springe zu Strategie-Vergleich, Redis Sliding Window und DDoS Protection Layer

Rate Limiting Strategien

StrategieUse CaseSpeicherGenauigkeit
Fixed WindowEinfach, schnellMinimalNiedrig
Sliding WindowPräzise, fairMittelHoch
Token BucketBurst-fähigMittelMittel
Distributed Sliding WindowMulti-ServerRedisHoch

Redis Sliding Window Implementation

// Redis Sliding Window Rate Limiter für Moltbot

const Redis = require('ioredis');

const redis = new Redis(process.env.REDIS_URL);

class SlidingWindowRateLimiter {

  constructor(options = {}) {

    this.windowSize = options.windowSize || 60000; // 1 minute

    this.maxRequests = options.maxRequests || 100;

    this.keyPrefix = options.keyPrefix || 'rate_limit:';

  }

  async isAllowed(key, identifier) {

    const now = Date.now();

    const windowStart = now - this.windowSize;

    const redisKey = this.keyPrefix + key + ':' + identifier;

    await redis.zremrangebyscore(redisKey, 0, windowStart);

    const currentRequests = await redis.zcard(redisKey);

    if (currentRequests >= this.maxRequests) {

      return {

        allowed: false,

        remaining: 0,

        resetTime: now + this.windowSize,

        totalRequests: currentRequests

      };

    }

    await redis.zadd(redisKey, now, now);

    await redis.expire(redisKey, Math.ceil(this.windowSize / 1000));

    return {

      allowed: true,

      remaining: this.maxRequests - currentRequests - 1,

      resetTime: now + this.windowSize,

      totalRequests: currentRequests + 1

    };

  }

  middleware(options = {}) {

    const limiter = new SlidingWindowRateLimiter(options);

    return async (req, res, next) => {

      const key = options.key || 'api';

      const identifier = this.getIdentifier(req);

      const result = await limiter.isAllowed(key, identifier);

      res.set({

        'X-RateLimit-Limit': limiter.maxRequests,

        'X-RateLimit-Remaining': result.remaining,

        'X-RateLimit-Reset': Math.ceil(result.resetTime / 1000)

      });

      if (!result.allowed) {

        return res.status(429).json({

          error: 'Too Many Requests',

          retryAfter: Math.ceil((result.resetTime - Date.now()) / 1000)

        });

      }

      next();

    };

  }

  getIdentifier(req) {

    const ip = req.ip || req.connection.remoteAddress;

    const userId = req.user?.id;

    return userId ? 'user:' + userId : 'ip:' + ip;

  }

}

const rateLimiter = new SlidingWindowRateLimiter({

  windowSize: 60000, // 1 minute

  maxRequests: 100,

  keyPrefix: 'moltbot:'

});

app.use('/api', rateLimiter.middleware({

  windowSize: 60000,

  maxRequests: 100,

  key: 'general'

}));

DDoS Protection Layer

// DDoS Protection für Moltbot

class DDoSProtection {

  constructor(redisClient) {

    this.redis = redisClient;

    this.thresholds = {

      ip: { requests: 1000, window: 60000 }, // 1000 req/min per IP

      global: { requests: 10000, window: 60000 }, // 10k req/min global

      endpoint: { requests: 500, window: 60000 } // 500 req/min per endpoint

    };

  }

  async checkRequest(req) {

    const ip = req.ip || req.connection.remoteAddress;

    const endpoint = req.path;

    const now = Date.now();

    const ipKey = 'ddos:ip:' + ip;

    const ipCount = await this.redis.incr(ipKey);

    if (ipCount === 1) await this.redis.expire(ipKey, 60);

    if (ipCount > this.thresholds.ip.requests) {

      await this.blockIP(ip, 3600); // Block for 1 hour

      return { blocked: true, reason: 'IP rate limit exceeded' };

    }

    const globalKey = 'ddos:global';

    const globalCount = await this.redis.incr(globalKey);

    if (globalCount === 1) await this.redis.expire(globalKey, 60);

    if (globalCount > this.thresholds.global.requests) {

      return { blocked: true, reason: 'Global rate limit exceeded' };

    }

    const endpointKey = 'ddos:endpoint:' + endpoint;

    const endpointCount = await this.redis.incr(endpointKey);

    if (endpointCount === 1) await this.redis.expire(endpointKey, 60);

    if (endpointCount > this.thresholds.endpoint.requests) {

      return { blocked: true, reason: 'Endpoint rate limit exceeded' };

    }

    return { blocked: false };

  }

  async blockIP(ip, duration) {

    const blockKey = 'blocked:ip:' + ip;

    await this.redis.setex(blockKey, duration, '1');

    await this.redis.lpush('ddos:blocks', JSON.stringify({

      ip,

      timestamp: Date.now(),

      duration,

      reason: 'Rate limit exceeded'

    }));

  }

  async isIPBlocked(ip) {

    const blockKey = 'blocked:ip:' + ip;

    return await this.redis.exists(blockKey);

  }

}

const ddosProtection = new DDoSProtection(redis);

app.use(async (req, res, next) => {

  if (await ddosProtection.isIPBlocked(req.ip)) {

    return res.status(403).json({ error: 'IP blocked' });

  }

  const result = await ddosProtection.checkRequest(req);

  if (result.blocked) {

    return res.status(429).json({ 

      error: 'Rate limit exceeded',

      reason: result.reason 

    });

  }

  next();

});
CG

ClawKing Security Team

✓ Verified
Security Research & Engineering · API Security Specialists
📅 Veröffentlicht: 27.04.2026🔄 Zuletzt geprüft: 27.04.2026
Dieser Guide basiert auf praktischer Erfahrung mit Redis-basiertem Rate Limiting in Hochlast-Produktionsumgebungen. Die Code-Beispiele sind produktionsreif und in Moltbot-Deployments getestet.
🔒 Verifiziert von ClawKing Security Team·Alle Informationen fact-checked und peer-reviewed

Weiterführende Ressourcen

🔒 Quantum-Resistant Mycelium Architecture
🛡️ Kuratierte Runbooks – EU-gehostet in Frankfurt
🌐 Zero Known Breaches – Powered by Living Intelligence
🏛️ DSGVO Art. 25 & 32 • SOC 2 & ISO 27001 in Vorbereitung
⚡ Real-Time Global Mycelium Network – 347 Bedrohungen in 60 Minuten
🧬 Trusted by SecOps Leaders worldwide