Mobile App WikiMobile App Wiki
WikiApp DiscoverDiscuss

Wiki

    mobileapp.wiki

    Wiki

    • ASO17
    • Monetization14
    • Store Policies20
    • Metrics15
    • Development25
    • Marketing15
    • Legal9
    • UI/UX14
    • Testing10
    • Infrastructure10

    mobileapp.wiki

    Home/Infrastructure/Rate Limiting and API Security for Mobile Backends
    Infrastructure3 min read

    Rate Limiting and API Security for Mobile Backends

    How to protect your mobile API with rate limiting, authentication, input validation, certificate pinning, and common attack prevention strategies.

    Rate Limiting and API Security for Mobile Backends

    Table of Contents

    Why Mobile APIs Need Special ProtectionRate LimitingCommon AlgorithmsRate Limit HeadersRecommended LimitsAuthentication and AuthorizationToken-Based AuthenticationOAuth 2.0 with PKCEAPI KeysTransport SecurityCertificate PinningInput ValidationCommon Attack VectorsMonitoringRelated Topics

    Why Mobile APIs Need Special Protection

    Your mobile API is publicly accessible. Anyone with a proxy tool like Charles or mitmproxy can inspect every request your app makes, extract API endpoints, and replay or modify them. Unlike web APIs that can rely partly on CORS, mobile APIs must assume that every request could be crafted by a malicious actor.

    Reverse-engineered APKs expose your entire API contract, hardcoded secrets are extracted within hours, and automated bots can hammer your endpoints at scale.

    Rate Limiting

    Rate limiting controls how many requests a client can make within a given time window. It protects against abuse, prevents resource exhaustion, and ensures fair usage.

    Common Algorithms

    • Fixed Window - Count requests in fixed intervals (e.g., 100/minute). Simple but allows bursts at boundaries.
    • Sliding Window - Tracks requests over a rolling period. Smoother, no boundary burst issue.
    • Token Bucket - Clients have tokens that refill at a steady rate. Each request consumes one. Allows short bursts while maintaining average limits. Most common in production.

    Rate Limit Headers

    Always return rate limit information in response headers:

    • X-RateLimit-Limit - Maximum requests allowed in the window
    • X-RateLimit-Remaining - Requests remaining in the current window
    • X-RateLimit-Reset - Unix timestamp when the window resets
    • Retry-After - Seconds to wait before retrying (on 429 responses)

    Recommended Limits

    Endpoint TypeSuggested LimitWindow
    Authentication (login/register)5-10 requestsper minute
    Password reset3 requestsper hour
    Standard API reads100-300 requestsper minute
    Write operations30-60 requestsper minute
    File uploads10 requestsper minute

    Authentication and Authorization

    Token-Based Authentication

    JWT is the standard for mobile API authentication. Use short-lived access tokens (15-60 minutes) and long-lived refresh tokens (30-90 days). Store tokens securely in iOS Keychain or Android EncryptedSharedPreferences. Never use plain UserDefaults or SharedPreferences.

    OAuth 2.0 with PKCE

    For social login, use OAuth 2.0 with PKCE (Proof Key for Code Exchange) to prevent authorization code interception. Use ASWebAuthenticationSession on iOS, Custom Tabs on Android. Never use embedded WebViews.

    API Keys

    API keys identify the app, not the user. Rotate every 90 days, use different keys per environment, and always combine with user authentication.

    Transport Security

    All mobile API communication must use HTTPS. Both Apple (ATS) and Google (Network Security Configuration) enforce this by default. Use TLS 1.3 where possible.

    Certificate Pinning

    Pin the public key (SPKI), not the full certificate, for easier rotation. Always include a backup pin and implement a remote kill switch to disable pinning if a pin becomes invalid.

    Input Validation

    Validate every input on the server side: type checking, length limits, format validation, SQL injection prevention with parameterized queries, and XSS prevention with content sanitization.

    Common Attack Vectors

    AttackPrevention
    Brute force loginRate limit + account lockout
    API scrapingRate limiting, bot detection
    Replay attacksTimestamps and nonces
    Man-in-the-middleTLS + certificate pinning
    Token theftShort-lived tokens, secure storage
    InjectionParameterized queries, sanitization

    Monitoring

    Log all authentication failures with IP and device fingerprint. Set up alerts for unusual traffic patterns. Maintain an IP blocklist updatable without app deployment. Use a WAF (Cloudflare or AWS WAF) as a first line of defense.

    Related Topics

    • API Design: REST vs GraphQL
    • WebSocket and Real-time Communication
    • Error Monitoring and Logging

    How did you find this content?

    Share

    ← Previous

    Firebase for Mobile Apps: The Complete Guide for 2026

    Next →

    Supabase for Mobile Apps: The Open-Source Firebase Alternative

    Related Content

    Firebase for Mobile Apps: The Complete Guide for 2026

    A practical guide to Firebase services for mobile developers covering Authentication, Firestore, Cloud Functions, Crashlytics, and cost optimization.

    Supabase for Mobile Apps: The Open-Source Firebase Alternative

    How to use Supabase as a mobile backend with Postgres, real-time subscriptions, Row Level Security, Edge Functions, and self-hosting options.

    Mobile Analytics Platforms Compared: Choosing the Right Tool in 2026

    A comparison of mobile analytics platforms including Firebase Analytics, Amplitude, Mixpanel, PostHog, and Apple App Analytics with pricing and use cases.

    Remote Config and Feature Flags: Control Your App Without Deploying

    How to use remote config and feature flags to control app behavior without app store updates using Firebase Remote Config, LaunchDarkly, and Statsig.

    CDN and Asset Delivery for Mobile Apps

    How CDNs improve mobile app performance through image optimization, edge caching, and efficient asset delivery using Cloudflare, CloudFront, and Imgix.