Skip to content

Commit 074d16b

Browse files
authored
Merge pull request #1737 from coderdojo-japan/fix/brakeman-dynamic-render-path
Dynamic Render Path警告の解消(Book.exist?の安全化)
2 parents eb3e7b8 + 9bcc9e6 commit 074d16b

File tree

4 files changed

+8
-63
lines changed

4 files changed

+8
-63
lines changed

app/controllers/sotechsha2_pages_controller.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.

app/controllers/sotechsha_pages_controller.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.

app/models/book.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ def find(title)
1919
end
2020

2121
def exist?(title, page)
22-
page.nil? ?
23-
self.find(title).any? :
24-
self.find(title).map(&:filename).include?(page + ".html")
22+
return false unless page.present?
23+
24+
view_paths = [
25+
Rails.root.join("app/views/books/#{title}/#{page}.html.erb"),
26+
Rails.root.join("app/views/#{title}/#{page}.html.erb")
27+
]
28+
29+
view_paths.any? { |path| File.exist?(path) }
2530
end
2631
end
2732

config/brakeman.ignore

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,5 @@
11
{
22
"ignored_warnings": [
3-
{
4-
"warning_type": "Dynamic Render Path",
5-
"warning_code": 15,
6-
"fingerprint": "69b5a133fab8ea617d2581423cefaf077b9366e683c5fac715647bddeec7f50a",
7-
"check_name": "Render",
8-
"message": "Render path contains parameter value",
9-
"file": "app/controllers/sotechsha_pages_controller.rb",
10-
"line": 5,
11-
"link": "https://brakemanscanner.org/docs/warning_types/dynamic_render_path/",
12-
"code": "render(action => \"sotechsha_pages/#{params[:page]}\", {})",
13-
"render_path": null,
14-
"location": {
15-
"type": "method",
16-
"class": "SotechshaPagesController",
17-
"method": "show"
18-
},
19-
"user_input": "params[:page]",
20-
"confidence": "Medium",
21-
"cwe_id": [
22-
22
23-
],
24-
"note": ""
25-
},
263
{
274
"warning_type": "Command Injection",
285
"warning_code": 14,
@@ -188,29 +165,6 @@
188165
],
189166
"note": ""
190167
},
191-
{
192-
"warning_type": "Dynamic Render Path",
193-
"warning_code": 15,
194-
"fingerprint": "c54623ebce2c2053b95088b9da8112aee962e7cadd79bd9b4b9afdedaddc15b1",
195-
"check_name": "Render",
196-
"message": "Render path contains parameter value",
197-
"file": "app/controllers/sotechsha2_pages_controller.rb",
198-
"line": 5,
199-
"link": "https://brakemanscanner.org/docs/warning_types/dynamic_render_path/",
200-
"code": "render(action => \"sotechsha2_pages/#{params[:page]}\", {})",
201-
"render_path": null,
202-
"location": {
203-
"type": "method",
204-
"class": "Sotechsha2PagesController",
205-
"method": "show"
206-
},
207-
"user_input": "params[:page]",
208-
"confidence": "Medium",
209-
"cwe_id": [
210-
22
211-
],
212-
"note": ""
213-
},
214168
{
215169
"warning_type": "Cross-Site Scripting",
216170
"warning_code": 2,

0 commit comments

Comments
 (0)