Skip to content

fix: prevent SSRF in product scraper and restrict sensitive data logging to development - #62

Merged
mitch-b merged 1 commit into
mainfrom
work/security-fix
Apr 5, 2026
Merged

fix: prevent SSRF in product scraper and restrict sensitive data logging to development#62
mitch-b merged 1 commit into
mainfrom
work/security-fix

Conversation

@mitch-b

@mitch-b mitch-b commented Apr 5, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes two security vulnerabilities identified in the codebase.

Changes

1. SSRF Prevention in ProductService (Critical)

ProductService.TryScrapeProductFromUrl accepted any user-supplied URL and made a server-side HTTP request without validation. An authenticated user could exploit this to:

  • Probe internal services (e.g., http://localhost/admin)
  • Access cloud metadata endpoints (e.g., http://169.254.169.254/)
  • Scan private RFC-1918 networks

Fix: Added IsSafeUrlAsync() which, before any HTTP request is made:

  • Enforces http/https schemes only
  • Resolves the hostname via DNS and rejects addresses that are:
    • Loopback (127.x.x.x / ::1)
    • Private IPv4: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16
    • Link-local: 169.254.0.0/16 (cloud metadata)
    • IPv6 ULA (fc00::/7) and link-local (fe80::/10)

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.cs
  • src/OpenWish.Web/Program.cs

…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>
@mitch-b
mitch-b merged commit 4bc256c into main Apr 5, 2026
1 check passed
@mitch-b
mitch-b deleted the work/security-fix branch April 5, 2026 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant