Skip to content

Commit ddc63b7

Browse files
Merge pull request rails#43923 from wynksaiddestroy/dont_use_single_character_block_argument_names
Improve security guide by avoiding single character block argument names [ci-skip]
2 parents 39d22f9 + a330b72 commit ddc63b7

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

guides/source/security.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -908,21 +908,21 @@ system("/bin/echo","hello; rm *")
908908
`Kernel#open` executes OS command if the argument starts with a vertical bar (`|`).
909909

910910
```ruby
911-
open('| ls') { |f| f.read }
911+
open('| ls') { |file| file.read }
912912
# returns file list as a String via `ls` command
913913
```
914914

915915
Countermeasures are to use `File.open`, `IO.open` or `URI#open` instead. They don't execute an OS command.
916916

917917
```ruby
918-
File.open('| ls') { |f| f.read }
918+
File.open('| ls') { |file| file.read }
919919
# doesn't execute `ls` command, just opens `| ls` file if it exists
920920

921-
IO.open(0) { |f| f.read }
921+
IO.open(0) { |file| file.read }
922922
# opens stdin. doesn't accept a String as the argument
923923

924924
require 'open-uri'
925-
URI('https://example.com').open { |f| f.read }
925+
URI('https://example.com').open { |file| file.read }
926926
# opens the URI. `URI()` doesn't accept `| ls`
927927
```
928928

@@ -1098,22 +1098,22 @@ Example controller overrides:
10981098
```ruby
10991099
# Override policy inline
11001100
class PostsController < ApplicationController
1101-
content_security_policy do |p|
1102-
p.upgrade_insecure_requests true
1101+
content_security_policy do |policy|
1102+
policy.upgrade_insecure_requests true
11031103
end
11041104
end
11051105

11061106
# Using literal values
11071107
class PostsController < ApplicationController
1108-
content_security_policy do |p|
1109-
p.base_uri "https://www.example.com"
1108+
content_security_policy do |policy|
1109+
policy.base_uri "https://www.example.com"
11101110
end
11111111
end
11121112

11131113
# Using mixed static and dynamic values
11141114
class PostsController < ApplicationController
1115-
content_security_policy do |p|
1116-
p.base_uri :self, -> { "https://#{current_user.domain}.example.com" }
1115+
content_security_policy do |policy|
1116+
policy.base_uri :self, -> { "https://#{current_user.domain}.example.com" }
11171117
end
11181118
end
11191119

0 commit comments

Comments
 (0)