fix(security): block SSRF via user-supplied ICS feed URLs#259
Open
ttonyxx wants to merge 1 commit into
Open
Conversation
This was referenced May 29, 2026
## Why this change is needed `/user/add-ics-calendar-account` lets an authenticated user store an arbitrary `feedUrl`, and `ICSCalendar.GetCalendarEvents` later fetched it with a plain `http.Get(cal.FeedURL)`. Because the URL is fully attacker-controlled, this is a Server-Side Request Forgery (SSRF) primitive: a user could point the feed at - the cloud metadata endpoint (`http://169.254.169.254/...`) to try to steal instance credentials, - internal-only services reachable from the server, or - `localhost` admin interfaces, and have the server issue the request from inside the trust boundary. ## What this does - Adds `safeGet` (services/calendar/safe_http.go), which only allows `http`/ `https` URLs and dials through a client whose `Control` hook rejects any connection to a non-public IP (loopback, RFC1918 private, link-local incl. 169.254.169.254, unspecified, multicast, and CGNAT 100.64.0.0/10). - Because the check runs on the resolved address at connect time, it also defeats DNS-rebinding and re-validates on every redirect hop. - `ICSCalendar.GetCalendarEvents` now uses `safeGet` instead of `http.Get`. - Adds unit tests for the IP classification and scheme rejection. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
d2919b6 to
e3c36eb
Compare
c5364ea to
62df3e5
Compare
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.
Severity: 🟡 Medium — authenticated SSRF
The problem
/user/add-ics-calendar-accountstores an arbitrary user-suppliedfeedUrl, andICSCalendar.GetCalendarEventslater fetched it with:The URL is fully attacker-controlled, giving any signed-in user an SSRF primitive. They can make the server fetch:
http://169.254.169.254/…(instance credential theft),localhostadmin interfaces.The fix
New
safeGetinservices/calendar/safe_http.go:http/httpsschemes.http.Clientwhosenet.Dialer.Controlhook rejects any non-public resolved IP: loopback, RFC1918 private, link-local (incl.169.254.169.254), unspecified, multicast, and CGNAT100.64.0.0/10.ICSCalendar.GetCalendarEventsnow callssafeGet. Added unit tests for the IP classifier and scheme rejection (both pass).🤖 Generated with Claude Code