[PM-30751] - add secure SSRF protection for internal IPs#7256
Open
jaasen-livefront wants to merge 5 commits intomainfrom
Open
[PM-30751] - add secure SSRF protection for internal IPs#7256jaasen-livefront wants to merge 5 commits intomainfrom
jaasen-livefront wants to merge 5 commits intomainfrom
Conversation
Contributor
|
Fixed Issues (2)Great job! The following issues were fixed in this Pull Request
|
|
Banrion
approved these changes
Mar 19, 2026
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.





🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-30751
📔 Objective
Adds centralized SSRF (Server-Side Request Forgery) protection to prevent server-initiated HTTP requests from reaching internal/private/reserved IP ranges when the destination URL is derived from external input.
Problem
SSRF protection logic existed only in the Icons project (
IPAddressExtension), and did not cover CGNAT ranges (RFC 6598). Multiple other HTTP clients accepting user-supplied or admin-configured URLs had no IP validation at all.Additionally, because
SsrfProtectionHandleris aDelegatingHandler, it only validates the initial request URI. WhenAllowAutoRedirect = true(the default onHttpClientHandler/SocketsHttpHandler), redirected requests are followed internally by the primary handler and never pass back through the SSRF handler. This means an attacker-controlled domain can redirect to internal addresses (e.g.,http://169.254.169.254/latest/meta-data/) and bypass SSRF protection entirely.Solution
Shared IP validation — Moved
IsInternal()logic fromIconsintoCore/Utilities/IPAddressExtensions.csso all projects can use it. Added CGNAT blocking (100.64.0.0/10).SsrfProtectionHandler— ADelegatingHandlerthat:SsrfProtectionExceptionif any resolved IP is internalHostheader for TLS SNIftp://)One-line opt-in —
IHttpClientBuilder.AddSsrfProtection()extension method to wire the handler into any namedHttpClient. This also disablesAllowAutoRedirecton the primary handler (bothHttpClientHandlerandSocketsHttpHandler) so that redirects always pass back throughSsrfProtectionHandlerfor validation. This provides defense-in-depth: the handler validates each hop, and the primary handler is prevented from silently following redirects on its own.Protected clients
ChangePasswordUriServiceWebhookIntegrationHandlerDatadogIntegrationHandlerSlackServiceTeamsServiceIcons(fetch + redirect)Note: The Icons client already set
AllowAutoRedirect = falseand handled redirects manually viaIconHttpRequest.FollowRedirectsAsync(), so it was not vulnerable to the redirect bypass. All other clients listed above were vulnerable.Out-of-scope clients (server-configured URLs not from external input):
BaseIdentityClientService,SSOController,NotificationHubPushRegistrationService,AliveJob,HomeController.Changes
src/Core/Utilities/IPAddressExtensions.cs— shared IP blocklist with CGNATsrc/Core/Utilities/SsrfProtectionHandler.cs— DNS-resolving delegating handler with redirect-following and per-hop SSRF validationsrc/Core/Utilities/HttpClientBuilderSsrfExtensions.cs—.AddSsrfProtection()extension (registers handler + disablesAllowAutoRedirect)src/Icons/Util/IPAddressExtension.cs— delegates to shared Core implementationsrc/Icons/Util/ServiceCollectionExtension.cs— adds SSRF protection to Icons/ChangePasswordUri clientssrc/Core/Dirt/EventIntegrations/EventIntegrationsServiceCollectionExtensions.cs— adds SSRF protection to Webhook, Datadog, Slack, Teams clientstest/Core.Test/Utilities/IPAddressExtensionsTests.cs— 30 test cases covering all IP ranges + CGNAT boundariestest/Core.Test/Utilities/SsrfProtectionHandlerTests.cs— 27 test cases for handler behavior including redirect validationRedirect protection test coverage
ftp://) → stopped, returns redirect response as-isFuture usage
Any new HTTP client that accepts external input can opt in with:
📸 Screenshots