decidim-cdtb 0.6.2 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c986754e258f5c89f059019e2eff8a989cb15972c8958a0aef8519246a1c974
4
- data.tar.gz: a930aa3920de4ffaa6549d86831dcc9f328b8e4be9eab69a3d0e99a4367ba7ad
3
+ metadata.gz: 87cfa078ca5fb059a580e029b4319a64d192a0b02e3cfd1136c2dd5d8d30a8e2
4
+ data.tar.gz: 2859c2bb9f9b079a672fe10600347bee48652daf70ec6810d412741765f00fdb
5
5
  SHA512:
6
- metadata.gz: 9ae0c57f0806d1d074969b6a4e6f5780d4cac4a6843d0696cc65c1235025e604eb5e6a1c866260a99fd15099b019aee936932888c0cdf0de345622b5a32d684d
7
- data.tar.gz: 187bcef080e8308048ee7250a8b7b226dc21ff644e875ac254a33164df150338a491d000e79b73058f04aea8bf03d639a1ce76707df340679a0af05610215122
6
+ metadata.gz: 48af433b8ce336f0f1f78a293a0ab129543e556b574f749e8b561e149f3fda247a59a4126cd6e512e35e127e17be921f22a0ad8abc78ad687a52419e4ff74cdd
7
+ data.tar.gz: df959a73420d0db727c237ed5c37edbe69e79f224a2bd7bf71f335dafc02d79b3a491718763ab3b2d6ac13716825c5f3cd475e55da2f35268e821c59e9c00ffa
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## [0.6.3] - 2026-10-16 (minor)
2
+
3
+ - Implement RackAttack feature to block abuse reported IPs.
4
+ - Improve RackAttack tests and compatibility with subnets.
5
+
1
6
  ## [0.6.2] - 2026-09-10 (minor)
2
7
 
3
8
  - Prevent `cdtb:users:remove` from enqueueing the admin block notification email when blocking users while preserving auditability and moderation records.
data/Gemfile.lock CHANGED
@@ -141,7 +141,7 @@ GIT
141
141
  PATH
142
142
  remote: .
143
143
  specs:
144
- decidim-cdtb (0.6.2)
144
+ decidim-cdtb (0.6.3)
145
145
  decidim (>= 0.29.0)
146
146
  rails (>= 6)
147
147
  ruby-progressbar
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "cdtb/ip_parser"
4
+ require "csv"
5
+ require "ipaddr"
4
6
 
5
7
  unless ENV["CDTB_RACK_ATTACK_DISABLED"].to_i.positive? || %w[development test].include?(Rails.env)
6
8
  require "rack/attack"
@@ -36,14 +38,38 @@ unless ENV["CDTB_RACK_ATTACK_DISABLED"].to_i.positive? || %w[development test].i
36
38
  end
37
39
 
38
40
  Rack::Attack.blocklist("cdtb:block all PHP RQs") do |request|
39
- request.path.end_with?("*.php")
41
+ request.path.end_with?(".php")
42
+ end
43
+
44
+ ABUSE_REPORTED_IPS_CSV_PATH= ENV.fetch("ABUSE_REPORTED_IPS_CSV_PATH", nil)
45
+ if ABUSE_REPORTED_IPS_CSV_PATH.present? && File.exist?(ABUSE_REPORTED_IPS_CSV_PATH)
46
+ ABUSE_REPORTED_IPS_CACHE_KEY= ["cdtb", "reported_ips", ABUSE_REPORTED_IPS_CSV_PATH].freeze
47
+ Rack::Attack.blocklist("block IPs in reported website") do |request|
48
+ ip= Cdtb::IpParser.extract_ip(request)
49
+
50
+ reported_ips = Rails.cache.fetch(ABUSE_REPORTED_IPS_CACHE_KEY, expires_in: 1.hour) do
51
+ if ABUSE_REPORTED_IPS_CSV_PATH.present? && File.exist?(ABUSE_REPORTED_IPS_CSV_PATH)
52
+ CSV.read(ABUSE_REPORTED_IPS_CSV_PATH).flatten.compact.map(&:strip).reject(&:blank?)
53
+ else
54
+ []
55
+ end
56
+ end
57
+
58
+ reported_ips.any? { |reported_ip| ip.start_with?(reported_ip) }
59
+ end
40
60
  end
41
61
 
42
62
  if ENV["RACK_ATTACK_BLOCKED_IPS"].present?
43
- blocked_ips_and_subnets= ENV["RACK_ATTACK_BLOCKED_IPS"].split(",")
63
+ blocked_ips_and_subnets= ENV["RACK_ATTACK_BLOCKED_IPS"].split(",").filter_map do |ip_or_subnet|
64
+ IPAddr.new(ip_or_subnet.strip)
65
+ rescue IPAddr::InvalidAddressError
66
+ nil
67
+ end
44
68
  Rack::Attack.blocklist("cdtb:block all unaccepted IPs") do |request|
45
- ip= Cdtb::IpParser.extract_ip(request)
46
- blocked_ips_and_subnets.any? { |ip_or_subnet| ip.start_with?(ip_or_subnet) }
69
+ request_ip= IPAddr.new(Cdtb::IpParser.extract_ip(request))
70
+ blocked_ips_and_subnets.any? { |ip_or_subnet| ip_or_subnet.include?(request_ip) }
71
+ rescue IPAddr::InvalidAddressError
72
+ false
47
73
  end
48
74
  end
49
75
  end
@@ -4,6 +4,8 @@ module Cdtb
4
4
  # Parses IPs from Rack::Request objects, discarding the port.
5
5
  module IpParser
6
6
  def self.decorate_rack_request
7
+ return if Rack::Request.ancestors.include?(Cdtb::IpParser)
8
+
7
9
  Rack::Request.class_eval do
8
10
  include Cdtb::IpParser
9
11
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Decidim
4
4
  module Cdtb
5
- VERSION = "0.6.2"
5
+ VERSION = "0.6.3"
6
6
  DECIDIM_MIN_VERSION = ">= 0.29.0"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-cdtb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Valls
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-09-21 00:00:00.000000000 Z
11
+ date: 2026-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: decidim