From dd5176a3b3bf5f7064731b088f85dc5bdc88278d Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 29 Jul 2026 14:13:10 +0200 Subject: [PATCH 1/2] Update dependencies for security fixes --- Gemfile.lock | 48 +++++++++-------- app/serializers/news/rss_serializer.rb | 5 +- config/routes.rb | 4 +- lib/news/engine.rb | 2 +- lib/news/item.rb | 2 +- lib/news/rss.rb | 3 +- lib/news/rss_topic_list.rb | 2 +- plugin.rb | 72 +++++++++++++------------- spec/lib/news/item_spec.rb | 17 ++++-- spec/lib/news/rss_spec.rb | 14 +++-- spec/system/news_spec.rb | 2 +- 11 files changed, 91 insertions(+), 80 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5d6be87..01028bb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ GEM remote: https://rubygems.org/ specs: - activesupport (8.1.2) + activesupport (8.1.3) base64 bigdecimal concurrent-ruby (~> 1.0, >= 1.3.1) @@ -16,48 +16,49 @@ GEM uri (>= 0.13.1) ast (2.4.3) base64 (0.3.0) - bigdecimal (4.0.1) - concurrent-ruby (1.3.6) + bigdecimal (4.1.2) + concurrent-ruby (1.3.8) connection_pool (3.0.2) drb (2.2.3) - i18n (1.14.8) + i18n (1.15.2) concurrent-ruby (~> 1.0) - json (2.18.0) - language_server-protocol (3.17.0.5) + json (2.21.1) + language_server-protocol (3.17.0.6) lint_roller (1.1.0) logger (1.7.0) - minitest (6.0.1) + minitest (6.0.6) + drb (~> 2.0) prism (~> 1.5) - parallel (1.27.0) - parser (3.3.10.1) + parallel (2.1.0) + parser (3.3.12.0) ast (~> 2.4.1) racc - prism (1.8.0) + prism (1.9.0) racc (1.8.1) - rack (3.2.4) + rack (3.2.6) rainbow (3.1.1) - regexp_parser (2.11.3) - rubocop (1.82.1) + regexp_parser (2.12.0) + rubocop (1.88.2) json (~> 2.3) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.1.0) - parallel (~> 1.10) + parallel (>= 1.10) parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 2.9.3, < 3.0) - rubocop-ast (>= 1.48.0, < 2.0) + rubocop-ast (>= 1.49.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 4.0) - rubocop-ast (1.49.0) + rubocop-ast (1.50.0) parser (>= 3.3.7.2) prism (~> 1.7) - rubocop-capybara (2.22.1) + rubocop-capybara (3.0.0) lint_roller (~> 1.1) - rubocop (~> 1.72, >= 1.72.1) - rubocop-discourse (3.14.0) + rubocop (~> 1.81) + rubocop-discourse (3.18.0) activesupport (>= 6.1) lint_roller (>= 1.1.0) - rubocop-capybara (>= 2.22.0) + rubocop-capybara (>= 2.23.0) rubocop-discourse-base (>= 1.0.0) rubocop-factory_bot (>= 2.27.0) rubocop-rails (>= 2.30.3) @@ -68,15 +69,16 @@ GEM rubocop-factory_bot (2.28.0) lint_roller (~> 1.1) rubocop (~> 1.72, >= 1.72.1) - rubocop-rails (2.34.3) + rubocop-rails (2.36.0) activesupport (>= 4.2.0) lint_roller (~> 1.1) rack (>= 1.1) rubocop (>= 1.75.0, < 2.0) rubocop-ast (>= 1.44.0, < 2.0) - rubocop-rspec (3.9.0) + rubocop-rspec (3.10.2) lint_roller (~> 1.1) - rubocop (~> 1.81) + regexp_parser (>= 2.0) + rubocop (~> 1.86, >= 1.86.2) rubocop-rspec_rails (2.32.0) lint_roller (~> 1.1) rubocop (~> 1.72, >= 1.72.1) diff --git a/app/serializers/news/rss_serializer.rb b/app/serializers/news/rss_serializer.rb index 9147384..fea654d 100644 --- a/app/serializers/news/rss_serializer.rb +++ b/app/serializers/news/rss_serializer.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true class News::RssSerializer < ::ApplicationSerializer - attributes :title, - :description, - :url, - :image_url + attributes :title, :description, :url, :image_url end diff --git a/config/routes.rb b/config/routes.rb index e645860..c349d91 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,3 @@ # frozen_string_literal: true -Discourse::Application.routes.prepend do - get 'news' => 'list#news' -end \ No newline at end of file +Discourse::Application.routes.prepend { get "news" => "list#news" } diff --git a/lib/news/engine.rb b/lib/news/engine.rb index c0a24e0..b2bc597 100644 --- a/lib/news/engine.rb +++ b/lib/news/engine.rb @@ -6,4 +6,4 @@ class Engine < ::Rails::Engine isolate_namespace News config.autoload_paths << File.join(config.root, "lib") end -end \ No newline at end of file +end diff --git a/lib/news/item.rb b/lib/news/item.rb index 05c1a48..f2b9912 100644 --- a/lib/news/item.rb +++ b/lib/news/item.rb @@ -10,4 +10,4 @@ def self.generate_body(html, featured_image_url) doc.to_html end -end \ No newline at end of file +end diff --git a/lib/news/rss.rb b/lib/news/rss.rb index 608b781..b66787c 100644 --- a/lib/news/rss.rb +++ b/lib/news/rss.rb @@ -43,7 +43,8 @@ def description def image_url @image_url ||= begin - if @attrs.enclosure && @attrs.enclosure.type.include?("image") && @attrs.enclosure.url + if @attrs.enclosure && @attrs.enclosure.type.include?("image") && + @attrs.enclosure.url @attrs.enclosure.url end end diff --git a/lib/news/rss_topic_list.rb b/lib/news/rss_topic_list.rb index 50b070d..d6545d4 100644 --- a/lib/news/rss_topic_list.rb +++ b/lib/news/rss_topic_list.rb @@ -2,4 +2,4 @@ module News RssTopicList = Struct.new(:topics, :more_topics_url) -end \ No newline at end of file +end diff --git a/plugin.rb b/plugin.rb index 49a0add..258e9b3 100644 --- a/plugin.rb +++ b/plugin.rb @@ -6,8 +6,8 @@ # authors: Angus McLeod # url: https://github.com/paviliondev/discourse-news -register_asset 'stylesheets/common/discourse-news.scss' -register_asset 'stylesheets/mobile/discourse-news.scss', :mobile +register_asset "stylesheets/common/discourse-news.scss" +register_asset "stylesheets/mobile/discourse-news.scss", :mobile enabled_site_setting :discourse_news_enabled @@ -21,59 +21,61 @@ end add_to_class(:list_controller, :news) do - if SiteSetting.discourse_news_source == 'rss' + if SiteSetting.discourse_news_source == "rss" feed_url = SiteSetting.discourse_news_rss feed = News::Rss.get_feed_items(feed_url) ## TODO implement caching: News::Rss.cached_feed(feed_url) - - serialized = ActiveModel::ArraySerializer.new(feed, each_serializer: News::RssSerializer, root: false) - + + serialized = + ActiveModel::ArraySerializer.new( + feed, + each_serializer: News::RssSerializer, + root: false + ) + respond_to do |format| format.html do @list = News::RssTopicList.new(feed, nil) store_preloaded("topic_list_news_rss", MultiJson.dump(serialized)) - render 'list/list' - end - format.json do - render json: serialized + render "list/list" end + format.json { render json: serialized } end else respond_with_list(TopicQuery.new(current_user).list_news) end end - + add_to_class(:topic_query, :list_news) do category_ids = [*SiteSetting.discourse_news_category.split("|")] - - topics = Topic.joins(:category).where('categories.id IN (?)', category_ids) - topics = topics.joins(" + + topics = Topic.joins(:category).where("categories.id IN (?)", category_ids) + topics = + topics.joins( + " LEFT OUTER JOIN topic_users AS tu ON ( topics.id = tu.topic_id AND tu.user_id = #{@user.id.to_i} )" - ).references('tu') if @user - - topics = topics.where('COALESCE(categories.topic_id, 0) <> topics.id') - + ).references("tu") if @user + + topics = topics.where("COALESCE(categories.topic_id, 0) <> topics.id") + topics = topics.order("topics.#{SiteSetting.discourse_news_sort} DESC") create_list(:news, {}, topics) end - + add_to_class(:topic, :news_item) do - category_ids = SiteSetting.discourse_news_category.split('|').map(&:to_i) + category_ids = SiteSetting.discourse_news_category.split("|").map(&:to_i) category_ids.include? category_id.to_i end - + add_to_class(:topic, :news_body) do - @news_body ||= begin - if news_item - News::Item.generate_body(first_post.cooked, image_url) - else - nil + @news_body ||= + begin + news_item ? News::Item.generate_body(first_post.cooked, image_url) : nil end - end end - + module TopicNewsExtension def reload(options = nil) @news_body = nil @@ -81,11 +83,11 @@ def reload(options = nil) end end - reloadable_patch do - ::Topic.prepend(TopicNewsExtension) - end - - add_to_serializer(:topic_list_item, :news_body, include_condition: -> { object.news_item }) do - object.news_body - end + reloadable_patch { ::Topic.prepend(TopicNewsExtension) } + + add_to_serializer( + :topic_list_item, + :news_body, + include_condition: -> { object.news_item } + ) { object.news_body } end diff --git a/spec/lib/news/item_spec.rb b/spec/lib/news/item_spec.rb index eef8ef0..41c8136 100644 --- a/spec/lib/news/item_spec.rb +++ b/spec/lib/news/item_spec.rb @@ -3,8 +3,10 @@ RSpec.describe News::Item do describe ".generate_body" do it "removes the featured image from the body" do - html = '

