WAF & Rate Limiting

Request protection, rate limiting, and security monitoring

WAF & Rate Limiting

Data Border uses Arcjet for Web Application Firewall (WAF) protection and intelligent rate limiting.

Arcjet Protection

Arcjet provides real-time protection against:

  • Bot attacks
  • Credential stuffing
  • Suspicious request patterns
  • DDoS attempts
  • Common web exploits

Configuration

Enable by setting:

ARCJET_KEY=ajkey_your_key_here

When configured, all requests pass through Arcjet's security layer before reaching Data Border.


Rate Limits

Per-Endpoint Limits

EndpointLimitWindowScope
/auth/initialize5 requests10 secondsPer IP
/auth/redirectNo additional limit-Called by Amazon
/api/pii/getPII/*1 request1 hourPer order
/api/pii/getFile50 requests24 hoursPer tenant
/api/*Adaptive-Per IP (Arcjet)
/passthrough-api/*Amazon limits-Per seller

PII Access Throttling

The strictest rate limiting applies to PII access:

Loading diagram...

This prevents bulk extraction of customer data.

File Operation Limits

File operations are limited to prevent abuse:

OperationDaily LimitPer
getFile50Tenant
writeFileNo hard limitRequires recent PII access
deleteFileNo hard limit-

Adaptive Rate Limiting

Arcjet uses machine learning to detect suspicious patterns:

What Triggers Limits

  • Unusually high request volume
  • Requests from known bad IPs
  • Bot-like request patterns
  • Rapid authentication attempts
  • Geographic anomalies

Response Headers

Rate-limited responses include:

HTTP/1.1 429 Too Many Requests
Retry-After: 60
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1640995260

Suspicious Activity Detection

Data Border monitors for patterns that may indicate misuse:

Flagged Behaviors

BehaviorResponse
Accessing PII for shipped ordersLogged as suspicious
Accessing PII for other sellers' ordersBlocked + logged
Repeated failed authenticationRate limited
Unusual access patternsLogged for review

Logging

Suspicious activity is logged with full context:

{
  "type": "security",
  "event": "suspicious_pii_access",
  "orderId": "123-456-789",
  "sellerId": "seller_abc",
  "tenantId": "tenant_xyz",
  "reason": "order_already_shipped",
  "ip": "203.0.113.42",
  "userAgent": "WMS-Client/1.0",
  "timestamp": "2024-01-15T10:30:00.000Z"
}

IP-Based Protection

Blocked by Default

  • Known malicious IPs (threat intelligence)
  • Tor exit nodes (configurable)
  • Data center IPs without proper identification

Trusted Sources

Requests from Amazon's infrastructure are trusted for:

  • OAuth callbacks
  • Notification webhooks (when verified)

Request Validation

Header Validation

Required headers are validated before processing:

// Enforced for all authenticated endpoints
const requiredHeaders = [
  'x-seller-access-token',  // For seller ops
  'x-amazon-token-secret'   // For Amazon access
]

// Validated
headers['x-original-url']  // Must be whitelisted carrier

Body Validation

Request bodies are validated using Zod schemas:

// Example: Create tenant validation
const createTenantSchema = z.object({
  name: z.string().min(1),
  redirectOrigin: z.string().url().startsWith('https://')
})

HTTPS Enforcement

All traffic must use HTTPS:

Loading diagram...
  • HTTP requests are redirected to HTTPS
  • HSTS headers are set
  • TLS 1.2+ required

CORS Configuration

Cross-Origin Resource Sharing is configured per route:

RouteCORS
/health-checkOpen
/auth/*Configured per tenant
/api/*Configured per tenant

Error Responses

Rate Limit Exceeded

{
  "is_adb_error": true,
  "success": false,
  "error": {
    "message": "Rate limit exceeded",
    "details": "Please retry after 60 seconds"
  }
}

Security Block

{
  "is_adb_error": true,
  "success": false,
  "error": {
    "message": "Request blocked",
    "details": "Suspicious activity detected"
  }
}

Invalid Token

{
  "is_adb_error": true,
  "success": false,
  "error": {
    "message": "Invalid or expired token"
  }
}

Implementing Client-Side Handling

Retry with Backoff

async function callAdbWithRetry(url, options, maxRetries = 3) {
  for (let attempt = 0; attempt < maxRetries; attempt++) {
    const response = await fetch(url, options)
    
    if (response.status === 429) {
      const retryAfter = response.headers.get('Retry-After') || 60
      console.log(`Rate limited, waiting ${retryAfter}s`)
      await sleep(retryAfter * 1000)
      continue
    }
    
    if (response.status === 403) {
      // Don't retry security blocks
      throw new SecurityBlockError(await response.json())
    }
    
    return response
  }
  
  throw new Error('Max retries exceeded')
}

PII Throttle Handling

async function getPII(orderId) {
  try {
    return await adb.get(`/api/pii/getPII/${orderId}`)
  } catch (error) {
    if (error.status === 429) {
      // Already fetched recently, use cached or skip
      const cached = await cache.get(`pii:${orderId}`)
      if (cached) return cached
      
      // Wait and retry
      await sleep(60 * 60 * 1000) // 1 hour
      return await getPII(orderId)
    }
    throw error
  }
}

Monitoring & Alerts

Key Metrics

MetricAlert Threshold
429 response rate> 5% of requests
Security blocksAny
Auth failures> 10/minute
PII access attempts on blocked ordersAny

Log Analysis

Search for security events:

# Find security blocks
grep '"type":"security"' /var/log/adb.log | jq

# Find rate limit events
grep '429' /var/log/adb.log | jq '.path, .ip'

Best Practices

Avoid Rate Limits

  1. Cache tokens - Don't regenerate on every request
  2. Batch operations - Combine requests where possible
  3. Implement backoff - Respect Retry-After headers
  4. Use webhooks - Subscribe to notifications instead of polling

Secure Your Integration

  1. Validate tokens - Check expiry before use
  2. Rotate secrets - Generate new tenant if compromised
  3. Monitor logs - Watch for unusual patterns
  4. Use least privilege - Only access what's needed

Next Steps

Deployment Security

Secure your Data Border deployment.

Audit & Compliance

Understand audit logging.