Skip to content

Commit 697e8af

Browse files
committed
security: エラーメッセージからユーザー入力値を除外(XSS対策)
- エラーメッセージに具体的な入力値を含めない - '指定された年(値)は無効です' → '指定された年は無効です' - 現在も.to_iとHTMLエスケープで安全だが、より防御的な実装に - セキュリティのベストプラクティスに従う
1 parent 5cda416 commit 697e8af

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

app/controllers/dojos_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def index
88
year = params[:year].to_i
99
# 有効な年の範囲をチェック
1010
unless year.between?(2012, Date.current.year)
11-
flash[:alert] = "指定された年(#{year})は無効です。2012年から#{Date.current.year}年の間で指定してください。"
11+
flash[:alert] = "指定された年は無効です。2012年から#{Date.current.year}年の間で指定してください。"
1212
return redirect_to dojos_path(anchor: 'table')
1313
end
1414

spec/requests/dojos_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
future_year = Date.current.year + 1
6363
get dojos_path(year: future_year, format: :json)
6464
expect(response).to redirect_to(dojos_path(anchor: 'table'))
65-
expect(flash[:alert]).to include("無効です")
65+
expect(flash[:alert]).to include("指定された年は無効です")
6666
end
6767

6868
it "handles invalid year strings" do

0 commit comments

Comments
 (0)