fix(lint): устранить замечания golangci-lint + переход на dockers_v2

Проход lint (52 → 0):
- vkauth/token: переименовать затенённый err (govet shadow x3)
- udprelay/loop: явный _ = conn.Close() (errcheck x2)
- captcha/manual: ReadHeaderTimeout + html.EscapeString (G112, G705)
- proxy/tcpfwd: хелпер nonNegUint64 для байтовых счётчиков io.Copy (G115)
- proxy/bondclient, wire/bondframe: bounds-проверки на len->uint16/uint32
- wire/srtpmimicry: задокументирована усечка RTP seq mod 2^16
- dnsdial/doh: bounds-проверка + binary.BigEndian.PutUint16
- captcha/slider: clamp luma до 255 перед конверсией uint8
- vkauth/types: обоснованный nolint для публичных учёток VK SDK

Новый пакет internal/randx — Intn/IntN/Float64 на crypto/rand, drop-in замена
math/rand. Мигрированы все места antifingerprint-jitter (~22) в captcha, slider,
namegen, vkauth, udprelay.

GoReleaser:
- bump GORELEASER_VERSION v2.5.0 → v2.15.4 в Taskfile и обоих CI-workflow;
  текущий синтаксис .goreleaser.yaml (archives.ids, format_overrides.formats)
  требует v2.8+
- миграция dockers + docker_manifests → dockers_v2 (единый блок, multi-platform
  buildx); Dockerfile.goreleaser использует конвенцию ARG TARGETPLATFORM
This commit is contained in:
samosvalishe committed 2026-05-23 01:37:42 +03:00
1 parent f8bc3f54e5
commit dd8233208c
20 files changed
+156 -109

No files matched your search

