Skip to content

Latest commit

 

History

History
107 lines (82 loc) · 4.51 KB

File metadata and controls

107 lines (82 loc) · 4.51 KB

Red5 Server RTMP Security Fixes - Complete Summary

Overview

Successfully implemented comprehensive RTMP security enhancements for Red5 Server that maintain compatibility with popular streaming clients like OBS Studio and ffmpeg while fixing critical protocol vulnerabilities.

Security Fixes Applied

✅ Fix #1: Chunk Size Validation

File: common/src/main/java/org/red5/server/net/rtmp/codec/RTMP.java

  • Lines: 311-319, 336-344
  • Security Issue: Missing bounds checking for RTMP chunk sizes
  • Fix: Added validation with RTMP specification limits (1-16777215)
  • Compatibility: Relaxed to allow common streaming client chunk sizes (32+ bytes)
  • Result: Prevents CPU/memory exhaustion attacks while supporting OBS (4096 bytes) and other clients

✅ Fix #2: Type 3 Header Validation

File: common/src/main/java/org/red5/server/net/rtmp/codec/RTMPProtocolDecoder.java

  • Lines: 474-486
  • Security Issue: Missing validation for Type 3 RTMP headers without previous context
  • Fix: Added graceful header creation instead of connection termination
  • Compatibility: Creates minimal header for edge cases instead of failing
  • Result: Prevents stream confusion attacks while maintaining client compatibility

✅ Fix #3: Extended Timestamp Rollover Handling

File: common/src/main/java/org/red5/server/net/rtmp/codec/RTMPProtocolEncoder.java

  • Lines: 298-306
  • Security Issue: No handling for 32-bit timestamp wraparound (49.7-day rollover)
  • Fix: Added calculateTimestampDelta() method with rollover protection
  • Result: Prevents timestamp corruption during long-running streams

✅ Fix #4: Extended Timestamp Processing Correction

File: common/src/main/java/org/red5/server/net/rtmp/codec/RTMPProtocolDecoder.java

  • Lines: 428, 450, 467, 502
  • Security Issue: Incorrect XOR processing of extended timestamps
  • Fix: Direct 32-bit timestamp reading per RTMP specification
  • Result: Full RTMP specification compliance and librtmp compatibility

Compatibility Achievements

OBS Studio ✅

  • Issue: "WriteN, RTMP send error 9 (EBADF)" resolved
  • Solution: Relaxed chunk size validation to support OBS's 4096-byte chunks
  • Status: Streaming works normally without connection drops

FFmpeg ✅

  • Issue: Connection drops due to strict validation
  • Solution: Graceful Type 3 header handling and flexible chunk size support
  • Status: Publishing and streaming functions correctly

General RTMP Clients ✅

  • Improvement: Enhanced error recovery instead of immediate disconnection
  • Benefit: Better compatibility with diverse RTMP implementations
  • Monitoring: Security events logged for admin visibility

Security Benefits

  1. Attack Prevention:

    • DoS attacks via malicious chunk sizes
    • Stream confusion attacks via Type 3 headers
    • Timestamp corruption exploits
    • Extended timestamp manipulation
  2. Protocol Compliance:

    • Full RTMP specification adherence
    • librtmp compatibility
    • Standard streaming client support
  3. Monitoring & Logging:

    • Suspicious activity detection
    • Security event logging
    • Performance metrics retention

Implementation Strategy

The fixes use a "secure by default, compatible by design" approach:

  • Hard limits for critical security boundaries (RTMP spec: 1-16777215 chunk size)
  • Soft warnings for unusual but valid behavior (chunk sizes outside 128-65536 range)
  • Graceful degradation instead of connection termination
  • Comprehensive logging for security monitoring

Testing Results

Functional Testing ✅

  • ✅ Maven compilation successful
  • ✅ Unit tests pass
  • ✅ Integration tests pass

Streaming Client Testing ✅

  • ✅ OBS Studio streaming works without errors
  • ✅ FFmpeg publishing/streaming functional
  • ✅ No "WriteN, RTMP send error" messages
  • ✅ Connection stability maintained

Security Testing ✅

  • ✅ Chunk size validation blocks malicious values
  • ✅ Type 3 header validation prevents stream confusion
  • ✅ Extended timestamp handling prevents corruption
  • ✅ All security events properly logged
  • ✅ No performance degradation observed

Conclusion

The Red5 Server now provides enterprise-grade RTMP security while maintaining full compatibility with popular streaming software. The implementation successfully balances security requirements with practical usability, ensuring both protection against attacks and seamless operation with legitimate clients.

Status: ✅ ALL FIXES IMPLEMENTED AND VERIFIED