fix: evaluate TRUSTED_PROXY_COUNT dynamically inside function body - #372
fix: evaluate TRUSTED_PROXY_COUNT dynamically inside function body#372google-labs-jules[bot] wants to merge 0 commit into
Conversation
|
👋 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. |
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
Reviewer's GuideRefactors client IP extraction to evaluate TRUSTED_PROXY_COUNT at call time instead of import time, and updates proxy-related rate limiting tests to monkeypatch security configuration explicitly while correcting a spoofing test’s expectations. Sequence diagram for dynamic TRUSTED_PROXY_COUNT evaluation in extract_client_ip_from_forwardedsequenceDiagram
actor Test
participant monkeypatch
participant security_module
participant extract_client_ip_from_forwarded
Test->>monkeypatch: set TRUSTED_PROXY_COUNT
Test->>extract_client_ip_from_forwarded: call(forwarded, trusted_proxy_count=None)
activate extract_client_ip_from_forwarded
extract_client_ip_from_forwarded->>security_module: read TRUSTED_PROXY_COUNT
security_module-->>extract_client_ip_from_forwarded: TRUSTED_PROXY_COUNT (patched value)
extract_client_ip_from_forwarded-->>Test: client_ip
deactivate extract_client_ip_from_forwarded
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:
- The repeated
import agent.security+monkeypatch.setattr(..., 'TRUSTED_PROXY_COUNT', 1)setup across multiple tests could be consolidated into a shared fixture (e.g.,trusted_proxy_count_1) to reduce duplication and keep test intent clearer. - In
extract_client_ip_from_forwarded, consider documenting in the docstring thattrusted_proxy_count=Nonemeans "use the global TRUSTED_PROXY_COUNT" so callers understand the special meaning ofNonefrom the type signature.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The repeated `import agent.security` + `monkeypatch.setattr(..., 'TRUSTED_PROXY_COUNT', 1)` setup across multiple tests could be consolidated into a shared fixture (e.g., `trusted_proxy_count_1`) to reduce duplication and keep test intent clearer.
- In `extract_client_ip_from_forwarded`, consider documenting in the docstring that `trusted_proxy_count=None` means "use the global TRUSTED_PROXY_COUNT" so callers understand the special meaning of `None` from the type signature.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the extract_client_ip_from_forwarded function in backend/src/agent/security.py to accept an optional trusted_proxy_count parameter, defaulting to TRUSTED_PROXY_COUNT when it is None. To support this change and ensure consistent behavior, several rate-limiting and proxy security tests have been updated to use monkeypatch to mock TRUSTED_PROXY_COUNT and TRUSTED_PROXIES. There are no review comments, and I have no feedback to provide.
I have consolidated the repeated monkeypatch setup into a shared fixture |
76d3a0b to
f2f4fe1
Compare
f2f4fe1 to
76d3a0b
Compare
Pull request was closed
76d3a0b to
4e4b8da
Compare
|



This PR fixes a bug related to late-binding of dynamic configurations during testing.
Fix
extract_client_ip_from_forwardedinbackend/src/agent/security.pyso thattrusted_proxy_countusesNoneas its default instead of evaluating the module-level constant at import time. The value is now safely evaluated within the function block, enablingpytestto successfully modify it viamonkeypatch.test_api_security.py,test_rate_limiter_proxy.py, andtest_proxy_security.pyto correctly apply monkeypatching.test_spoofing_vulnerabilityto correctly intercept fallback mocking mechanisms.PR created automatically by Jules for task 917366035391238728 started by @MasumRab
Summary by Sourcery
Adjust client IP extraction to evaluate trusted proxy configuration at call time and align tests with dynamic proxy settings and updated spoofing behavior.
Bug Fixes:
Tests: