[fix] solution/backend,frontend: 메일 '고쳐서 올리려면' 링크를 일회용 코드로
주소가 500자였던 것은 곁가지고, 진짜 문제는 그 auto= 가 빌더 액세스 토큰 통짜(sub 에 UserInfo 전체 — role 포함)였다는 것이다. 메일 전달 한 번이 그날 자정까지의 권한 양도였고, 브라우저 히스토리·프록시 로그·Referer 에도 남았다. SNS 승인 흐름에서는 같은 이유로 "기존 액세스 토큰을 승인 링크에 얹지 않는다" 를 원칙으로 박아 뒀는데 이 경로에만 남아 있었다. - 0023: place_posts.edit_token_hash. 승인 토큰과 같은 규약(평문은 메일에만) - GET /v1/site/post/edit?t=<코드> → 검증 후 day-pass 를 그 자리에서 만들어 /blog?...#auto=<JWT> 로 303. ★ 프래그먼트는 서버 로그·Referer 에 안 남는다 - 프론트는 hash 에서 읽고 **주소창에서 지운다**. 쿼리도 계속 받는다 — 이미 나간 메일이 자정까지 살아 있고 그걸 깨면 그 링크들이 통째로 죽는다 - 두 코드는 서로 다른 칸에 산다. 하나로 둘 다 되면 일회성이 무의미해진다 - blog_service.app_origin() 으로 오리진 계산을 옮겼다 — 라우터도 같은 값을 쓴다 링크 길이 약 500자 → 약 75자. test_blog_owner 45 passed (신규 6건: 길이·프래그먼트·소유자·만료·없는 코드· 승인 코드 교차 사용). test_upcoming_only_returns_next_week_in_date_order 1건은 기준(stash)에서도 동일하게 실패하는 기존 건. npm run lint 통과 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
79962b93e2
commit
e35ce311d3
11 files changed
+298
-27
No files matched your search
@@ -63,6 +63,62 @@ class PostService:
|
||||
return None
|
||||
return post
|
||||
|
||||
async def open_editor(self, token: str) -> dict:
|
||||
"""메일의 '고쳐서 올리려면' — 일회용 코드를 그 자리에서 세션으로 바꾼다.
|
||||
|
||||
★ 예전에는 메일 링크에 **빌더 액세스 토큰을 통짜로** 실어 보냈다(sub 에 UserInfo
|
||||
전체 — role 포함). 주소가 500자였던 것은 곁가지고, 진짜 문제는 **메일 전달 한 번이
|
||||
그날 자정까지의 권한 양도**였다는 것이다. 브라우저 히스토리·프록시 로그·Referer 에도
|
||||
그대로 남았다. 이제 URL 에는 일회용 코드만 있고, 토큰은 여기서 만들어 **프래그먼트**로
|
||||
넘긴다 — 프래그먼트는 서버 로그와 Referer 에 남지 않는다.
|
||||
★ 실패 이유를 구분해 답하지 않는다(만료·없는 코드·이미 처리됨) — 사장님에게는
|
||||
'못 쓰는 링크' 하나다(find_by_token 과 같은 규약)."""
|
||||
from router.v1.validator.dependencies import CreateDayPassToken
|
||||
|
||||
token_hash = blog_service.hash_token(token)
|
||||
post = await DB_SESSION_MNG.execute_lambda(
|
||||
place_posts.DBType(), DBWRType.DB_READ.value,
|
||||
lambda s: self.crud.by_edit_token_hash(s, token_hash),
|
||||
)
|
||||
if not post or post.status not in (PostStatus.SENT.value, PostStatus.REVIEWED.value):
|
||||
return {"success": False}
|
||||
if post.token_expires_at and post.token_expires_at.replace(tzinfo=None) < GTime.UTC():
|
||||
return {"success": False}
|
||||
|
||||
owner = await self._owner_of(post.place_id)
|
||||
if owner is None:
|
||||
return {"success": False}
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"place_id": str(post.place_id),
|
||||
"post_id": str(post.post_id),
|
||||
"auto": CreateDayPassToken(owner),
|
||||
}
|
||||
|
||||
async def _owner_of(self, place_id) -> UserInfo | None:
|
||||
"""글이 달린 사업장의 주인. ★ 토큰이 가리키는 글에서 사람을 끌어낸다 —
|
||||
URL 에 누구인지 싣지 않기 위한 조건이다."""
|
||||
from common.database.model.models import users
|
||||
|
||||
def query(session):
|
||||
return session.execute(
|
||||
select(users)
|
||||
.join(places, places.owner_user_id == users.user_id)
|
||||
.where(
|
||||
places.place_id == place_id,
|
||||
places.deleted == False, # noqa: E712
|
||||
users.deleted == False, # noqa: E712
|
||||
)
|
||||
.limit(1)
|
||||
)
|
||||
|
||||
result = await DB_SESSION_MNG.execute_lambda(place_posts.DBType(), DBWRType.DB_READ.value, query)
|
||||
row = result.scalars().first() if result is not None else None
|
||||
if row is None:
|
||||
return None
|
||||
return UserInfo(user_id=str(row.user_id), id=row.id, role=row.role, token_version=row.token_version)
|
||||
|
||||
async def decide(self, token: str, *, skip: bool) -> dict:
|
||||
post = await self.find_by_token(token)
|
||||
if not post:
|
||||
|
||||
Reference in new issue
Block a user