Hello

World

' - result = described_class.generate_body(html, "https://example.com/featured.jpg") + html = + '

Hello

World

' + result = + described_class.generate_body(html, "https://example.com/featured.jpg") expect(result).not_to include("featured.jpg") expect(result).to include("Hello") @@ -12,7 +14,8 @@ end it "removes lightbox wrappers" do - html = '

Text

More

' + html = + '

Text

More

' result = described_class.generate_body(html, nil) expect(result).not_to include("lightbox-wrapper") @@ -28,11 +31,15 @@ paragraphs = doc.css("p") expect(paragraphs.size).to eq(2) - expect(paragraphs.map(&:text)).to contain_exactly("Content", "More content") + expect(paragraphs.map(&:text)).to contain_exactly( + "Content", + "More content" + ) end it "preserves valid HTML structure" do - html = '

Paragraph

' + html = + '

Paragraph

' result = described_class.generate_body(html, nil) expect(result).to include('
') diff --git a/spec/lib/news/rss_spec.rb b/spec/lib/news/rss_spec.rb index e158a90..b62d11d 100644 --- a/spec/lib/news/rss_spec.rb +++ b/spec/lib/news/rss_spec.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true RSpec.describe News::Rss do - let(:sample_rss) do - <<~RSS + let(:sample_rss) { <<~RSS } @@ -25,11 +24,11 @@ RSS - end describe ".detect_charset" do it "extracts charset from Content-Type header" do - response = double(headers: { "Content-Type" => "text/xml; charset=ISO-8859-1" }) + response = + double(headers: { "Content-Type" => "text/xml; charset=ISO-8859-1" }) charset = described_class.detect_charset(response) expect(charset).to eq(Encoding::ISO_8859_1) @@ -43,7 +42,12 @@ end it "returns nil for invalid charset" do - response = double(headers: { "Content-Type" => "text/xml; charset=invalid-encoding" }) + response = + double( + headers: { + "Content-Type" => "text/xml; charset=invalid-encoding" + } + ) charset = described_class.detect_charset(response) expect(charset).to be_nil diff --git a/spec/system/news_spec.rb b/spec/system/news_spec.rb index 7e21ccc..8393ebf 100644 --- a/spec/system/news_spec.rb +++ b/spec/system/news_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe "News page", type: :system do +RSpec.describe "News page" do fab!(:category) fab!(:topic) { Fabricate(:topic, category: category) } fab!(:post) { Fabricate(:post, topic: topic) } From 66dc8e6a1a59f6a836e3f30b6267ae8e9c5148a7 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 30 Jul 2026 10:33:14 +0200 Subject: [PATCH 2/2] DEV: Complete dependency update audit --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 01028bb..f157ca0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ GEM remote: https://rubygems.org/ specs: - activesupport (8.1.3) + activesupport (8.1.3.1) base64 bigdecimal concurrent-ruby (~> 1.0, >= 1.3.1) @@ -100,4 +100,4 @@ DEPENDENCIES rubocop-discourse BUNDLED WITH - 2.6.9 + 4.0.11