fix: enforce webhook response size limits via named constants

readLimitedBody already enforces 10KB body limit. Answer truncation
(2000 chars) and trash_talk truncation (200 chars) now reference
named constants from lib/constants.ts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-08 23:40:17 +00:00
co-authored by Claude Opus 4.6
parent eb4d52438d
commit d8e43d6843
+3 -3
View File
@@ -35,7 +35,7 @@ interface WebhookResponse {
error: boolean
}
import { MAX_ROUNDS, KO_THRESHOLD, MAX_RESPONSE_BYTES, STARTING_HP, ELO_K_FACTOR, ELO_K_FACTOR_MOCK } from '../lib/constants.js'
import { MAX_ROUNDS, KO_THRESHOLD, MAX_RESPONSE_BYTES, STARTING_HP, ELO_K_FACTOR, ELO_K_FACTOR_MOCK, MAX_ANSWER_LENGTH, MAX_TRASH_TALK_LENGTH } from '../lib/constants.js'
// Track bots currently in a fight to prevent concurrent fights
const activeFighters = new Set<string>()
@@ -192,8 +192,8 @@ async function callWebhook(
}
// Enforce size limits on fields
const answer = data.answer ? data.answer.slice(0, 2000) : null
const trashTalk = data.trash_talk ? data.trash_talk.slice(0, 200) : undefined
const answer = data.answer ? data.answer.slice(0, MAX_ANSWER_LENGTH) : null
const trashTalk = data.trash_talk ? data.trash_talk.slice(0, MAX_TRASH_TALK_LENGTH) : undefined
console.log(`[webhook] ${url} OK in ${elapsed}ms answer=${(answer || '').slice(0, 80)}`)
return {