Skip to content

fix: 시스템 프롬프트 CAS 업데이트의 TOCTOU race condition 해소 #99

@greenheadHQ

Description

@greenheadHQ

Summary

`POST /api/prompts/system`의 CAS(Compare-And-Swap) 패턴에 TOCTOU(Time-of-Check-to-Time-of-Use) 취약점. 코드 주석에서 인지하고 있으나 미해결.

Context

  • `getRemoteSystemPromptPayload()` (read) → revision 비교 → `setRemoteSystemPromptPayload()` (write) 사이에 동시 요청 가능
  • AnkiConnect config API가 true CAS를 지원하지 않음
  • 단일 사용자 환경이라 실질 위험은 낮지만, 동시에 두 탭에서 수정 시 데이터 유실 가능

Proposed Changes

  • 서버 사이드 in-memory mutex (또는 파일 락)로 read-check-write 구간 보호
  • 또는 SQLite에 시스템 프롬프트를 저장하고 IMMEDIATE 트랜잭션으로 true CAS 구현

Notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:serverHono API 서버 및 라우트bugSomething isn't workingpriority:low여유가 있을 때 처리할 작업

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions