Mitigation Strategy: Connection Limits (uWS Configuration)
-
Description:
- Identify Resource Limits: Determine the maximum concurrent connections your server can handle (RAM, CPU, network, OS limits).
- Configure
maxConnections
: In youruWS::App
oruWS::SSLApp
configuration, set themaxConnections
option to a value below your identified limits. This is a direct uWebSockets setting. - Test: Load test to ensure the limit is effective and doesn't negatively impact legitimate users.
-
Threats Mitigated:
- Denial of Service (DoS): (Severity: High) - Limits connections, preventing resource exhaustion.
- Distributed Denial of Service (DDoS): (Severity: High) - Makes DDoS more difficult by limiting the impact of each attacking node.
- Resource Exhaustion: (Severity: High) - Protects server resources.
-
Impact:
- DoS: Significantly reduces risk.
- DDoS: Reduces impact; server remains operational up to the limit.
- Resource Exhaustion: High impact; prevents crashes.
-
Currently Implemented:
- Example:
src/server.cpp
,uWS::App
configuration:maxConnections = 1000
.
- Example:
-
Missing Implementation:
- Example: The limit of 1000 might be too high; re-evaluate based on load testing.
Mitigation Strategy: Backpressure Handling (uWS API)
-
Description:
- Monitor
getBufferedAmount()
: In your WebSocket message handling, regularly callgetBufferedAmount()
on theuWS::WebSocket
object to check the send buffer size. - Set Thresholds: Define "warning" and "critical" thresholds for the buffered amount.
pause()
andresume()
:- If the "critical" threshold is exceeded, call
uWS::WebSocket::pause()
to stop reading from the socket. - When the buffer drains below the threshold, call
uWS::WebSocket::resume()
to resume reading. This directly uses uWebSockets' API for flow control.
- If the "critical" threshold is exceeded, call
- Monitor
-
Threats Mitigated:
- Denial of Service (DoS): (Severity: High) - Prevents fast clients/data floods from overwhelming buffers.
- Memory Exhaustion: (Severity: High) - Protects against excessive memory usage.
- Application Instability: (Severity: Medium) - Prevents buffer-related crashes.
-
Impact:
- DoS: High impact; prevents a specific DoS type.
- Memory Exhaustion: High impact; reduces risk.
- Application Instability: Medium impact; improves stability.
-
Currently Implemented:
- Example:
src/websocket_handler.cpp
checksgetBufferedAmount()
and logs warnings.
- Example:
-
Missing Implementation:
- Example:
pause()
andresume()
are not used. The application doesn't actively stop reading. Thresholds need review.
- Example:
Mitigation Strategy: Timeouts (uWS Configuration)
-
Description:
- Set
idleTimeout
: In youruWS::App
oruWS::SSLApp
configuration, set theidleTimeout
option (in seconds). This is a direct uWebSockets setting that controls how long a connection remains open without activity. - Test and Tune: Adjust the timeout based on your application's needs and network conditions.
- Set
-
Threats Mitigated:
- Slowloris Attacks: (Severity: High) - Closes connections held open by slow data sending.
- Resource Exhaustion: (Severity: Medium) - Frees resources from idle connections.
- Denial of Service (DoS): (Severity: Medium) - Mitigates Slowloris.
-
Impact:
- Slowloris Attacks: High impact; prevents the attack.
- Resource Exhaustion: Medium impact; reduces usage.
- DoS: Medium impact; protects against a specific type.
-
Currently Implemented:
- Example:
src/server.cpp
,uWS::App
configuration:idleTimeout = 60
.
- Example:
-
Missing Implementation:
- Example: 60 seconds might be too long; re-evaluate.
Mitigation Strategy: Origin Checking (uWS API)
-
Description:
- Access
Origin
Header: In your connection handler, access theOrigin
header from the incoming request using uWebSockets' header access methods. - Whitelist: Compare the
Origin
value exactly against a hardcoded whitelist of allowed origins. - Reject Invalid: If the
Origin
is missing, empty, or not in the whitelist, reject the connection using uWebSockets' connection rejection mechanism (typically returningfalse
from the connection handler).
- Access
-
Threats Mitigated:
- Cross-Site WebSocket Hijacking (CSWSH): (Severity: High) - Prevents control from malicious websites.
-
Impact:
- CSWSH: High impact; prevents the attack.
-
Currently Implemented:
- Example:
src/websocket_handler.cpp
checks theOrigin
header.
- Example:
-
Missing Implementation:
- Example: The check is not strict (case-insensitive, allows subdomains).
null
origin handling is undefined.
- Example: The check is not strict (case-insensitive, allows subdomains).
Mitigation Strategy: Message Size Limits (uWS Configuration)
-
Description:
- Determine Max Size: Decide on the maximum acceptable WebSocket message size for your application.
- Configure
maxPayloadLength
: In youruWS::App
oruWS::SSLApp
configuration, set themaxPayloadLength
option (in bytes) to this limit. This is a direct uWebSockets setting.
-
Threats Mitigated:
- Denial of Service (DoS): (Severity: High) - Prevents large messages from exhausting memory.
- Resource Exhaustion: (Severity: High) - Protects memory.
- Buffer Overflow (Potential): (Severity: Medium) - Reduces risk.
-
Impact:
- DoS: High impact; prevents a specific DoS type.
- Resource Exhaustion: High impact; reduces risk.
- Buffer Overflow: Medium impact; reduces attack surface.
-
Currently Implemented:
- Example:
src/server.cpp
,uWS::App
configuration:maxPayloadLength = 1048576
.
- Example:
-
Missing Implementation:
- Example: No limit on reassembled fragmented message size.