🇰🇷 한글 설명
MarcosCamara01 이커머스 템플릿의 장바구니 및 위시리스트 저장소에서 사용자 제어 키를 통한 권한 우회 취약점이 발견되었습니다. PostgreSQL의 행 수준 보안(RLS)이 테이블 소유자에게 적용되지 않는 설정 오류로 인해, 인증된 사용자가 다른 사용자의 장바구니 및 위시리스트 데이터를 삭제하거나 수정할 수 있습니다.
💡 쉬운 설명
로그인한 사용자가 다른 사람의 장바구니 목록을 마음대로 지우거나 내용을 바꿀 수 있는 보안 결함입니다. 시스템이 데이터 주인인지 확인하는 절차를 건너뛰고 데이터베이스에 직접 접근하기 때문에 발생합니다.
🇺🇸 원문 (English)
Authorization Bypass Through User-Controlled Key (CWE-639) in the cart and wishlist repositories of MarcosCamara01 Ecommerce Template allows any authenticated user to delete and modify the cart and wishlist rows of any other user, because cartRepository.delete(), cartRepository.updateQuantityInternal() and wishlistRepository.delete() in src/lib/db/drizzle/repositories/ match rows by primary key alone, with no predicate on the owning user, and the per user authorization for those three operations rests on PostgreSQL row level security. The migrations run ALTER TABLE ... ENABLE ROW LEVEL SECURITY and create policies comparing app.current_user_id() with user_id, but never ALTER TABLE ... FORCE ROW LEVEL SECURITY, and PostgreSQL does not apply policies to the role that owns a table. The template uses one DATABASE_URL both to run the migrations, which create the tables, and for the application at runtime, so the application connects as the owner of the tables and the policies do not apply to it. cart_items.id and wishlist.id are sequential bigserial values, so the identifiers of rows belonging to other users can be enumerated, and the update path returns the modified row, which carries the identifier of the user it belongs to. This results in the destruction and modification of cart and wishlist contents belonging to other accounts of the installation.
📍 영향받는 시스템
MarcosCamara01 Ecommerce Template (Drizzle ORM 및 PostgreSQL 사용 환경)
⚔️ 공격 벡터
순차적인 ID 값을 이용한 다른 사용자의 장바구니/위시리스트 식별자 열거 및 수정/삭제 요청
🛡️ 대응 방법
PostgreSQL 마이그레이션 스크립트에 'ALTER TABLE ... FORCE ROW LEVEL SECURITY'를 추가하여 소유자에게도 정책이 적용되도록 수정하거나, 애플리케이션이 테이블 소유자가 아닌 별도의 제한된 권한을 가진 계정으로 접속하도록 변경해야 합니다.
🔧 검증 코드
명령어 실행 결과 'FORCE ROW LEVEL SECURITY'가 출력되지 않는다면 취약한 설정 상태입니다.
grep -r "ENABLE ROW LEVEL SECURITY" src/lib/db/drizzle/migrations/ && grep -r "FORCE ROW LEVEL SECURITY" src/lib/db/drizzle/migrations/