fix: prevent SSRF in product scraper and restrict sensitive data logging to development - #62
Merged
Conversation
…ng to development
- Add IsSafeUrlAsync() to ProductService that validates URLs before fetching:
- Only allows http/https schemes
- Resolves hostname via DNS and rejects loopback, private (RFC-1918),
link-local (169.254.x.x), and IPv6 ULA/link-local addresses
- Logs a warning when a URL is rejected
- Restrict EnableSensitiveDataLogging() to development environments only
to avoid leaking SQL parameter values in production logs
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two security vulnerabilities identified in the codebase.
Changes
1. SSRF Prevention in
ProductService(Critical)ProductService.TryScrapeProductFromUrlaccepted any user-supplied URL and made a server-side HTTP request without validation. An authenticated user could exploit this to:http://localhost/admin)http://169.254.169.254/)Fix: Added
IsSafeUrlAsync()which, before any HTTP request is made:2. Sensitive Data Logging Restricted to Development
EnableSensitiveDataLogging()was called unconditionally, causing EF Core to log SQL parameter values (potentially including PII/credentials) in all environments including production.Fix: Wrapped the call in an
IsDevelopment()guard.Files Modified
src/OpenWish.Application/Services/ProductService.cssrc/OpenWish.Web/Program.cs