Project

General

Profile

Patch #44745 ยป allow-http-oauth-redirect-uri-for-localhost-subdomains.patch

Alessandro Rodi, 2026-11-12 09:36

View differences:

config/initializers/30-redmine.rb
58 58
    allow_token_introspection false
59 59

  
60 60
    # allow http loopback redirect URIs but require https for all others
61
    force_ssl_in_redirect_uri { |uri| !%w[localhost 127.0.0.1 ::1].include?(uri.hostname) }
61
    force_ssl_in_redirect_uri do |uri|
62
      hostname = uri.hostname.to_s
63
      !(%w[localhost 127.0.0.1 ::1].include?(hostname) || hostname.end_with?('.localhost'))
64
    end
62 65

  
63 66
    # Specify what redirect URI's you want to block during Application creation.
64 67
    forbid_redirect_uri { |uri| %w[data vbscript javascript].include?(uri.scheme.to_s.downcase) }
test/unit/oauth_redirect_uri_test.rb
1
# frozen_string_literal: true
2

  
3
# Redmine - project management software
4
# Copyright (C) 2006-  Jean-Philippe Lang
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; either version 2
9
# of the License, or (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19

  
20
require_relative '../test_helper'
21

  
22
class OauthRedirectUriTest < ActiveSupport::TestCase
23
  def test_http_redirect_uri_should_be_allowed_for_loopback_hosts
24
    %w[
25
      http://localhost:3000/callback
26
      http://127.0.0.1:3000/callback
27
      http://[::1]:3000/callback
28
      http://app.localhost:3000/callback
29
    ].each do |uri|
30
      assert_empty redirect_uri_errors(uri), uri
31
    end
32
  end
33

  
34
  def test_http_redirect_uri_should_be_rejected_for_other_hosts
35
    %w[
36
      http://example.com/callback
37
      http://localhost.example.com/callback
38
      http://notlocalhost/callback
39
    ].each do |uri|
40
      assert_not_empty redirect_uri_errors(uri), uri
41
    end
42
  end
43

  
44
  private
45

  
46
  def redirect_uri_errors(redirect_uri)
47
    application = Doorkeeper::Application.new(name: 'test', redirect_uri: redirect_uri)
48
    application.valid?
49
    application.errors[:redirect_uri]
50
  end
51
end
    (1-1/1)