Skip to content

Commit 8800cce

Browse files
committed
refactor: set rate limit enabled by default
1 parent 8ec9181 commit 8800cce

5 files changed

Lines changed: 28 additions & 13 deletions

File tree

.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
# Copy this file to .env and adjust values as needed
33

44
# Environment type: 'development' or 'production'
5-
# In development mode, CSRF protection and rate limiting are disabled
5+
# In development mode, CSRF protection is disabled
66
CROSSBAR_ENV=development
77

8+
# Rate limiting: enabled by default. Set to 'false' or '0' to disable.
9+
# CROSSBAR_RATE_LIMIT=false
10+
811
# API keys for various LLM providers
912
OPENAI_API_KEY="sk-************************************************"
1013
GEMINI_API_KEY="AI*****************-**-******-*********"

ENVIRONMENT.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CROssBAR LLM backend can be configured to run in different environments with dis
55
## Environment Types
66

77
The application supports two environment types:
8-
- **Development**: Optimized for local development with security features relaxed and no rate limiting
8+
- **Development**: Optimized for local development with CSRF disabled (rate limiting enabled unless CROSSBAR_RATE_LIMIT=false)
99
- **Production**: Full security features enabled with CSRF protection and rate limiting
1010

1111
## Configuration
@@ -24,12 +24,20 @@ You can set this in your `.env` file or directly in your environment.
2424
| Feature | Development | Production |
2525
|---------|-------------|------------|
2626
| CSRF Protection | Disabled | Enabled |
27-
| Rate Limiting | Disabled | Enabled |
27+
| Rate Limiting | See CROSSBAR_RATE_LIMIT below | See CROSSBAR_RATE_LIMIT below |
2828
| Debug Logging | Verbose | Minimal |
2929

30-
### Rate Limits (Production Only)
30+
### Rate Limiting (CROSSBAR_RATE_LIMIT)
3131

32-
Rate limiting in production mode follows these defaults:
32+
Rate limiting is **enabled by default**. Set `CROSSBAR_RATE_LIMIT=false` or `0` to disable:
33+
34+
```
35+
CROSSBAR_RATE_LIMIT=false # Disable rate limiting
36+
```
37+
38+
### Rate Limits (When Enabled)
39+
40+
When rate limiting is enabled, these defaults apply:
3341
- 6 requests per minute
3442
- 20 requests per hour
3543
- 50 requests per day

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ When the backend is running, you can access:
173173

174174
The application supports both development and production environments with different security settings:
175175

176-
- **Development mode** (default): Disables CSRF protection and rate limiting for easier local development
176+
- **Development mode** (default): Disables CSRF protection for easier local development (rate limiting on unless CROSSBAR_RATE_LIMIT=false)
177177
- **Production mode**: Enables full security features
178178

179179
For details on configuring the environment, see [ENVIRONMENT.md](ENVIRONMENT.md).

crossbar_llm/backend/config.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@
1515
IS_PRODUCTION = ENV == "production"
1616
IS_DEVELOPMENT = not IS_PRODUCTION
1717

18+
# Rate limit: enforced by default. Set CROSSBAR_RATE_LIMIT=false or 0 to disable.
19+
_rate_limit_env = os.getenv("CROSSBAR_RATE_LIMIT", "").lower()
20+
RATE_LIMITING_ENABLED = _rate_limit_env not in ("false", "0")
21+
1822
# Environment-specific settings
1923
SETTINGS = {
2024
"csrf_enabled": IS_PRODUCTION,
21-
"rate_limiting_enabled": IS_PRODUCTION,
25+
"rate_limiting_enabled": RATE_LIMITING_ENABLED,
2226
"debug_logging": IS_DEVELOPMENT,
2327
# Rate limiting settings
2428
"rate_limits": {
25-
# Use a very large number in development mode instead of infinity
26-
# to avoid JSON serialization issues
27-
"minute": 6 if IS_PRODUCTION else 10000000, # Requests per minute
28-
"hour": 20 if IS_PRODUCTION else 10000000, # Requests per hour
29-
"day": 50 if IS_PRODUCTION else 10000000, # Requests per day
29+
# Use production limits when rate limiting is enabled; otherwise use
30+
# very large numbers (instead of infinity) to avoid JSON serialization issues
31+
"minute": 6 if RATE_LIMITING_ENABLED else 10000000, # Requests per minute
32+
"hour": 20 if RATE_LIMITING_ENABLED else 10000000, # Requests per hour
33+
"day": 50 if RATE_LIMITING_ENABLED else 10000000, # Requests per day
3034
},
3135
}
3236

crossbar_llm/backend/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def __init__(self):
319319

320320
# Log with readable rate limit values
321321
if not self.enabled:
322-
Logger.info("Rate limiting is disabled (development mode)")
322+
Logger.info("Rate limiting is disabled")
323323
else:
324324
# Consider very high limits as effectively unlimited for display purposes
325325
minute_display = (

0 commit comments

Comments
 (0)