tiktak: принимать legacy-токены для старых видео + fail-open в probe
MUMBLE "failed to get access using private key": чекер держит share-токен, выданный ещё старым keygen, а после перехода на HMAC ValidateKey его отвергал. - keygen/legacy.go: восстановленный из keygen.a алгоритм seed=(seed*17+42)%62 принимается ТОЛЬКО для video.id <= cutoff, то есть для видео, существовавших на момент перехода. Выше cutoff -- лишь HMAC. - cutoff берётся из max(video.id) при первом старте и пишется в public/.legacy_cutoff на volume: рестарт не должен расширять окно. Не смогли прочитать -- fail closed, legacy выключен. - Когда старые флаги протухнут: echo 0 > public/.legacy_cutoff + рестарт, и legacy отключается полностью. Ещё MUMBLE "cannot create video" -- он же DoS, у NOP-команды то же самое: - checkGeometry сделан FAIL-OPEN. Неразобранный ffprobe больше не отклоняет загрузку, режем только успешно прочитанную и абсурдную геометрию. - ffmpeg -max_alloc 128M: 1080p кадру нужно ~8 МБ, бомбе ~1 ГБ. Работает даже когда probe промолчал. check_tiktak.sh: smoke-тест для vulnbox, гоняет сценарий чекера целиком и отдельно проверяет, что патчи реально в задеплоенном билде. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -25,7 +25,11 @@ func generatePreview(ctx context.Context, inp string, out string) error {
|
||||
if err := checkGeometry(ctx, inp); err != nil {
|
||||
return err
|
||||
}
|
||||
cmd := exec.CommandContext(ctx, "ffmpeg", "-y", "-threads", "1", "-i", inp, "-vframes", "1", out)
|
||||
// -max_alloc caps a single ffmpeg allocation: a 1080p frame needs ~8 MB, a
|
||||
// 16383x16383 bomb needs ~1 GB. Second line of defence behind checkGeometry,
|
||||
// and it works even when the probe told us nothing.
|
||||
cmd := exec.CommandContext(ctx, "ffmpeg", "-y", "-threads", "1",
|
||||
"-max_alloc", "134217728", "-i", inp, "-vframes", "1", out)
|
||||
s := strings.Builder{}
|
||||
cmd.Stdout = &s
|
||||
cmd.Stderr = &s
|
||||
|
||||
@@ -20,16 +20,24 @@ func checkGeometry(ctx context.Context, inp string) error {
|
||||
args := []string{"-v", "error", "-select_streams", "v:0",
|
||||
"-show_entries", "stream=width,height", "-of", "csv=s=x:p=0", inp}
|
||||
|
||||
// FAIL-OPEN on purpose. A probe that errors out or prints something we do
|
||||
// not understand must NOT reject the upload: the checker's video would
|
||||
// start failing with "cannot create video" and that costs more than the
|
||||
// bomb does. Only a geometry we successfully read and that is absurd is
|
||||
// rejected. Bombs need a real, huge, parseable resolution to be bombs.
|
||||
out, err := exec.CommandContext(ctx, "ffprobe", args...).Output()
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot probe video: %v", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
var w, h int
|
||||
if _, err := fmt.Sscanf(strings.TrimSpace(string(out)), "%dx%d", &w, &h); err != nil {
|
||||
return fmt.Errorf("cannot read video geometry")
|
||||
return nil
|
||||
}
|
||||
if w <= 0 || h <= 0 || w > MaxDimension || h > MaxDimension || w*h > MaxPixels {
|
||||
if w <= 0 || h <= 0 {
|
||||
return nil
|
||||
}
|
||||
if w > MaxDimension || h > MaxDimension || w*h > MaxPixels {
|
||||
return fmt.Errorf("video resolution %dx%d is not supported", w, h)
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user