Skip to content

Commit ccabb2e

Browse files
committed
Upgrade framework to rail 8.0
1 parent c81a2ee commit ccabb2e

12 files changed

Lines changed: 190 additions & 112 deletions

.github/workflows/shared_gem_verify_rails.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Build Rails version matrix
3131
id: merge_rails_versions
3232
run: |
33-
default_rails_versions='["~> 7.0.0","~> 7.1.0","~> 7.2.0"]'
33+
default_rails_versions='["~> 7.0.0","~> 7.1.0","~> 7.2.0","~> 8.0.0"]'
3434
additional_rails_versions='${{ inputs.additional_rails_versions }}'
3535
3636
rails_versions=$(jq -cn \

Gemfile.lock

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ PATH
44
metasploit-framework (6.4.128)
55
aarch64
66
abbrev
7-
actionpack (~> 7.2.0)
8-
activerecord (~> 7.2.0)
9-
activesupport (~> 7.2.0)
7+
actionpack (~> 8.0.0)
8+
activerecord (~> 8.0.0)
9+
activesupport (~> 8.0.0)
1010
aws-sdk-ec2
1111
aws-sdk-ec2instanceconnect
1212
aws-sdk-iam
@@ -43,11 +43,11 @@ PATH
4343
json
4444
lru_redux
4545
metasm
46-
metasploit-concern
47-
metasploit-credential (>= 6.0.21)
48-
metasploit-model
46+
metasploit-concern (~> 5.0, >= 5.0.6)
47+
metasploit-credential (~> 6.0, >= 6.0.22)
48+
metasploit-model (~> 5.0, >= 5.0.5)
4949
metasploit-payloads (= 2.0.245)
50-
metasploit_data_models (>= 6.0.15)
50+
metasploit_data_models (~> 6.0, >= 6.0.16)
5151
metasploit_payloads-mettle (= 1.0.46)
5252
mqtt
5353
msgpack (~> 1.6.0)
@@ -72,7 +72,7 @@ PATH
7272
pdf-reader
7373
pg
7474
puma
75-
rack (~> 2.2)
75+
rack (>= 3.0)
7676
railties
7777
rasn1 (= 0.14.0)
7878
rb-readline
@@ -105,13 +105,12 @@ PATH
105105
ruby_smb (~> 3.3.17)
106106
rubyntlm
107107
rubyzip
108-
sinatra (~> 3.2)
108+
sinatra (~> 4.0)
109109
sqlite3 (= 1.7.3)
110110
sshkey
111111
stringio (= 3.1.1)
112112
swagger-blocks
113113
syslog
114-
thin (~> 1.x)
115114
tzinfo
116115
tzinfo-data
117116
unix-crypt
@@ -130,30 +129,29 @@ GEM
130129
aarch64 (2.1.0)
131130
racc (~> 1.6)
132131
abbrev (0.1.2)
133-
actionpack (7.2.2.2)
134-
actionview (= 7.2.2.2)
135-
activesupport (= 7.2.2.2)
132+
actionpack (8.0.5)
133+
actionview (= 8.0.5)
134+
activesupport (= 8.0.5)
136135
nokogiri (>= 1.8.5)
137-
racc
138-
rack (>= 2.2.4, < 3.2)
136+
rack (>= 2.2.4)
139137
rack-session (>= 1.0.1)
140138
rack-test (>= 0.6.3)
141139
rails-dom-testing (~> 2.2)
142140
rails-html-sanitizer (~> 1.6)
143141
useragent (~> 0.16)
144-
actionview (7.2.2.2)
145-
activesupport (= 7.2.2.2)
142+
actionview (8.0.5)
143+
activesupport (= 8.0.5)
146144
builder (~> 3.1)
147145
erubi (~> 1.11)
148146
rails-dom-testing (~> 2.2)
149147
rails-html-sanitizer (~> 1.6)
150-
activemodel (7.2.2.2)
151-
activesupport (= 7.2.2.2)
152-
activerecord (7.2.2.2)
153-
activemodel (= 7.2.2.2)
154-
activesupport (= 7.2.2.2)
148+
activemodel (8.0.5)
149+
activesupport (= 8.0.5)
150+
activerecord (8.0.5)
151+
activemodel (= 8.0.5)
152+
activesupport (= 8.0.5)
155153
timeout (>= 0.4.0)
156-
activesupport (7.2.2.2)
154+
activesupport (8.0.5)
157155
base64
158156
benchmark (>= 0.3)
159157
bigdecimal
@@ -165,6 +163,7 @@ GEM
165163
minitest (>= 5.1)
166164
securerandom (>= 0.3)
167165
tzinfo (~> 2.0, >= 2.0.5)
166+
uri (>= 0.13.1)
168167
addressable (2.8.7)
169168
public_suffix (>= 2.0.2, < 7.0)
170169
afm (0.2.2)
@@ -175,8 +174,8 @@ GEM
175174
mime-types (>= 3.3, < 4)
176175
require_all (>= 2, < 4)
177176
rspec-expectations (~> 3.12)
178-
arel-helpers (2.16.0)
179-
activerecord (>= 3.1.0, < 8.1)
177+
arel-helpers (2.17.0)
178+
activerecord (>= 3.1.0)
180179
ast (2.4.3)
181180
aws-eventstream (1.3.2)
182181
aws-partitions (1.1065.0)
@@ -225,7 +224,6 @@ GEM
225224
cookiejar (0.3.4)
226225
crass (1.0.6)
227226
csv (3.3.2)
228-
daemons (1.4.1)
229227
date (3.4.1)
230228
debug (1.11.0)
231229
irb (~> 1.10)
@@ -324,14 +322,14 @@ GEM
324322
lru_redux (1.1.0)
325323
memory_profiler (1.1.0)
326324
metasm (1.0.5)
327-
metasploit-concern (5.0.5)
328-
activemodel (~> 7.0)
329-
activesupport (~> 7.0)
325+
metasploit-concern (5.0.6)
326+
activemodel (>= 7.0, < 8.1)
327+
activesupport (>= 7.0, < 8.1)
330328
drb
331329
mutex_m
332-
railties (~> 7.0)
330+
railties (>= 7.0, < 8.1)
333331
zeitwerk
334-
metasploit-credential (6.0.21)
332+
metasploit-credential (6.0.22)
335333
bigdecimal
336334
csv
337335
drb
@@ -345,25 +343,25 @@ GEM
345343
rex-socket
346344
rubyntlm
347345
rubyzip (< 3.0.0)
348-
metasploit-model (5.0.4)
349-
activemodel (~> 7.0)
350-
activesupport (~> 7.0)
346+
metasploit-model (5.0.5)
347+
activemodel (>= 7.0, < 8.1)
348+
activesupport (>= 7.0, < 8.1)
351349
bigdecimal
352350
drb
353351
mutex_m
354-
railties (~> 7.0)
352+
railties (>= 7.0, < 8.1)
355353
metasploit-payloads (2.0.245)
356-
metasploit_data_models (6.0.15)
357-
activerecord (~> 7.0)
358-
activesupport (~> 7.0)
354+
metasploit_data_models (6.0.16)
355+
activerecord (>= 7.0, < 8.1)
356+
activesupport (>= 7.0, < 8.1)
359357
arel-helpers
360358
bigdecimal
361359
drb
362360
metasploit-concern
363-
metasploit-model (~> 5.0.4)
361+
metasploit-model (>= 5.0.4)
364362
mutex_m
365363
pg
366-
railties (~> 7.0)
364+
railties (>= 7.0, < 8.1)
367365
recog
368366
webrick
369367
metasploit_payloads-mettle (1.0.46)
@@ -435,38 +433,40 @@ GEM
435433
pry-byebug (3.11.0)
436434
byebug (~> 12.0)
437435
pry (>= 0.13, < 0.16)
438-
psych (5.2.6)
436+
psych (5.3.1)
439437
date
440438
stringio
441439
public_suffix (6.0.2)
442440
puma (6.6.0)
443441
nio4r (~> 2.0)
444442
racc (1.8.1)
445-
rack (2.2.19)
446-
rack-protection (3.2.0)
443+
rack (3.2.6)
444+
rack-protection (4.2.1)
447445
base64 (>= 0.1.0)
448-
rack (~> 2.2, >= 2.2.4)
449-
rack-session (1.0.2)
450-
rack (< 3)
446+
logger (>= 1.6.0)
447+
rack (>= 3.0.0, < 4)
448+
rack-session (2.1.2)
449+
base64 (>= 0.1.0)
450+
rack (>= 3.0.0)
451451
rack-test (2.2.0)
452452
rack (>= 1.3)
453-
rackup (1.0.1)
454-
rack (< 3)
455-
webrick
453+
rackup (2.3.1)
454+
rack (>= 3)
456455
rails-dom-testing (2.3.0)
457456
activesupport (>= 5.0.0)
458457
minitest
459458
nokogiri (>= 1.6)
460459
rails-html-sanitizer (1.6.2)
461460
loofah (~> 2.21)
462461
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
463-
railties (7.2.2.2)
464-
actionpack (= 7.2.2.2)
465-
activesupport (= 7.2.2.2)
462+
railties (8.0.5)
463+
actionpack (= 8.0.5)
464+
activesupport (= 8.0.5)
466465
irb (~> 1.13)
467466
rackup (>= 1.0.0)
468467
rake (>= 12.2)
469468
thor (~> 1.0, >= 1.2.2)
469+
tsort (>= 0.2)
470470
zeitwerk (~> 2.6)
471471
rainbow (3.1.1)
472472
rake (13.3.0)
@@ -611,10 +611,12 @@ GEM
611611
simplecov-html (~> 0.11)
612612
simplecov-html (0.13.1)
613613
simpleidn (0.2.3)
614-
sinatra (3.2.0)
614+
sinatra (4.2.1)
615+
logger (>= 1.6.0)
615616
mustermann (~> 3.0)
616-
rack (~> 2.2, >= 2.2.4)
617-
rack-protection (= 3.2.0)
617+
rack (>= 3.0.0, < 4)
618+
rack-protection (= 4.2.1)
619+
rack-session (>= 2.0.0, < 3)
618620
tilt (~> 2.0)
619621
sqlite3 (1.7.3)
620622
mini_portile2 (~> 2.8.0)
@@ -625,10 +627,6 @@ GEM
625627
syslog (0.3.0)
626628
logger
627629
test-prof (1.4.4)
628-
thin (1.8.2)
629-
daemons (~> 1.0, >= 1.0.9)
630-
eventmachine (~> 1.0, >= 1.0.4)
631-
rack (>= 1, < 3)
632630
thor (1.4.0)
633631
tilt (2.6.0)
634632
timecop (0.9.10)
@@ -646,6 +644,7 @@ GEM
646644
unicode-emoji (~> 4.1)
647645
unicode-emoji (4.1.0)
648646
unix-crypt (1.3.1)
647+
uri (1.1.1)
649648
useragent (0.16.11)
650649
warden (1.2.9)
651650
rack (>= 2.0.9)
@@ -667,9 +666,9 @@ GEM
667666
rexml (~> 3.0)
668667
rubyntlm (~> 0.6.0, >= 0.6.3)
669668
with_env (1.1.0)
670-
xdr (3.0.3)
671-
activemodel (>= 4.2, < 8.0)
672-
activesupport (>= 4.2, < 8.0)
669+
xdr (3.0.1)
670+
activemodel (>= 5.2.0)
671+
activesupport (>= 5.2.0)
673672
xml-simple (1.1.9)
674673
rexml
675674
xmlrpc (0.3.3)

config/application.rb

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,46 @@
55
require File.expand_path('../boot', __FILE__)
66

77
require 'action_view'
8-
# Monkey patch https://github.com/rails/rails/blob/v7.2.2.1/actionview/lib/action_view/helpers/tag_helper.rb#L51
9-
# Might be fixed by 8.x https://github.com/rails/rails/blob/v8.0.2/actionview/lib/action_view/helpers/tag_helper.rb#L51C1-L52C1
10-
raise unless ActionView::VERSION::STRING == '7.2.2.2' # A developer will need to ensure this is still required when bumping rails
11-
module ActionView::Helpers::TagHelper
12-
class TagBuilder
13-
def self.define_element(name, code_generator:, method_name: name.to_s.underscore)
14-
code_generator.define_cached_method(method_name, namespace: :tag_builder) do |batch|
15-
# Fixing a bug introduced by Metasploit's global Kernel patch: https://github.com/rapid7/metasploit-framework/blob/ae1db09f32cd04c007dbf445cf16dc22c9fc2e53/lib/rex.rb#L74-L79
16-
# which fails when using the below 'instance_methods.include?(method_name.to_sym)' check
17-
batch.push(<<~RUBY) # unless instance_methods.include?(method_name.to_sym)
18-
def #{method_name}(content = nil, escape: true, **options, &block)
19-
tag_string("#{name}", content, options, escape: escape, &block)
20-
end
21-
RUBY
8+
# Monkey patch for ActionView::Helpers::TagHelper::TagBuilder.define_element
9+
#
10+
# Metasploit's global Kernel patch (lib/rex.rb) overrides Kernel#select and Kernel#sleep.
11+
# ActionView's define_element checks whether a method already exists before defining HTML
12+
# element helpers (e.g. :select). Because Kernel#select is in the ancestor chain, the check
13+
# returns true and the :select element helper is never defined, breaking tag.select().
14+
#
15+
# Rails 7.2.x uses `instance_methods.include?(method_name.to_sym)` — affected.
16+
# Rails 8.0.x uses `return if method_defined?(name)` — also affected, since method_defined?
17+
# checks the ancestor chain including Kernel.
18+
#
19+
# See: https://github.com/rapid7/metasploit-framework/blob/ae1db09f32cd04c007dbf445cf16dc22c9fc2e53/lib/rex.rb#L74-L79
20+
if ActionView::VERSION::MAJOR == 7
21+
# Rails 7.2.x patch: override define_element to skip the instance_methods.include? guard
22+
# https://github.com/rails/rails/blob/v7.2.2.2/actionview/lib/action_view/helpers/tag_helper.rb#L51
23+
module ActionView::Helpers::TagHelper
24+
class TagBuilder
25+
def self.define_element(name, code_generator:, method_name: name.to_s.underscore)
26+
code_generator.define_cached_method(method_name, namespace: :tag_builder) do |batch|
27+
batch.push(<<~RUBY)
28+
def #{method_name}(content = nil, escape: true, **options, &block)
29+
tag_string("#{name}", content, options, escape: escape, &block)
30+
end
31+
RUBY
32+
end
33+
end
34+
end
35+
end
36+
elsif ActionView::VERSION::MAJOR >= 8
37+
# Rails 8.0.x patch: override define_element to skip the method_defined? guard
38+
# https://github.com/rails/rails/blob/v8.0.2/actionview/lib/action_view/helpers/tag_helper.rb#L51
39+
module ActionView::Helpers::TagHelper
40+
class TagBuilder
41+
def self.define_element(name, code_generator:, method_name: name)
42+
code_generator.class_eval do |batch|
43+
batch << "\n" <<
44+
"def #{method_name}(content = nil, escape: true, **options, &block)" <<
45+
" tag_string(#{name.inspect}, content, options, escape: escape, &block)" <<
46+
"end"
47+
end
2248
end
2349
end
2450
end
@@ -59,9 +85,15 @@ class Application < Rails::Application
5985

6086
config.paths['log'] = "#{Msf::Config.log_directory}/#{Rails.env}.log"
6187
config.paths['config/database'] = [Metasploit::Framework::Database.configurations_pathname.try(:to_path)]
62-
config.autoloader = :zeitwerk
6388

64-
config.load_defaults 7.2
89+
# Rails 8.0 upgrade: changed from 'config.load_defaults 7.2'.
90+
# Activates Rails 8.0 framework defaults including:
91+
# - config.active_support.to_time_preserves_timezone = :zone
92+
# - config.active_record.default_column_serializer = nil
93+
# - config.active_record.run_after_transaction_callbacks_in_order_defined = true
94+
# The config.autoloader = :zeitwerk line was also removed here because
95+
# Zeitwerk is the only autoloader in Rails 8 — the setting no longer exists.
96+
config.load_defaults 8.0
6597

6698
config.eager_load = false
6799
end

db/schema.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.2].define(version: 2026_01_30_124052) do
13+
ActiveRecord::Schema[8.0].define(version: 2026_01_30_124052) do
1414
# These are extensions that must be enabled in order to support this database
15-
enable_extension "plpgsql"
15+
enable_extension "pg_catalog.plpgsql"
1616

1717
create_table "api_keys", id: :serial, force: :cascade do |t|
1818
t.text "token"

lib/metasploit/framework/rails_version_constraint.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
module Metasploit
44
module Framework
55
module RailsVersionConstraint
6-
RAILS_VERSION = '~> 7.2.0'
6+
# Rails 8.0 upgrade: changed from '~> 7.2.0' to '~> 8.0.0'.
7+
# This constant is used in metasploit-framework.gemspec to pin activerecord,
8+
# activesupport, and actionpack. Rails 8.0 requires Rack 3.x and Zeitwerk-only
9+
# autoloading, which drove the broader upgrade across all supporting gems.
10+
RAILS_VERSION = '~> 8.0.0'
711
end
812
end
913
end

0 commit comments

Comments
 (0)