Skip to content

Commit 3ae8f4d

Browse files
committed
Fix chmod race condition when generating key
Encrypted keys were updated [previously][1] to restrict other users from reading the file by default. However, there is a brief period of time between an encrypted key being created and its permissions being set to 0600. This means that it is possible for another user to read that file during that time. This commit fixes that issue by setting the desired permissions when the file is created. The ability to use the `perm` option was added in Thor 1.2.2 so the minimum version was updated in the Railties gemspec. [1]: 4c6c357
1 parent cb1073e commit 3ae8f4d

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ PATH
106106
irb
107107
rackup (>= 1.0.0)
108108
rake (>= 12.2)
109-
thor (~> 1.0)
109+
thor (~> 1.0, >= 1.2.2)
110110
zeitwerk (~> 2.6)
111111

112112
GEM
@@ -517,7 +517,7 @@ GEM
517517
railties (>= 6.0.0)
518518
terser (1.1.13)
519519
execjs (>= 0.3.0, < 3)
520-
thor (1.2.1)
520+
thor (1.2.2)
521521
tilt (2.0.11)
522522
timeout (0.3.2)
523523
tomlrb (2.0.3)

railties/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ def add_key_file(key_path)
2626
end
2727

2828
def add_key_file_silently(key_path, key = nil)
29-
create_file key_path, key || ActiveSupport::EncryptedFile.generate_key
30-
key_path.chmod 0600
29+
create_file key_path, key || ActiveSupport::EncryptedFile.generate_key, perm: 0600
3130
end
3231

3332
def ignore_key_file(key_path, ignore: key_ignore(key_path))

railties/railties.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
4242

4343
s.add_dependency "rackup", ">= 1.0.0"
4444
s.add_dependency "rake", ">= 12.2"
45-
s.add_dependency "thor", "~> 1.0"
45+
s.add_dependency "thor", "~> 1.0", ">= 1.2.2"
4646
s.add_dependency "zeitwerk", "~> 2.6"
4747
s.add_dependency "irb"
4848

0 commit comments

Comments
 (0)