← PHP / Laravel 목차

PHP-014 / 기초

업로드 파일의 확장자/MIME만 신뢰

A04:2021 Insecure Design · CWE-434 Unrestricted Upload of File with Dangerous Type

왜 문제가 될까요?

클라이언트가 보낸 Content-Type과 확장자는 위조 가능, .php.jpg 같은 우회도 있다.

이렇게 수정하세요

php
$request->validate(['img' => 'required|image|mimes:jpg,png|max:2048']);
$path = $request->file('img')->store('avatars', 'private'); // 랜덤 파일명, 비공개 디스크

더 읽기