Fix SSRF on TOCTOU#4344
Conversation
📝 WalkthroughWalkthroughNew UrlValidatedDTO and UrlValidation service centralize URL validation; requests are preprocessed into DTOs, PhotoUrlRule and FromUrl action consume DTOs, DownloadedFile accepts DTOs and supports fopen/cURL paths; feature flag and unit tests added. ChangesURL Validation & Download Refactor
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ❌ 1❌ Failed checks (1 warning)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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 |
There was a problem hiding this comment.
Actionable comments posted: 7
🧹 Nitpick comments (1)
app/Services/UrlValidation.php (1)
107-111: ⚖️ Poor tradeoffConsider exposing all resolved IPs, not just the first.
resolved_ipretains only$resolved_ips[0]. SinceDownloadedFile::downloadWithCurl()pins that single IP viaCURLOPT_RESOLVE, multi-homed hosts lose all fallback IPs and a transient outage on the first record fails the import even though sibling records were validated. Storing the full list (e.g.resolved_ips: string[]) and joining them with commas into theCURLOPT_RESOLVEentry would preserve resiliency while keeping the SSRF guarantee intact (all IPs in the list have already been vetted).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1f85e6c1-e85a-4693-b272-3bd8262a8ab7
📒 Files selected for processing (7)
app/Actions/Import/FromUrl.phpapp/DTO/UrlValidatedDTO.phpapp/Http/Requests/Photo/FromUrlRequest.phpapp/Image/Files/DownloadedFile.phpapp/Rules/PhotoUrlRule.phpapp/Services/UrlValidation.phpconfig/features.php
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/Unit/Services/UrlValidationTest.php (1)
30-49: ⚡ Quick winMake the config fixture self-restoring and build
UrlValidationafter seeding it.Line 33 constructs the service before Lines 35-38 set the flags, and Lines 43-46 restore fixed
'1'values instead of the pre-test state. That makes this suite depend onUrlValidationreading config lazily and on those defaults never changing. Capturing the original values, setting the test values, then constructing the service would make these tests much less order-dependent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0ff4c6a4-7a05-464b-a048-bc37a7c484cd
📒 Files selected for processing (7)
Dockerfileapp/DTO/UrlValidatedDTO.phpapp/Image/Files/DownloadedFile.phpapp/Rules/PhotoUrlRule.phpapp/Services/UrlValidation.phptests/Unit/Rules/PhotoUrlRuleTest.phptests/Unit/Services/UrlValidationTest.php
✅ Files skipped from review due to trivial changes (1)
- Dockerfile
🚧 Files skipped from review as they are similar to previous changes (4)
- app/DTO/UrlValidatedDTO.php
- app/Rules/PhotoUrlRule.php
- app/Services/UrlValidation.php
- app/Image/Files/DownloadedFile.php
Codecov Report❌ Patch coverage is 🚀 New features to boost your workflow:
|
Summary by CodeRabbit
New Features
Improvements
Bug Fixes
Tests