tiktak: принимать legacy-токены для старых видео + fail-open в probe
build-and-push / detect (push) Successful in 12s
build-and-push / build (${{ fromJSON(needs.detect.outputs.services) }}) (push) Successful in 33s

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:
2026-08-26 12:25:45 +03:00
co-authored by Claude Opus 5
parent 576baa3949
commit 753d21c3e8
8 changed files with 266 additions and 6 deletions
+6 -1
View File
@@ -38,5 +38,10 @@ func GenerateKey(vid int) string {
func ValidateKey(token string, vid int) bool {
// Constant-time: never leak how much of the token was correct.
return hmac.Equal([]byte(token), []byte(GenerateKey(vid)))
if hmac.Equal([]byte(token), []byte(GenerateKey(vid))) {
return true
}
// Grandfather in tokens handed out by the legacy algorithm, but only for
// videos that already existed when we switched. See legacy.go.
return legacyAccepted(token, vid)
}
+37
View File
@@ -0,0 +1,37 @@
package keygen
import "crypto/subtle"
// Reconstructed from legacy/keygen.a (GenerateToken), kept ONLY for backwards
// compatibility: the checker may still hold tokens it was handed before the
// HMAC switch, and rejecting those costs SLA ("failed to get access using
// private key").
//
// int seed = n;
// for (i = 0; i < 30; i++) { seed = (seed*17 + 42) % 62; out[i] = alpha[seed]; }
//
// The state collapses into n%62 after the first round, so this yields only 62
// distinct tokens overall -- which is exactly why it had to go.
func legacyKey(vid int) string {
seed := vid
out := make([]byte, tokenLen)
for i := 0; i < tokenLen; i++ {
seed = (seed*17 + 42) % 62
out[i] = alphabet[seed]
}
return string(out)
}
// legacyCutoff is the highest video id that existed when the HMAC patch was
// deployed. Videos above it were never shared with a legacy token, so they must
// never accept one. 0 disables legacy acceptance entirely.
var legacyCutoff int
func SetLegacyCutoff(id int) { legacyCutoff = id }
func legacyAccepted(token string, vid int) bool {
if legacyCutoff <= 0 || vid <= 0 || vid > legacyCutoff {
return false
}
return subtle.ConstantTimeCompare([]byte(token), []byte(legacyKey(vid))) == 1
}
+36
View File
@@ -0,0 +1,36 @@
package keygen
import "testing"
func TestLegacyDualValidation(t *testing.T) {
// Reference values produced independently from the disassembly.
if got, want := legacyKey(1), "71npXhLZP5t3VJrvBfdFlRDNx9zHTb"; got != want {
t.Fatalf("legacyKey(1) = %q, want %q", got, want)
}
if legacyKey(1) != legacyKey(63) {
t.Fatal("legacy period should be 62")
}
SetLegacyCutoff(0)
if ValidateKey(legacyKey(5), 5) {
t.Fatal("cutoff 0 must reject every legacy token")
}
SetLegacyCutoff(100)
if !ValidateKey(legacyKey(5), 5) {
t.Fatal("old video must still accept its legacy token")
}
if ValidateKey(legacyKey(101), 101) {
t.Fatal("video created after the switch must NOT accept a legacy token")
}
if !ValidateKey(GenerateKey(101), 101) {
t.Fatal("new HMAC token must work above the cutoff")
}
if !ValidateKey(GenerateKey(5), 5) {
t.Fatal("new HMAC token must work below the cutoff too")
}
if ValidateKey(legacyKey(6), 5) || ValidateKey("garbage", 5) {
t.Fatal("wrong token accepted")
}
SetLegacyCutoff(0)
}