+2 -2
View File
@@ -11,7 +11,6 @@ import (
"errors"
"fmt"
"io"
mathrand "math/rand"
"regexp"
"strconv"
"strings"
@@ -23,6 +22,7 @@ import (
"github.com/samosvalishe/btp/internal/client/browserprofile"
"github.com/samosvalishe/btp/internal/logx"
"github.com/samosvalishe/btp/internal/randx"
)
// Log — пакетный логгер. По умолчанию no-op; main устанавливает его через
@@ -449,7 +449,7 @@ func (s *captchaSession) solveCheckboxCaptcha(
select {
case <-s.ctx.Done():
return "", s.ctx.Err()
case <-time.After(time.Duration(400+mathrand.Intn(250)) * time.Millisecond):
case <-time.After(time.Duration(400+randx.Intn(250)) * time.Millisecond):
}
check, err := s.performCaptchaCheck(sessionToken, browserFP, hash, "{}", "[]", debugInfo)
+7 -3
View File
@@ -12,6 +12,7 @@ import (
"encoding/json"
"errors"
"fmt"
"html"
"io"
"net"
"net/http"
@@ -548,7 +549,7 @@ func startCaptchaServer(srv *http.Server, logPrefix string) error {
// runCaptchaServerAndWait открывает браузер и ждёт токен решения.
// При срабатывании ctx возвращает ctx.Err(); в обоих случаях HTTP-сервер останавливается.
func runCaptchaServerAndWait(ctx context.Context, handler http.Handler, captchaURL string, keyCh <-chan string, logPrefix string) (string, error) {
srv := &http.Server{Handler: handler}
srv := &http.Server{Handler: handler, ReadHeaderTimeout: 10 * time.Second}
if err := startCaptchaServer(srv, logPrefix); err != nil {
return "", err
@@ -700,7 +701,8 @@ func SolveViaProxy(ctx context.Context, redirectURI string, dialer net.Dialer) (
Log.Errorf("[Captcha Proxy] %s %s: %v", r.Method, r.URL.String(), err)
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusBadGateway)
_, _ = fmt.Fprintf(w, `<!DOCTYPE html><html><body style="font-family:sans-serif;padding:20px"><h2>Captcha proxy error</h2><p>%s %s</p><p>%v</p></body></html>`, r.Method, r.URL.String(), err)
_, _ = fmt.Fprintf(w, `<!DOCTYPE html><html><body style="font-family:sans-serif;padding:20px"><h2>Captcha proxy error</h2><p>%s %s</p><p>%s</p></body></html>`,
html.EscapeString(r.Method), html.EscapeString(r.URL.String()), html.EscapeString(err.Error()))
},
ModifyResponse: func(res *http.Response) error {
rewriteProxyCookies(res.Header)
@@ -870,7 +872,9 @@ func SolveViaProxy(ctx context.Context, redirectURI string, dialer net.Dialer) (
func openBrowser(url string) {
for _, cmd := range browserOpenCommands(runtime.GOOS, url) {
if err := exec.Command(cmd.name, cmd.args...).Start(); err == nil { //nolint:noctx
// cmd.name/args приходят из жёстко закодированного browserOpenCommands;
// внешнего ввода в exec.Command нет (url передан внутри args как обычная строка).
if err := exec.Command(cmd.name, cmd.args...).Start(); err == nil { //nolint:noctx,gosec // hardcoded browser binary list, no taint
return
}
}
+24 -20
View File
@@ -10,12 +10,13 @@ import (
"image/color"
_ "image/jpeg" // регистрация JPEG-декодера для image.Decode
"math"
mathrand "math/rand"
"runtime"
"sort"
"strconv"
"strings"
"sync"
"github.com/samosvalishe/btp/internal/randx"
)
type sliderPuzzle struct {
@@ -509,7 +510,10 @@ func sampleLumaMapped(img image.Image, dstRect image.Rectangle, srcRect image.Re
c := sampleColorMapped(img, dstRect, srcRect, dstX, dstY)
r, g, b, _ := c.RGBA()
y := (299*(r>>8) + 587*(g>>8) + 114*(b>>8)) / 1000
return uint8(y)
if y > 255 {
y = 255
}
return uint8(y) //nolint:gosec // bounded above by 255
}
func absFloat(v float64) float64 {
@@ -565,29 +569,29 @@ func buildSliderCursor(candidateIndex int, candidateCount int) string {
Y int `json:"y"`
}
startX := 570 + mathrand.Intn(40)
startY := 875 + mathrand.Intn(30)
startX := 570 + randx.Intn(40)
startY := 875 + randx.Intn(30)
denom := candidateCount - 1
if denom < 1 {
denom = 1
}
baseTargetX := 734 + (937-734)*(candidateIndex-1)/denom
targetX := baseTargetX + mathrand.Intn(10) - 5
targetY := 655 + mathrand.Intn(14)
targetX := baseTargetX + randx.Intn(10) - 5
targetY := 655 + randx.Intn(14)
points := make([]cursorPoint, 0, 28)
for i := 0; i < 1+mathrand.Intn(3); i++ {
for i := 0; i < 1+randx.Intn(3); i++ {
points = append(points, cursorPoint{
X: startX + mathrand.Intn(5) - 2,
Y: startY + mathrand.Intn(5) - 2,
X: startX + randx.Intn(5) - 2,
Y: startY + randx.Intn(5) - 2,
})
}
transitSteps := 2 + mathrand.Intn(3)
arcOffX := mathrand.Intn(60) - 30
arcOffY := -(mathrand.Intn(30) + 10)
transitSteps := 2 + randx.Intn(3)
arcOffX := randx.Intn(60) - 30
arcOffY := -(randx.Intn(30) + 10)
for i := 1; i <= transitSteps; i++ {
t := float64(i) / float64(transitSteps+1)
cx := float64(startX+targetX)/2 + float64(arcOffX)
@@ -596,25 +600,25 @@ func buildSliderCursor(candidateIndex int, candidateCount int) string {
by := (1-t)*(1-t)*float64(startY) + 2*t*(1-t)*cy + t*t*float64(targetY)
jitter := int((1-t)*8) + 2
points = append(points, cursorPoint{
X: int(math.Round(bx)) + mathrand.Intn(jitter*2+1) - jitter,
Y: int(math.Round(by)) + mathrand.Intn(jitter*2+1) - jitter,
X: int(math.Round(bx)) + randx.Intn(jitter*2+1) - jitter,
Y: int(math.Round(by)) + randx.Intn(jitter*2+1) - jitter,
})
}
approachSteps := 4 + mathrand.Intn(4)
approachSteps := 4 + randx.Intn(4)
prev := points[len(points)-1]
for i := 1; i <= approachSteps; i++ {
t := float64(i) / float64(approachSteps)
ax := prev.X + int(math.Round(t*float64(targetX-prev.X))) + mathrand.Intn(5) - 2
ay := prev.Y + int(math.Round(t*float64(targetY-prev.Y))) + mathrand.Intn(5) - 2
ax := prev.X + int(math.Round(t*float64(targetX-prev.X))) + randx.Intn(5) - 2
ay := prev.Y + int(math.Round(t*float64(targetY-prev.Y))) + randx.Intn(5) - 2
points = append(points, cursorPoint{X: ax, Y: ay})
}
settleCount := 3 + mathrand.Intn(5)
settleCount := 3 + randx.Intn(5)
for i := 0; i < settleCount; i++ {
points = append(points, cursorPoint{
X: targetX + mathrand.Intn(7) - 3,
Y: targetY + mathrand.Intn(7) - 3,
X: targetX + randx.Intn(7) - 3,
Y: targetY + randx.Intn(7) - 3,
})
}