fix: resolve rate-limit proxy IP collapse and JSON log injection#289
fix: resolve rate-limit proxy IP collapse and JSON log injection#289luis5tb wants to merge 2 commits into
Conversation
07196d5 to
de2da8a
Compare
Code Review — Issues1. Security trade-off of reordering: unauthenticated floods no longer throttled at IP level before auth The old comment explicitly noted: "runs before auth so unauthenticated floods are throttled at the IP level before any auth processing." By moving rate-limit after auth, every unauthenticated request now passes through the full JWT validation pipeline before being throttled. This means:
Consider whether a two-layer approach is better: a lightweight IP-based pre-auth throttle (e.g., connection-level via Cloud Armor / nginx) plus the current tenant-based post-auth throttle. The CLAUDE.md notes Cloud Armor is already in the Cloud Run deployment — does it cover this gap? 2. The The field description says "safe when ingress is restricted to the load balancer" — consider defaulting to 3. Marketplace handler uses The agent service added proxy_headers=os.getenv("PROXY_HEADERS", "true").lower() == "true",
forwarded_allow_ips=os.getenv("FORWARDED_ALLOW_IPS", "*"),This bypasses the Pydantic validation. It's consistent with how the handler already reads 4. Duplicate if log_format == "json":
from pythonjsonlogger.json import JsonFormatter
handler.setFormatter(...)
if log_format == "json": # <-- second check, same condition
logging.basicConfig(level=log_level, handlers=[handler])
else:
logging.basicConfig(...)These two blocks should be a single 5. Stderr → stdout change in marketplace handler The diff adds |
- Add Cloud Armor IP-based throttle rule at priority 100 for pre-auth flood protection and document middleware order trade-off in app.py - Change forwarded_allow_ips default to empty (safe-by-default for dev), add explicit FORWARDED_ALLOW_IPS=* in Cloud Run and OpenShift configs - Fix duplicate if log_format check in both main.py and marketplace __main__.py by consolidating into single if/else blocks - Add stdout comment on marketplace handler StreamHandler Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add Cloud Armor IP-based throttle rule at priority 100 for pre-auth flood protection and document middleware order trade-off in app.py - Change forwarded_allow_ips default to empty (safe-by-default for dev), add explicit FORWARDED_ALLOW_IPS=* in Cloud Run and OpenShift configs - Fix duplicate if log_format check in both main.py and marketplace __main__.py by consolidating into single if/else blocks - Add stdout comment on marketplace handler StreamHandler Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ec7e8fc to
9d6296b
Compare
- Add Cloud Armor IP-based throttle rule at priority 100 for pre-auth flood protection and document middleware order trade-off in app.py - Change forwarded_allow_ips default to empty (safe-by-default for dev), add explicit FORWARDED_ALLOW_IPS=* in Cloud Run and OpenShift configs - Fix duplicate if log_format check in both main.py and marketplace __main__.py by consolidating into single if/else blocks - Add stdout comment on marketplace handler StreamHandler Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
9d6296b to
5b17225
Compare
Rate limiter: enable uvicorn proxy header trust (X-Forwarded-For) so each client gets its own bucket behind GCLB/OpenShift Routes instead of all tenants sharing a single proxy-IP bucket. Reorder Auth before RateLimit middleware on the agent service so tenant-based bucketing (order/user/client) is active — the multi-dimensional principal resolution was dead code when rate limiting ran before auth. JSON logging (CWE-117): replace %-format JSON templates with pythonjsonlogger JsonFormatter so user-controlled content in log messages cannot break JSON structure or inject fake fields. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add Cloud Armor IP-based throttle rule at priority 100 for pre-auth flood protection and document middleware order trade-off in app.py - Change forwarded_allow_ips default to empty (safe-by-default for dev), add explicit FORWARDED_ALLOW_IPS=* in Cloud Run and OpenShift configs - Fix duplicate if log_format check in both main.py and marketplace __main__.py by consolidating into single if/else blocks - Add stdout comment on marketplace handler StreamHandler Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
5b17225 to
38a693f
Compare
Rate limiter: enable uvicorn proxy header trust (X-Forwarded-For) so each client gets its own bucket behind GCLB/OpenShift Routes instead of all tenants sharing a single proxy-IP bucket. Reorder Auth before RateLimit middleware on the agent service so tenant-based bucketing (order/user/client) is active — the multi-dimensional principal resolution was dead code when rate limiting ran before auth.
JSON logging (CWE-117): replace %-format JSON templates with pythonjsonlogger JsonFormatter so user-controlled content in log messages cannot break JSON structure or inject fake fields.