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:
+37
-1
@@ -6,10 +6,14 @@ import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/gocraft/dbr/v2"
|
||||
"github.com/thanhpk/randstr"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"strings"
|
||||
"tiktak/db"
|
||||
"tiktak/keygen"
|
||||
"tiktak/server"
|
||||
"tiktak/server/auth"
|
||||
"tiktak/video"
|
||||
@@ -29,13 +33,21 @@ func main() {
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
storage := db.New(conn)
|
||||
|
||||
auth.SetSalt(randstr.Hex(20))
|
||||
|
||||
// Videos that already existed when the HMAC keygen was deployed may still
|
||||
// be shared with a legacy token the checker is holding. Freeze that cutoff
|
||||
// on first boot and persist it, so a container restart cannot widen the
|
||||
// window (a wider window means more videos accepting forgeable tokens).
|
||||
keygen.SetLegacyCutoff(legacyCutoff(storage))
|
||||
config := server.Config{
|
||||
StaticFolder: "public/static",
|
||||
VttFolder: "public/vtt",
|
||||
TemplatesFolder: "templates",
|
||||
}
|
||||
srv := server.NewServer(db.New(conn), &video.Storage{Directory: "public/video"}, config)
|
||||
srv := server.NewServer(storage, &video.Storage{Directory: "public/video"}, config)
|
||||
|
||||
// Start server
|
||||
go func() {
|
||||
@@ -54,3 +66,27 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// legacyCutoffFile lives on the ./public volume so it survives restarts.
|
||||
const legacyCutoffFile = "public/.legacy_cutoff"
|
||||
|
||||
func legacyCutoff(storage *db.Storage) int {
|
||||
if b, err := ioutil.ReadFile(legacyCutoffFile); err == nil {
|
||||
if n, err := strconv.Atoi(strings.TrimSpace(string(b))); err == nil {
|
||||
fmt.Println("legacy token cutoff (pinned):", n)
|
||||
return n
|
||||
}
|
||||
}
|
||||
|
||||
id, err := storage.MaxVideoID(context.Background())
|
||||
if err != nil {
|
||||
// Fail closed: no legacy tokens rather than an unbounded window.
|
||||
fmt.Println("cannot read max video id, legacy tokens disabled:", err)
|
||||
return 0
|
||||
}
|
||||
if err := ioutil.WriteFile(legacyCutoffFile, []byte(strconv.FormatInt(id, 10)), 0644); err != nil {
|
||||
fmt.Println("cannot pin legacy cutoff:", err)
|
||||
}
|
||||
fmt.Println("legacy token cutoff (fresh):", id)
|
||||
return int(id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user