Skip to content

Commit cd09ba6

Browse files
authored
fix: backport xss and rce fixes to v7.1 (#834)
* fix: backport xss and rce fixes to v7.1 This was fixed in #829 and #833 * chore(lint): lint'em real good * chore: remove reek
1 parent 81cc875 commit cd09ba6

File tree

18 files changed

+78
-85
lines changed

18 files changed

+78
-85
lines changed

.github/workflows/lint.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,3 @@ jobs:
1818
bundler-cache: true
1919
- run: bin/bundle --jobs=$(nproc) --retry=$(nproc)
2020
- run: bin/rubocop -P
21-
22-
reek:
23-
runs-on: ubuntu-latest
24-
strategy:
25-
fail-fast: true
26-
27-
steps:
28-
- uses: actions/checkout@v3
29-
- uses: ruby/setup-ruby@v1
30-
with:
31-
ruby-version: 3.1
32-
bundler: 2.4.12
33-
bundler-cache: true
34-
- run: bin/bundle --jobs=$(nproc) --retry=$(nproc)
35-
- run: bin/reek .

.rubocop.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ RSpec/RepeatedExample:
135135
Exclude:
136136
- spec/sidekiq_unique_jobs/unique_args_spec.rb
137137

138+
RSpec/SpecFilePathFormat:
139+
Exclude:
140+
- spec/performance/lock_digest_spec.rb
141+
- spec/performance/locksmith_spec.rb
142+
- spec/sidekiq_unique_jobs/configuration_spec.rb
143+
- spec/sidekiq_unique_jobs/middleware/server/until_and_while_executing_spec.rb
144+
138145
Style/Documentation:
139146
Enabled: true
140147
Exclude:

lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def configure(options = {})
186186
yield config
187187
else
188188
options.each do |key, val|
189-
config.send("#{key}=", val)
189+
config.send(:"#{key}=", val)
190190
end
191191
end
192192
end

lib/sidekiq_unique_jobs/web.rb

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ def self.registered(app) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
1414
end
1515

1616
app.get "/changelogs" do
17-
@filter = params[:filter] || "*"
17+
@filter = h(params[:filter] || "*")
1818
@filter = "*" if @filter == ""
19-
@count = (params[:count] || 100).to_i
20-
@current_cursor = params[:cursor]
21-
@prev_cursor = params[:prev_cursor]
19+
@count = h(params[:count] || 100).to_i
20+
@current_cursor = h(params[:cursor])
21+
@prev_cursor = h(params[:prev_cursor])
2222
@total_size, @next_cursor, @changelogs = changelog.page(
2323
cursor: @current_cursor,
2424
pattern: @filter,
@@ -34,11 +34,11 @@ def self.registered(app) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
3434
end
3535

3636
app.get "/locks" do
37-
@filter = params[:filter] || "*"
37+
@filter = h(params[:filter] || "*")
3838
@filter = "*" if @filter == ""
39-
@count = (params[:count] || 100).to_i
40-
@current_cursor = params[:cursor]
41-
@prev_cursor = params[:prev_cursor]
39+
@count = h(params[:count] || 100).to_i
40+
@current_cursor = h(params[:cursor])
41+
@prev_cursor = h(params[:prev_cursor])
4242

4343
@total_size, @next_cursor, @locks = digests.page(
4444
cursor: @current_cursor,
@@ -50,11 +50,11 @@ def self.registered(app) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
5050
end
5151

5252
app.get "/expiring_locks" do
53-
@filter = params[:filter] || "*"
53+
@filter = h(params[:filter] || "*")
5454
@filter = "*" if @filter == ""
55-
@count = (params[:count] || 100).to_i
56-
@current_cursor = params[:cursor]
57-
@prev_cursor = params[:prev_cursor]
55+
@count = h(params[:count] || 100).to_i
56+
@current_cursor = h(params[:cursor])
57+
@prev_cursor = h(params[:prev_cursor])
5858

5959
@total_size, @next_cursor, @locks = expiring_digests.page(
6060
cursor: @current_cursor,
@@ -72,7 +72,7 @@ def self.registered(app) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
7272
end
7373

7474
app.get "/locks/:digest" do
75-
@digest = params[:digest]
75+
@digest = h(params[:digest])
7676
@lock = SidekiqUniqueJobs::Lock.new(@digest)
7777

7878
erb(unique_template(:lock))
@@ -85,9 +85,10 @@ def self.registered(app) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
8585
end
8686

8787
app.get "/locks/:digest/jobs/:job_id/delete" do
88-
@digest = params[:digest]
88+
@digest = h(params[:digest])
89+
@job_id = h(params[:job_id])
8990
@lock = SidekiqUniqueJobs::Lock.new(@digest)
90-
@lock.unlock(params[:job_id])
91+
@lock.unlock(@job_id)
9192

9293
redirect_to "locks/#{@lock.key}"
9394
end

spec/performance/lock_digest_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
RSpec.describe SidekiqUniqueJobs::LockDigest, perf: true do
3+
RSpec.describe SidekiqUniqueJobs::LockDigest, :perf do
44
let(:lock_digest) { described_class.new(item) }
55
let(:job_class) { UntilExecutedJob }
66
let(:class_name) { worker_class.to_s }

spec/performance/locksmith_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
RSpec.describe SidekiqUniqueJobs::Locksmith, perf: true do
3+
RSpec.describe SidekiqUniqueJobs::Locksmith, :perf do
44
let(:locksmith_one) { described_class.new(item_one) }
55
let(:locksmith_two) { described_class.new(item_two) }
66

spec/sidekiq_unique_jobs/changelog_spec.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@
3939

4040
it "clears out all entries" do
4141
expect { clear }.to change { entity.entries.size }.by(-1)
42-
expect(clear).to be == 1
42+
expect(clear).to eq 1
4343
end
4444
end
4545

4646
context "without entries" do
4747
it "returns 0 (zero)" do
4848
expect { clear }.not_to change { entity.entries.size }
49-
expect(clear).to be == 0
49+
expect(clear).to eq 0
5050
end
5151
end
5252
end
@@ -55,27 +55,27 @@
5555
subject(:exist?) { entity.exist? }
5656

5757
context "when no entries exist" do
58-
it { is_expected.to be == false }
58+
it { is_expected.to be false }
5959
end
6060

6161
context "when entries exist" do
6262
before { simulate_lock(key, job_id) }
6363

64-
it { is_expected.to be == true }
64+
it { is_expected.to be true }
6565
end
6666
end
6767

6868
describe "#pttl" do
6969
subject(:pttl) { entity.pttl }
7070

7171
context "when no entries exist" do
72-
it { is_expected.to be == -2 }
72+
it { is_expected.to eq(-2) }
7373
end
7474

7575
context "when entries exist without expiration" do
7676
before { simulate_lock(key, job_id) }
7777

78-
it { is_expected.to be == -1 }
78+
it { is_expected.to eq(-1) }
7979
end
8080

8181
context "when entries exist with expiration" do
@@ -92,13 +92,13 @@
9292
subject(:ttl) { entity.ttl }
9393

9494
context "when no entries exist" do
95-
it { is_expected.to be == -2 }
95+
it { is_expected.to eq(-2) }
9696
end
9797

9898
context "when entries exist without expiration" do
9999
before { simulate_lock(key, job_id) }
100100

101-
it { is_expected.to be == -1 }
101+
it { is_expected.to eq(-1) }
102102
end
103103

104104
context "when entries exist with expiration" do
@@ -107,15 +107,15 @@
107107
expire(key.changelog, 600)
108108
end
109109

110-
it { is_expected.to be == 600 }
110+
it { is_expected.to eq 600 }
111111
end
112112
end
113113

114114
describe "#expires?" do
115115
subject(:expires?) { entity.expires? }
116116

117117
context "when no entries exist" do
118-
it { is_expected.to be == false }
118+
it { is_expected.to be false }
119119
end
120120

121121
context "when entries exist" do
@@ -124,21 +124,21 @@
124124
expire(key.changelog, 600)
125125
end
126126

127-
it { is_expected.to be == true }
127+
it { is_expected.to be true }
128128
end
129129
end
130130

131131
describe "#count" do
132132
subject(:count) { entity.count }
133133

134134
context "when no entries exist" do
135-
it { is_expected.to be == 0 }
135+
it { is_expected.to eq 0 }
136136
end
137137

138138
context "when entries exist" do
139139
before { simulate_lock(key, job_id) }
140140

141-
it { is_expected.to be == 2 }
141+
it { is_expected.to eq 2 }
142142
end
143143
end
144144

spec/sidekiq_unique_jobs/cli_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
jobs del PATTERN
3838
3939
Options:
40-
d, [--dry-run], [--no-dry-run] # set to false to perform deletion
41-
c, [--count=N] # The max number of digests to return
42-
# Default: 1000
40+
-d, [--dry-run], [--no-dry-run] # set to false to perform deletion
41+
-c, [--count=N] # The max number of digests to return
42+
# Default: 1000
4343
4444
deletes unique digests from redis by pattern
4545
HEADER
@@ -55,8 +55,8 @@
5555
jobs list PATTERN
5656
5757
Options:
58-
c, [--count=N] # The max number of digests to return
59-
# Default: 1000
58+
-c, [--count=N] # The max number of digests to return
59+
# Default: 1000
6060
6161
list all unique digests and their expiry time
6262
HEADER

spec/sidekiq_unique_jobs/lua/delete_by_digest_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
it "deletes the expected keys from redis" do
4141
expect(delete_by_digest).to eq(8)
4242

43-
expect(queued.count).to be == 0
44-
expect(primed.count).to be == 0
45-
expect(locked.count).to be == 0
43+
expect(queued.count).to eq 0
44+
expect(primed.count).to eq 0
45+
expect(locked.count).to eq 0
4646

47-
expect(run_queued.count).to be == 0
48-
expect(run_primed.count).to be == 0
49-
expect(run_locked.count).to be == 0
47+
expect(run_queued.count).to eq 0
48+
expect(run_primed.count).to eq 0
49+
expect(run_locked.count).to eq 0
5050
end
5151
end

spec/sidekiq_unique_jobs/lua/lock_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
let(:now_f) { SidekiqUniqueJobs.now_f }
2121
let(:lock_limit) { 1 }
2222

23-
shared_context "with a primed key", with_primed_key: true do
23+
shared_context "with a primed key", :with_primed_key do
2424
before do
2525
call_script(:queue, key.to_a, argv_one)
2626
rpoplpush(key.queued, key.primed)

0 commit comments

Comments
 (0)