refactor: extract SSRF worker-URL validation into app/worker_proxy.py (CashPilot-sux)#121
Conversation
… (CashPilot-sux) Move the self-contained SSRF/worker-URL guard (policy constants, allowlist parsing, IP classification, _validate_worker_url, _pin_url_to_ip) out of the main.py god module into a focused, independently unit-testable app/worker_proxy.py. main.py's _get_verified_worker_url composes them; it stays in main because it also needs FLEET_API_KEY + database. worker_proxy imports nothing from main, so no new import cycle is introduced. Behavior-preserving: 1172 tests green. Test seams that referenced the moved symbols via app.main (the socket-getaddrinfo patches and the strict-mode/allowlist tests mutating the policy constants) now point at app.worker_proxy; the _validate_worker_url/_pin_url_to_ip patches keep working through main's import binding. This is the architect-endorsed least-coupled extraction from bead CashPilot-sux. The benign, documented main->routers->main import cycle is intentionally left as-is (resolving it risks the ~40 app.main.* test seams for no correctness gain).
|
@coderabbitai review |
|
Warning Review limit reached
Next review available in: 43 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ Action performedReview finished.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #121 +/- ##
=======================================
Coverage 93.89% 93.90%
=======================================
Files 33 34 +1
Lines 3901 3905 +4
=======================================
+ Hits 3663 3667 +4
Misses 238 238
🚀 New features to boost your workflow:
|
Splits a cohesive, self-contained slice out of the
main.pygod module — the architect-endorsed least-coupled candidate from beadCashPilot-sux.What moved
The SSRF/worker-URL guard → new
app/worker_proxy.py:_WORKER_URL_POLICY, metadata/loopback block sets, allowlist),_parse_worker_allowlist,_normalize_ip,_assert_ip_not_blocked,_assert_ip_strict_allowed,_validate_worker_url(DNS-rebinding-safe validation),_pin_url_to_ip.main.py's_get_verified_worker_urlcomposes them and stays in main (it also needsFLEET_API_KEY+database).worker_proxyimports nothing frommain, so no new import cycle. main.py drops ~160 lines and the SSRF policy is now isolated and unit-testable on its own.Test seams
app.main.socket.getaddrinfopatches →app.worker_proxy.socket(that's where_validate_worker_urlresolves the host).mainalias toapp.worker_proxy(where_validate_worker_urlreads them)._validate_worker_url/_pin_url_to_ippatches keep working viamain's import binding — unchanged.Verification
Behavior-preserving: 1172 tests green;
ruff check+ruff format --checkclean; verifiedworker_proxyimports nothing fromapp.main.Scope
This lands the module-extraction half of
sux. The other half — resolving themain → routers → mainimport cycle — is intentionally left as-is: it's benign and documented, and breaking it churns ~40app.main.*test seams for no correctness gain (per the architect review). The bead can close on the extraction or stay open for the cosmetic cycle cleanup — your call.Addresses bead CashPilot-sux (extraction half).