Add SSRF filter for HTTPX

Filtering in front of HTTPX calls is less secure, because it's vulnerable to
DNS rebinding. In addition to that it's also duplicate work, because all affected
callsites would have to make sure to "remember" SSRF filtering.

This SSRF filter is inspired by the original HTTPX SSRF Filter, but using our custom
IP address matcher that allows to configure safe IP addresses or ranges.
This commit is contained in:
Jan Sandbrink
2026-06-01 10:57:00 +02:00
parent 306173ad3f
commit 294611cc59
4 changed files with 137 additions and 3 deletions
+2
View File
@@ -34,6 +34,7 @@ require "open_project/patches"
require "open_project/mime_type"
require "open_project/custom_styles/design"
require "open_project/httpx_appsignal"
require "open_project/httpx_ssrf_filter"
require "redmine/plugin"
require "csv"
@@ -62,6 +63,7 @@ module OpenProject
.with(headers: { "User-Agent" => "OpenProject #{OpenProject::VERSION.to_semver} HTTPX Client" })
.plugin(:auth)
.plugin(:webdav)
.plugin(HttpxSsrfFilter)
.with(
timeout: {
connect_timeout: OpenProject::Configuration.httpx_connect_timeout,
+57
View File
@@ -0,0 +1,57 @@
# frozen_string_literal: true
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
#++
module OpenProject
# An SSRF filter for HTTPX based on the original plugin.
# See https://gitlab.com/os85/httpx/-/blob/master/lib/httpx/plugins/ssrf_filter.rb
#
# The main difference is that we use our own subclass of `SsrfFilter` to perform the matching of unsafe IP addresses.
# We are thus consulting our own allow list of IP addresses before blocking an IP address.
module HttpxSsrfFilter
class ServerSideRequestForgeryError < HTTPX::Error; end
module ConnectionMethods
def initialize(*)
super
rescue ServerSideRequestForgeryError => e
# may raise when IPs are passed as options via :addresses
throw(:resolve_error, e)
end
def addresses=(addrs)
addrs.reject!(&SsrfProtection.method(:unsafe_ip_address?)) # rubocop:disable Performance/MethodObjectAsBlock
raise ServerSideRequestForgeryError, "#{@origin.host} has no public IP addresses" if addrs.empty?
super
end
end
end
end