수뇌 국가 설정과 NPC 정책을 actor-bound ENGINE mutation으로 옮기고, 추방·등용·점령·멸망·아이템 폐기의 특수 분기를 Ref와 맞춘다. 요청 ID를 사용자·프로필별로 격리하고 토너먼트 손상 projection을 fail-closed하며 실제 DB 및 Ref 차등 회귀를 보강한다.
25 lines
837 B
TypeScript
25 lines
837 B
TypeScript
import { createHash } from 'node:crypto';
|
|
|
|
export const scopeHttpIdempotencyKey = (options: {
|
|
rawKey: string | undefined;
|
|
profileId: string;
|
|
userId: string | null;
|
|
}): string | undefined => {
|
|
const rawKey = options.rawKey?.trim();
|
|
if (!rawKey) {
|
|
return undefined;
|
|
}
|
|
// Request IDs are global in input_event. Hash the untrusted header with
|
|
// its authenticated principal and profile so equal client keys cannot
|
|
// collide across users or profiles, and oversized/punctuation-heavy
|
|
// headers never flow into DB identifiers or child command IDs.
|
|
const digest = createHash('sha256')
|
|
.update(options.profileId)
|
|
.update('\0')
|
|
.update(options.userId ?? 'anonymous')
|
|
.update('\0')
|
|
.update(rawKey)
|
|
.digest('hex');
|
|
return `http:${digest}`;
|
|
};
|