From bd1cc614346410e46512e51776ae5ab12b0850a9 Mon Sep 17 00:00:00 2001 From: king Date: Tue, 20 Oct 2026 11:01:39 +0900 Subject: [PATCH] =?UTF-8?q?fix(cafe24):=20=EB=94=94=EC=9E=90=EC=9D=B8=20FT?= =?UTF-8?q?P=20=EC=9E=84=EC=8B=9C=20=ED=8C=8C=EC=9D=BC=EC=9D=B4=20?= =?UTF-8?q?=ED=99=95=EC=9E=A5=EC=9E=90=20=EC=A0=9C=ED=95=9C=EC=97=90=20?= =?UTF-8?q?=EA=B1=B8=EB=A0=A4=20=EC=A0=81=EC=9A=A9=20=EC=8B=A4=ED=8C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 카페24 디자인 FTP 는 허용 확장자만 받는다. 임시 이름 `product-swiper.js.cf24tmp-` 는 확장자가 바뀌어 STOR 가 `550 Operation not permitted` 로 거부돼 모바일 스와이프·PC/모바일 상품상세 적용이 모두 실패했다. 원래 확장자를 끝에 두도록 `_cf24tmp_` 로 바꾼다(원본 비킴 이름도 동일). 테스트 FTP 대역에 확장자 제한을 흉내내 회귀를 막는다. Co-Authored-By: Claude Opus 5.5 --- app/integrations/cafe24/design_ftp.py | 13 ++++++++++--- app/modules/cafe24/CLAUDE.md | 1 + app/modules/cafe24/tests/fakes.py | 11 +++++++++++ app/modules/cafe24/tests/test_cafe24.py | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/integrations/cafe24/design_ftp.py b/app/integrations/cafe24/design_ftp.py index 834f7fa..6c4ddb2 100644 --- a/app/integrations/cafe24/design_ftp.py +++ b/app/integrations/cafe24/design_ftp.py @@ -85,10 +85,17 @@ def read_text_file(config: Cafe24FtpConfig, path: str) -> str: def temp_names(path: str, tag: str) -> tuple[str, str]: - """(임시 업로드 이름, 원본을 잠시 비킬 이름) — 같은 폴더, 원본 이름 + 표식.""" + """(임시 업로드 이름, 원본을 잠시 비킬 이름) — 같은 폴더, 원본 이름 + 표식. + + ⚠️ 원래 확장자를 **맨 끝에 그대로** 둔다. 카페24 디자인 FTP 는 허용된 확장자(.js· + .html·.css 등)만 받는다 — 예전 이름 `product-swiper.js.cf24tmp-…` 는 확장자가 바뀌어 + STOR 가 `550 Operation not permitted` 로 거부됐다(실물). 그래서 + `product-swiper_cf24tmp_.js` 모양으로 만든다(점·하이픈 대신 밑줄). + """ folder, name = posixpath.split(path) - return (posixpath.join(folder, f"{name}.cf24tmp-{tag}"), - posixpath.join(folder, f"{name}.cf24old-{tag}")) + stem, ext = posixpath.splitext(name) + return (posixpath.join(folder, f"{stem}_cf24tmp_{tag}{ext}"), + posixpath.join(folder, f"{stem}_cf24old_{tag}{ext}")) def write_text_file( diff --git a/app/modules/cafe24/CLAUDE.md b/app/modules/cafe24/CLAUDE.md index 38190ce..c597d9d 100644 --- a/app/modules/cafe24/CLAUDE.md +++ b/app/modules/cafe24/CLAUDE.md @@ -21,6 +21,7 @@ - 카페24 OAuth/API 클라이언트는 향후 주문관리와 공유하기 위해 **공통 계층 `app/integrations/cafe24/`** 에 둔다 — 라우터에서 `httpx`/`requests` 직접 호출 금지. - 토큰은 Fernet 암호화 저장(`CAFE24_TOKEN_SECRET`), 로그/화면에 토큰·시크릿 절대 미출력. - 쓰기 직전 항상 카페24 현재 HTML 을 다시 읽어 `BACKUP` revision 생성(로컬 값을 현재값으로 가정 금지). +- 디자인 FTP(스와이프·상품상세) 쓰기는 임시 파일 → 검증 → rename. **카페24 FTP 는 허용 확장자만 받으므로 임시 이름도 원래 확장자로 끝나야 함**(`x_cf24tmp_.js`, `design_ftp.temp_names`). `x.js.cf24tmp-…` 는 `550 Operation not permitted`. - 예약은 DB 저장 + 별도 worker(`worker.py`, compose 서비스 `dbx-cafe24-worker`)가 처리 — 웹 프로세스에서 대기하지 않는다. ## 읽기 지연 ("마지막 쓰기가 권위") diff --git a/app/modules/cafe24/tests/fakes.py b/app/modules/cafe24/tests/fakes.py index cb25bdf..38590c4 100644 --- a/app/modules/cafe24/tests/fakes.py +++ b/app/modules/cafe24/tests/fakes.py @@ -478,10 +478,20 @@ class FakeFTP: raise ftplib.error_perm("550 No such file") callback(self.files[path]) + # 카페24 디자인 FTP 는 허용 확장자만 받는다(실물: `x.js.cf24tmp-…` STOR → 550). + ALLOWED_EXT = (".js", ".html", ".htm", ".css", ".json", ".txt", ".xml", + ".jpg", ".jpeg", ".gif", ".png", ".svg", ".webp") + + @classmethod + def _check_ext(cls, path): + if not path.lower().endswith(cls.ALLOWED_EXT): + raise ftplib.error_perm(f"550 {path}: Operation not permitted") + def storbinary(self, cmd, fp): path = cmd.split(" ", 1)[1] data = fp.read() FakeFTP.log.append(("STOR", path)) + self._check_ext(path) self.files[path] = data[: len(data) // 2] if FakeFTP.truncate_store else data def rename(self, src, dst): @@ -493,6 +503,7 @@ class FakeFTP: raise ftplib.error_perm("502 RNFR not implemented") if src not in self.files: raise ftplib.error_perm("550 No such file") + self._check_ext(dst) if dst in self.files and FakeFTP.rename_mode == "no_overwrite": raise ftplib.error_perm("553 File exists") self.files[dst] = self.files.pop(src) diff --git a/app/modules/cafe24/tests/test_cafe24.py b/app/modules/cafe24/tests/test_cafe24.py index 124f8c7..a650ddf 100644 --- a/app/modules/cafe24/tests/test_cafe24.py +++ b/app/modules/cafe24/tests/test_cafe24.py @@ -746,7 +746,7 @@ def test_design_ftp_read_and_write_roundtrip(): assert design_ftp.read_text_file(_FTP_CFG, _SWIPER) == "new content" # 원본에 직접 STOR 하지 않는다 — 임시 파일에 올린 뒤 이름 바꾸기로 교체 stors = [e for e in ftp.log if e[0] == "STOR"] - assert stors and all(".cf24tmp-" in e[1] for e in stors), ftp.log + assert stors and all("_cf24tmp_" in e[1] and e[1].endswith(".js") for e in stors), ftp.log assert any(e[0] == "RENAME" and e[2] == _SWIPER for e in ftp.log) # 임시 파일이 남지 않는다 assert set(ftp.files) == {_SWIPER}