봇 중계: 연결한 뒤 권한을 잃으면 음성 연결을 끊는다

- 음성 연결을 가진 앱과 그 채널을 기록하고, 다시 확인해서 그 유저가 더는 들어갈 수 없으면
  음성 접속 정보 전달을 멈추고, 봇을 빼고(op 4 null), 앱에 taken 을 보낸다 (revoke)
- 다시 확인하는 때: 탈퇴 · 추방 · 역할 · 채널 권한 변경 이벤트(BotSource 'access', discord.js GuildMemberRemove/Update ·
  ChannelUpdate/Delete · GuildRoleUpdate/Delete · GuildDelete), vserver/vstate 를 넘기기 직전(봇이 옮겨진 채널 기준), 30초 주기
- 서버 멤버가 아니게 되면 지켜보기도 watch_denied 로 끊는다
- 테스트 (site/server/test/bot-broker.test.ts): 허용 → 연결 → 회수(탈퇴 · 채널 권한 제거 · 이벤트 없이 바뀜 · 권한 없는 채널로 옮겨짐)
  → 전달 차단 · 봇 퇴장 · 알림. 고치기 전 코드에서는 4건 모두 실패

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-15 11:34:45 +09:00
parent 6721db23ac
commit 1429f74074
5 changed files with 261 additions and 17 deletions

View File

@@ -16,7 +16,7 @@ const SID = 'gvr_sid';
const RECHECK_MS = 10 * 60000;
/** botSource: 겜녹이 봇 디스코드 연결 (main.ts 가 discord.js 로 만든다. 없으면 /app/bot/ws 는 503) */
export async function buildServer(cfg: Config, opts: { botSource?: BotSource } = {}) {
export async function buildServer(cfg: Config, opts: { botSource?: BotSource; botRecheckMs?: number } = {}) {
const app = Fastify({
logger: {
level: process.env.LOG_LEVEL || 'info',
@@ -34,7 +34,7 @@ export async function buildServer(cfg: Config, opts: { botSource?: BotSource } =
const secure = cfg.publicUrl.startsWith('https://');
let broker: BotBroker | null = null;
const appAuth = registerAppAuth(app, { cfg, store, discord, secure, onRevoke: (by) => broker?.kick(by) });
if (opts.botSource) broker = new BotBroker(opts.botSource, appAuth.verifyToken, app.log);
if (opts.botSource) broker = new BotBroker(opts.botSource, appAuth.verifyToken, app.log, opts.botRecheckMs);
// 보안 헤더. HSTS · X-Frame-Options · Referrer-Policy 는 앞단 프록시(NPMplus)가 붙인다 (http → https 이동도 프록시)
// CSP: 이 사이트의 스크립트만 실행, 접속은 이 사이트로만 (XSS 가 생겨도 기록을 바깥으로 보내지 못하게)