Skip to content

Commit dde3027

Browse files
committed
Improve brakeman config and fix some warnings.
1 parent 028be5f commit dde3027

File tree

7 files changed

+26
-5
lines changed

7 files changed

+26
-5
lines changed

bin/reloader

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ def reload(skip_seed: false)
2525
# Run the test suite (generates coverage report).
2626
system("#{"SKIP_SEED=1" if skip_seed} SIMPLECOV_INLINE_ASSETS=1 bin/rails test".strip)
2727

28-
# Generate brakeman report.
28+
# Generate lib brakeman report.
2929
system("bin/brakeman")
30+
31+
# Generage app brakeman report.
32+
Dir.chdir(File.join(PROJECT_ROOT, "test")) do
33+
system("bin/brakeman")
34+
end
3035
end
3136

3237
# Load to generate initial reports.

config/brakeman.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
:output_files:
3-
- test/public/reports/brakeman.html
3+
- test/public/reports/brakeman-lib.html
44
:combine_locations: false
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
class ApplicationController < ActionController::Base
22
include ActiveStorage::SetCurrent
3+
4+
protect_from_forgery
35
end

test/app/controllers/home_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ def send_guide_asset
2525

2626
protected
2727

28+
def sanitize_path(path)
29+
return path&.gsub(/[^a-zA-Z0-9-_\/]+/, "")&.gsub(/^\/+/, "")&.gsub(/\/+$/, "")
30+
end
31+
2832
def render_content(path)
2933
file_content = File.read(path)
3034

@@ -42,7 +46,7 @@ def render_content(path)
4246
def lookup_section(section, asset: nil)
4347
if path = self.get_sections.dig(section, :path)
4448
if asset
45-
f = File.join(path, "assets/#{asset}")
49+
f = File.join(path, "assets/#{sanitize_path(asset)}")
4650
return f if File.exist?(f)
4751
else
4852
return File.join(path, "index.md")

test/bin/brakeman

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env ruby
2+
require "rubygems"
3+
require "bundler/setup"
4+
5+
load Gem.bin_path("brakeman", "brakeman")

test/config/brakeman.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
:output_files:
3+
- public/reports/brakeman-app.html
4+
:combine_locations: false

test/public/reports/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
</head>
66
<body>
77
<h1>Reports:</h1>
8-
<p><a href="/reports/coverage/">SimpleCov Coverage Report</a></p>
9-
<p><a href="/reports/brakeman.html">Brakeman Vulnerability Report</a></p>
8+
<p><a target="_blank" href="/reports/coverage/">SimpleCov Coverage Report</a></p>
9+
<p><a target="_blank" href="/reports/brakeman-lib.html">Brakeman Vulnerability Report - Lib</a></p>
10+
<p><a target="_blank" href="/reports/brakeman-app.html">Brakeman Vulnerability Report - App</a></p>
1011
</body>
1112
</html>

0 commit comments

Comments
 (0)