fix(core): 레이아웃 첨부 URL 이 항상 프록시로 발급되던 결함 수정
공개 자산 스토리지를 설정해도 레이아웃 배경 이미지가 매번 오리진 PHP 를 거쳐 서빙되던 결함을 고친다 (https://github.com/gnuboard/g7/issues/134). 판정 기준은 운영자가 명시 선언한 core.storage.public_asset_disk 와 행 disk 의 일치다 — 디스크의 url 설정 유무로 판정하면 비공개 버킷에 공개 URL 이 설정된 구성에서 발급된 주소가 403 이 되어 그 이미지가 전부 깨진다. 전수조사에서 함께 처리한 것: 게시판 첨부 응답 url 칸(항상 null → 게이트가 살아 있는 서빙 URL), 페이지의 미배선 메서드 삭제, 확장 카테고리별 저장소 URL·경로 조회 교정, 그리고 이번 변경이 새로 만드는 고아 disk 위험 방어 (무인증 공개 서빙 라우트가 500 이 되는 것을 404 로 degrade). 문서화 하네스도 함께 보강한다. 실측을 수행하고도 이력 문서에는 판정만 남기면 대화 로그가 사라진 뒤 아무에게도 도달하지 않는데, 그 강제가 보고 형식에만 있었다.
This commit is contained in:
1 parent
e160a86f0d
commit
5c2e42c133
42 files changed
+1427
-83
No files matched your search
@@ -8,6 +8,7 @@ use App\Contracts\Repositories\TemplateRepositoryInterface;
|
||||
use App\Extension\HookManager;
|
||||
use App\Models\TemplateLayoutAttachment;
|
||||
use App\Support\ImageResizer;
|
||||
use App\Support\PublicAssetDisk;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -64,7 +65,10 @@ class TemplateLayoutAttachmentService
|
||||
$storedFilename = Str::uuid().'.'.$file->getClientOriginalExtension();
|
||||
$relativePath = "{$templateIdentifier}/".date('Y/m/d')."/{$storedFilename}";
|
||||
|
||||
$disk = config('attachment.disk', 'attachments');
|
||||
// 운영자가 공개 자산 디스크를 선언했으면 그쪽에 저장한다 (방문자 요청이 CDN 을 탄다).
|
||||
// 미선언이면 기존 첨부 디스크 그대로. 행이 자기 disk 를 기록하므로 나중에 설정이
|
||||
// 바뀌어도 각 행은 자기 저장 위치를 기억한다.
|
||||
$disk = PublicAssetDisk::resolve() ?? config('attachment.disk', 'attachments');
|
||||
|
||||
// 환경설정 > 업로드의 최대 가로/세로·품질 적용 (코어 설정이 모든 업로드 경로에 동일 적용).
|
||||
// 임시 파일을 제자리에서 줄이므로 아래의 저장·크기 기록이 모두 축소본을 본다.
|
||||
@@ -138,8 +142,7 @@ class TemplateLayoutAttachmentService
|
||||
public function delete(TemplateLayoutAttachment $attachment): bool
|
||||
{
|
||||
// 1. 스토리지 파일 실삭제 (명시적 — CASCADE 미의존)
|
||||
$this->storage
|
||||
->withDisk($attachment->disk)
|
||||
$this->storageForRow($attachment->disk)
|
||||
->delete(self::STORAGE_CATEGORY, $attachment->path);
|
||||
|
||||
// 2. DB 행 삭제
|
||||
@@ -149,16 +152,48 @@ class TemplateLayoutAttachmentService
|
||||
/**
|
||||
* 첨부 파일의 공개 접근 URL을 생성합니다.
|
||||
*
|
||||
* 첨부 파일은 비공개 `attachments` 디스크에 저장되어 직접 공개 URL 이 없다
|
||||
* (`StorageInterface::url()` 은 public 디스크 전용). 발행된 배경 이미지는 일반
|
||||
* 사이트 방문자에게도 로드되어야 하므로, 인증 불필요한 공개 서빙 라우트
|
||||
* (`PublicTemplateController::serveFile`)의 URL 을 돌려준다. 라우트는 첨부 id 로
|
||||
* 키되며 서빙 시 첨부가 해당 템플릿 소속인지 검증한다.
|
||||
* 운영자가 공개 자산 디스크(`core.storage.public_asset_disk`)를 선언했고 행 disk 가
|
||||
* 그 값과 일치할 때만 직접 URL(CDN)을 돌려준다. 그 외에는 인증 불필요한 공개 서빙
|
||||
* 라우트(`PublicTemplateController::serveFile`)의 URL 을 돌려주며, 라우트는 첨부 id 로
|
||||
* 키되고 서빙 시 첨부가 해당 템플릿 소속인지 검증한다.
|
||||
*
|
||||
* 디스크의 `url` 설정 유무로 판정하지 않는다 — 그 설정은 "URL 문자열을 만들 수
|
||||
* 있는가" 일 뿐 "익명 읽기가 되는가" 가 아니어서, 비공개 버킷에 공개 URL 이
|
||||
* 설정된 조합에서는 발급된 직접 URL 이 403 이 된다.
|
||||
*
|
||||
* @param TemplateLayoutAttachment $attachment 첨부 파일
|
||||
* @return string 직접 URL 또는 공개 서빙 URL
|
||||
*/
|
||||
public function resolveUrl(TemplateLayoutAttachment $attachment): string
|
||||
{
|
||||
return $this->resolveDirectUrl($attachment) ?? $this->proxyUrl($attachment);
|
||||
}
|
||||
|
||||
/**
|
||||
* 행 disk 가 공개 자산 디스크일 때만 직접 URL 해석을 시도합니다.
|
||||
*
|
||||
* @param TemplateLayoutAttachment $attachment 첨부 파일
|
||||
* @return string|null 직접 URL (대상이 아니거나 훅이 차단하면 null)
|
||||
*/
|
||||
private function resolveDirectUrl(TemplateLayoutAttachment $attachment): ?string
|
||||
{
|
||||
if (! PublicAssetDisk::isCurrent($attachment->disk)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 게이트를 통과한 disk 는 PublicAssetDisk::resolve() 가 존재를 이미 확인했다.
|
||||
return $this->storage
|
||||
->withDisk($attachment->disk)
|
||||
->url(self::STORAGE_CATEGORY, $attachment->path);
|
||||
}
|
||||
|
||||
/**
|
||||
* 공개 서빙 라우트(프록시) URL 을 생성합니다.
|
||||
*
|
||||
* @param TemplateLayoutAttachment $attachment 첨부 파일
|
||||
* @return string 공개 서빙 URL
|
||||
*/
|
||||
public function resolveUrl(TemplateLayoutAttachment $attachment): string
|
||||
private function proxyUrl(TemplateLayoutAttachment $attachment): string
|
||||
{
|
||||
$template = $attachment->template;
|
||||
$identifier = $template?->identifier ?? (string) $attachment->template_id;
|
||||
@@ -169,6 +204,26 @@ class TemplateLayoutAttachmentService
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 행에 기록된 disk 기준 스토리지를 반환합니다 (고아 disk 방어).
|
||||
*
|
||||
* 공개 자산 디스크는 플러그인이 등록한 디스크일 수 있고, 그 플러그인이 비활성화되면
|
||||
* 해당 disk 가 config 에서 사라진다. 미등록 disk 로 withDisk 를 만들면 이후
|
||||
* response/delete 가 InvalidArgumentException 을 던져 **무인증 공개 서빙 라우트가
|
||||
* 500** 이 되므로, 주입 스토리지로 폴백해 404 로 끝나게 한다.
|
||||
*
|
||||
* @param string|null $disk 행의 disk 컬럼 값
|
||||
* @return StorageInterface 행 disk 의 스토리지 (고아면 주입 스토리지)
|
||||
*/
|
||||
private function storageForRow(?string $disk): StorageInterface
|
||||
{
|
||||
if ($disk === null || $disk === '' || config("filesystems.disks.{$disk}") === null) {
|
||||
return $this->storage;
|
||||
}
|
||||
|
||||
return $this->storage->withDisk($disk);
|
||||
}
|
||||
|
||||
/**
|
||||
* 서빙 가능한 첨부의 인라인 스트림 응답과 캐싱 메타를 돌려줍니다.
|
||||
*
|
||||
@@ -190,7 +245,7 @@ class TemplateLayoutAttachmentService
|
||||
|
||||
// 행 disk 기준 인라인 스트림 (존재 검사는 response() 내부에서 수행).
|
||||
// 로컬 절대 경로 조립(getBasePath)은 S3 등 원격 디스크 행에서 성립하지 않는다 (#99).
|
||||
$response = $this->storage->withDisk($attachment->disk)->response(
|
||||
$response = $this->storageForRow($attachment->disk)->response(
|
||||
self::STORAGE_CATEGORY,
|
||||
$attachment->path,
|
||||
$attachment->original_name ?? basename($attachment->path),
|
||||
|
||||
Reference in new issue
Block a user