fix: reviews の作成・更新・削除をプレースホルダ化する (#529) - #531
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthrough
ChangesレビューSQLのパラメータ化
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to Review creation, update, and deletion now safely handle quoted comments and do not interpolate operation values into SQL. No actionable merge risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Close #529
Ref #363
変更内容
review_repository.goのCreate/Update/Deleteから文字列連結をなくし、プレースホルダに置き換える。コメントはユーザーの自由記述がそのままクォート内に連結されていたため、アポストロフィを1つ含むだけで INSERT が壊れ、アプリには「レビューの送信に失敗しました」とだけ出て入力が失われていた。同じ経路で SQL インジェクションも成立しうる。
repository の引数は string のまま受けるため、数値カラムへは
$1::intと明示的にキャストし、パラメータの型推論に依存しない形にしている。Crudはもともと可変長引数を受けるので、呼び出し側の変更だけで済んでいる。テスト
review_repository_sqlmock_test.goを追加した。コメントがクエリ本文ではなく引数として渡ることを固定するテストで、文字列連結に戻すと失敗する。アポストロフィを含むコメントを使っている。TestReviewRepositoryCreate_PassesCommentAsArgumentTestReviewRepositoryUpdate_PassesCommentAsArgumentAndIDLast(WHERE の id が末尾の$6であることも固定)TestReviewRepositoryDelete_PassesIDAsArgumentスコープ外
#363 に挙がっている他の repository(
department/place/bureau/grade/time/shift)は触っていない。#363 は引き続き開いたままにする。動作確認
go build ./...— 成功go vet ./lib/internals/repository/— 指摘なしgo test ./...— repository・usecase ともに okgolangci-lint run ./lib/internals/repository/...— 0 issuesSummary by CodeRabbit
セキュリティ改善
テスト