Add CORS Logging Middleware and Fix CORS Configuration#32
Add CORS Logging Middleware and Fix CORS Configuration#32
Conversation
…nfig Co-authored-by: KnellBalm <90038472+KnellBalm@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Reviewer's GuideAdds a CORS logging middleware to observe and debug CORS behavior in production and wires it into the FastAPI app after the existing CORS middleware, without changing the underlying CORS config itself. Sequence diagram for CORS request handling with CORSLoggingMiddlewaresequenceDiagram
actor Browser
participant FastAPIApp
participant CORSLoggingMiddleware
participant CORSMiddleware
participant EndpointHandler
Browser->>FastAPIApp: HTTP request with Origin header
FastAPIApp->>CORSLoggingMiddleware: dispatch(request, call_next)
CORSLoggingMiddleware->>CORSMiddleware: call_next(request)
CORSMiddleware->>EndpointHandler: Process request
EndpointHandler-->>CORSMiddleware: Response
CORSMiddleware-->>CORSLoggingMiddleware: Response with CORS headers
CORSLoggingMiddleware->>CORSLoggingMiddleware: Read Origin and CORS headers
alt access_control_allow_origin present
CORSLoggingMiddleware->>CORSLoggingMiddleware: logger.info CORS Success
else access_control_allow_origin missing
CORSLoggingMiddleware->>CORSLoggingMiddleware: logger.warning CORS Missing Header
end
CORSLoggingMiddleware-->>FastAPIApp: Final response
FastAPIApp-->>Browser: HTTP response with CORS headers
Class diagram for new CORSLoggingMiddlewareclassDiagram
class BaseHTTPMiddleware {
}
class CORSLoggingMiddleware {
+dispatch(request, call_next)
}
BaseHTTPMiddleware <|-- CORSLoggingMiddleware
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
CORSLoggingMiddlewarecallsget_loggeron every request; consider instantiating the logger once at module or class level to avoid repeated lookups on the hot path.- Logging every successful CORS response at
infolevel may be too noisy in production; you might want to downgrade success logs todebugand keepwarningonly for missing headers. - Since
CORSLoggingMiddlewarelogs theOriginheader for all requests with an origin, verify that this doesn’t expose sensitive or high-volume data in your central logs and consider adding sampling or filtering if needed.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- `CORSLoggingMiddleware` calls `get_logger` on every request; consider instantiating the logger once at module or class level to avoid repeated lookups on the hot path.
- Logging every successful CORS response at `info` level may be too noisy in production; you might want to downgrade success logs to `debug` and keep `warning` only for missing headers.
- Since `CORSLoggingMiddleware` logs the `Origin` header for all requests with an origin, verify that this doesn’t expose sensitive or high-volume data in your central logs and consider adding sampling or filtering if needed.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…ests Co-authored-by: KnellBalm <90038472+KnellBalm@users.noreply.github.com>
Added CORSLoggingMiddleware to backend/common/middleware.py and registered it in backend/main.py to debug production CORS issues. Verified that the cloud origin regex and allowed origins list are correct using tests/test_cors_config.py. This change also triggers a redeployment which might resolve stale configuration issues.
PR created automatically by Jules for task 8824180182849832873 started by @KnellBalm
Summary by Sourcery
Add middleware to log CORS-related request and response details to aid debugging of CORS issues in production.
Enhancements: