fix(core,board,ecommerce,page): 중첩 리소스 스코프·계층 무결성 결함 12건 일괄 수정

중첩 라우트의 상위 리소스 ID 를 조회 스코프에 반영하지 않아 A 의 경로로 B 의
하위 리소스를 읽거나 변경할 수 있었다. 방어 위치를 Repository where 절(SSoT)로
통일하고 컨트롤러 사후 비교에 의존하지 않게 했다. 같은 리소스의 형제 엔드포인트가
서로 다른 강도로 검증하던 부분도 맞췄다.

계층 리소스는 자기 자신·자손을 부모로 지정하는 순환을 검증 계층에서 차단하고,
검증을 우회하는 경로(시더/훅/오염 데이터)를 위해 path 재귀에 방문 ID 가드를 뒀다.
설정값이 정하는 깊이 상한을 Service 가 리터럴로 재클램프하던 부분을 제거해
게시판 설정이 실제로 적용되게 했다.

쓰기 경로는 validated 기준으로 좁혀 FormRequest 미정의 필드가 fillable 로
새지 않게 했다. 기존 오염 데이터는 업그레이드 스텝이 정리한다(삭제 없이 최상위로 이동).

재발 방지로 audit 룰 3종을 추가하고, 규정 문서와 트러블슈팅 사례를 함께 갱신했다.

공개 이슈: gnuboard/g7
This commit is contained in:
HeuJung committed 2026-07-24 16:17:44 +09:00
1 parent 9dda22f8e4
commit abb40ad210
74 files changed
+3880 -192

No files matched your search

@@ -127,8 +127,8 @@ class CommentController extends AdminBaseController
public function update(UpdateCommentRequest $request, string $slug, int $postId, int $id): JsonResponse
{
try {
// 댓글 조회
$comment = $this->commentService->getComment($slug, $id);
// 경로의 게시글에 속한 댓글만 조회 (교차 게시글 접근 차단)
$comment = $this->commentService->getComment($slug, $id, $postId);
// 권한 체크: 본인 댓글 또는 admin.manage
if ($response = $this->authorizeCommentModification($slug, $comment->user_id)) {
@@ -146,7 +146,7 @@ class CommentController extends AdminBaseController
}
$data = $request->validated();
$updatedComment = $this->commentService->updateComment($slug, $id, $data);
$updatedComment = $this->commentService->updateComment($slug, $id, $data, $postId);
return $this->successWithResource(
'sirsoft-board::messages.comment.update_success',
@@ -170,8 +170,8 @@ class CommentController extends AdminBaseController
public function destroy(string $slug, int $postId, int $id): JsonResponse
{
try {
// 댓글 조회
$comment = $this->commentService->getComment($slug, $id);
// 경로의 게시글에 속한 댓글만 조회 (교차 게시글 접근 차단)
$comment = $this->commentService->getComment($slug, $id, $postId);
// 권한 체크: 본인 댓글 또는 admin.manage
if ($response = $this->authorizeCommentModification($slug, $comment->user_id)) {
@@ -188,7 +188,7 @@ class CommentController extends AdminBaseController
return $this->error('sirsoft-board::messages.comments.comments_disabled', 403);
}
$this->commentService->deleteComment($slug, $id, 'admin');
$this->commentService->deleteComment($slug, $id, 'admin', $postId);
return $this->success('sirsoft-board::messages.comment.delete_success');
} catch (ModelNotFoundException) {
@@ -223,7 +223,7 @@ class CommentController extends AdminBaseController
$validated = $request->validated();
$reason = $validated['reason'] ?? '';
$comment = $this->commentService->blindComment($slug, $id, $reason);
$comment = $this->commentService->blindComment($slug, $id, $reason, null, $postId);
return $this->successWithResource(
'sirsoft-board::messages.comment.blind_success',
@@ -259,7 +259,7 @@ class CommentController extends AdminBaseController
}
$reason = $request->validated()['reason'] ?? null;
$comment = $this->commentService->restoreComment($slug, $id, $reason);
$comment = $this->commentService->restoreComment($slug, $id, $reason, null, $postId);
return $this->successWithResource(
'sirsoft-board::messages.comment.restore_success',
@@ -5,14 +5,14 @@ namespace Modules\Sirsoft\Board\Http\Controllers\User;
use App\Http\Controllers\Api\Base\PublicBaseController;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Modules\Sirsoft\Board\Http\Requests\StoreCommentRequest;
use Modules\Sirsoft\Board\Http\Requests\UpdateCommentRequest;
use Modules\Sirsoft\Board\Http\Requests\VerifyCommentPasswordRequest;
use Modules\Sirsoft\Board\Http\Resources\CommentResource;
use Modules\Sirsoft\Board\Models\Board;
use Modules\Sirsoft\Board\Services\BoardService;
use Modules\Sirsoft\Board\Services\CommentService;
/**
@@ -26,9 +26,11 @@ class CommentController extends PublicBaseController
* CommentController 생성자
*
* @param CommentService $commentService 댓글 서비스
* @param BoardService $boardService 게시판 서비스
*/
public function __construct(
private CommentService $commentService
private CommentService $commentService,
private BoardService $boardService
) {
parent::__construct();
}
@@ -43,7 +45,11 @@ class CommentController extends PublicBaseController
public function index(string $slug, int $postId): JsonResponse
{
try {
$board = Board::where('slug', $slug)->firstOrFail();
$board = $this->boardService->getBoardBySlug($slug, checkScope: false);
if (! $board) {
return $this->error('sirsoft-board::messages.boards.not_found', 404);
}
if (! $board->use_comment) {
return $this->error('sirsoft-board::messages.comments.comments_disabled', 403);
@@ -73,13 +79,19 @@ class CommentController extends PublicBaseController
public function store(StoreCommentRequest $request, string $slug, int $postId): JsonResponse
{
try {
$board = Board::where('slug', $slug)->firstOrFail();
$board = $this->boardService->getBoardBySlug($slug, checkScope: false);
if (! $board) {
return $this->error('sirsoft-board::messages.boards.not_found', 404);
}
if (! $board->use_comment) {
return $this->error('sirsoft-board::messages.comments.comments_disabled', 403);
}
$data = $request->validated();
// 경로의 게시글을 SSoT 로 고정 (요청 본문 값이 경로와 갈라지지 않도록)
$data['post_id'] = $postId;
$data['ip_address'] = $request->ip();
// user_id 설정 (인증 필수)
@@ -119,13 +131,18 @@ class CommentController extends PublicBaseController
public function update(UpdateCommentRequest $request, string $slug, int $postId, int $commentId): JsonResponse
{
try {
$board = Board::where('slug', $slug)->firstOrFail();
$board = $this->boardService->getBoardBySlug($slug, checkScope: false);
if (! $board) {
return $this->error('sirsoft-board::messages.boards.not_found', 404);
}
if (! $board->use_comment) {
return $this->error('sirsoft-board::messages.comments.comments_disabled', 403);
}
$comment = $this->commentService->getComment($slug, $commentId);
// 경로의 게시글에 속한 댓글만 조회 (교차 게시글 접근 차단)
$comment = $this->commentService->getComment($slug, $commentId, $postId);
// 권한 확인 (Service에서 처리)
$canUpdate = $this->commentService->canUpdate(
@@ -139,9 +156,9 @@ class CommentController extends PublicBaseController
return $this->forbidden('sirsoft-board::messages.comment.update_forbidden');
}
// password는 검증용이므로 제거
$data = $request->except('password');
$updatedComment = $this->commentService->updateComment($slug, $commentId, $data);
// 검증된 필드만 반영 (미검증 입력의 대량 할당 차단). password는 검증용이므로 제거
$data = collect($request->validated())->except('password')->toArray();
$updatedComment = $this->commentService->updateComment($slug, $commentId, $data, $postId);
return $this->successWithResource(
'sirsoft-board::messages.comment.update_success',
@@ -165,13 +182,18 @@ class CommentController extends PublicBaseController
public function destroy(string $slug, int $postId, int $commentId): JsonResponse
{
try {
$board = Board::where('slug', $slug)->firstOrFail();
$board = $this->boardService->getBoardBySlug($slug, checkScope: false);
if (! $board) {
return $this->error('sirsoft-board::messages.boards.not_found', 404);
}
if (! $board->use_comment) {
return $this->error('sirsoft-board::messages.comments.comments_disabled', 403);
}
$comment = $this->commentService->getComment($slug, $commentId);
// 경로의 게시글에 속한 댓글만 조회 (교차 게시글 접근 차단)
$comment = $this->commentService->getComment($slug, $commentId, $postId);
// 비회원인 경우 password 파라미터 필요
$password = request()->input('password');
@@ -188,7 +210,7 @@ class CommentController extends PublicBaseController
return $this->forbidden('sirsoft-board::messages.comment.delete_forbidden');
}
$this->commentService->deleteComment($slug, $commentId, 'user');
$this->commentService->deleteComment($slug, $commentId, 'user', $postId);
return $this->success(
'sirsoft-board::messages.comment.delete_success'
@@ -203,17 +225,13 @@ class CommentController extends PublicBaseController
/**
* 비회원 댓글 비밀번호를 검증합니다.
*
* @param Request $request 요청
* @param VerifyCommentPasswordRequest $request 비밀번호 확인 요청
* @param string $slug 게시판 slug
* @param int $commentId 댓글 ID
* @return JsonResponse 비밀번호 검증 결과 응답
*/
public function verifyPassword(Request $request, string $slug, int $commentId): JsonResponse
public function verifyPassword(VerifyCommentPasswordRequest $request, string $slug, int $commentId): JsonResponse
{
$request->validate([
'password' => ['required', 'string'],
]);
try {
$comment = $this->commentService->getComment($slug, $commentId);
@@ -76,7 +76,8 @@ class StoreCommentRequest extends FormRequest
'parent_id' => [
'nullable',
'integer',
new CommentValidationRule($slug, 'parent_comment'),
// 부모 댓글은 요청 경로의 게시글에 속해야 한다 (교차 게시글 부모 차단)
new CommentValidationRule($slug, 'parent_comment', (int) $this->route('postId')),
],
// depth는 서비스에서 자동 계산되므로 요청 데이터에서 받지 않음 (보안상 이유)
'is_secret' => ['boolean'],
@@ -0,0 +1,57 @@
<?php
namespace Modules\Sirsoft\Board\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
/**
* 비회원 댓글 비밀번호 확인 요청 폼 검증
*/
class VerifyCommentPasswordRequest extends FormRequest
{
/**
* 사용자가 이 요청을 수행할 권한이 있는지 확인
*
* @return bool 권한 검증 결과 (권한 체크는 미들웨어 위임, 항상 true)
*/
public function authorize(): bool
{
return true;
}
/**
* 요청에 적용할 검증 규칙
*
* @return array<string, mixed> 필드별 검증 규칙
*/
public function rules(): array
{
return [
'password' => ['required', 'string'],
];
}
/**
* 검증 오류 메시지 커스터마이징
*
* @return array<string, string> 규칙별 다국어 메시지
*/
public function messages(): array
{
return [
'password.required' => __('sirsoft-board::validation.comment.password.required'),
];
}
/**
* 검증할 필드의 이름을 커스터마이징
*
* @return array<string, string> 필드별 표시명
*/
public function attributes(): array
{
return [
'password' => __('sirsoft-board::validation.attributes.comment.password'),
];
}
}