fix: устранить замечания комплексной проверки
Критичное: - go.mod: версия 1.25.5→1.25.0 (go mod tidy); Dockerfile: тег 1.25 - release.yml: go-version 1.25.5 → stable - удалён temp-файл types.go.tmp.18500.1c9f4278a15a - udprelay/loop.go: defer conn1/conn2.Close() при сбое Dial; лог write-error Безопасность/код: - browserprofile: пермиссии 0644→0600 - bondserver: once.Do перед go readLane (ordering fix) - cmd/server: err= → err:= (shadow fix в AfterFunc) - vkauth/client: vkDelayRandom ctx-aware (возвращает error) - captcha/manual: whitelist хостов в /generic_proxy (SSRF mitigation) Инфра: - .dockerignore: исключить .git/.github/notes/dist из build context - docker-compose.yml: env_file .env для OBF_KEY - entrypoint.sh: позиционные аргументы вместо unquoted vars; валидация host:port CI: - ci.yml: исправлен путь go module cache (~/go/pkg/mod); добавлен -race - .gitignore: добавлены /dist/, *.test, coverage.out, .env, *.tmp - .golangci.yml: добавлены gosec и staticcheck - routes-macos.sh: set -eu вместо set -u Код: - bondclient/bondserver: errors.Is(err, io.EOF) вместо err != io.EOF - cmd/client: константа dtlsHandshakeConcurrency для HandshakeSem Доки: - quickstart.md: добавлен Intel Mac (darwin-amd64) - build.md: версия Go, Windows/macOS cross-compile инструкции - flags.md: уточнено описание -bond
This commit is contained in:
1 parent
6fb3b69b1c
commit
8b2e028f99
21 files changed
+133
-33
No files matched your search
@@ -39,7 +39,7 @@ func Save(sp Saved) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(profileFile, data, 0644)
|
||||
return os.WriteFile(profileFile, data, 0600)
|
||||
}
|
||||
|
||||
func ApplyFhttp(req *fhttp.Request, profile Profile) {
|
||||
|
||||
@@ -65,6 +65,20 @@ func localCaptchaHosts() []string {
|
||||
}
|
||||
}
|
||||
|
||||
func isAllowedProxyHost(hostname string) bool {
|
||||
allowed := []string{
|
||||
".vk.com", ".vk.ru", ".vkontakte.ru",
|
||||
".userapi.com", ".okcdn.ru", ".mycdn.me",
|
||||
".api.vk.ru",
|
||||
}
|
||||
for _, suffix := range allowed {
|
||||
if strings.HasSuffix(hostname, suffix) || hostname == suffix[1:] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isLocalCaptchaHost(host string) bool {
|
||||
for _, localHost := range localCaptchaHosts() {
|
||||
if strings.EqualFold(host, localHost) {
|
||||
@@ -790,6 +804,10 @@ func SolveViaProxy(ctx context.Context, redirectURI string, dialer net.Dialer) (
|
||||
http.Error(w, "Bad URL", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if !isAllowedProxyHost(targetParsed.Hostname()) {
|
||||
http.Error(w, "Forbidden host", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
genericReverse := &httputil.ReverseProxy{
|
||||
Transport: transport,
|
||||
Rewrite: func(req *httputil.ProxyRequest) {
|
||||
|
||||
@@ -237,7 +237,12 @@ func (c *Client) fetch(ctx context.Context, link string, streamID int) (string,
|
||||
return "", "", nil, fmt.Errorf("all VK credentials failed: %w", lastErr)
|
||||
}
|
||||
|
||||
func vkDelayRandom(minMs, maxMs int) {
|
||||
func vkDelayRandom(ctx context.Context, minMs, maxMs int) error {
|
||||
ms := minMs + rand.Intn(maxMs-minMs+1)
|
||||
time.Sleep(time.Duration(ms) * time.Millisecond)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-time.After(time.Duration(ms) * time.Millisecond):
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,9 @@ func (c *Client) getTokenChain(ctx context.Context, link string, streamID int, c
|
||||
return "", "", nil, err
|
||||
}
|
||||
|
||||
vkDelayRandom(100, 150)
|
||||
if err := vkDelayRandom(ctx, 100, 150); err != nil {
|
||||
return "", "", nil, err
|
||||
}
|
||||
|
||||
// Шаг 1a: прогрев getCallPreview (не критично).
|
||||
previewData := fmt.Sprintf("vk_join_link=https://vk.com/call/join/%s&fields=photo_200&access_token=%s", link, token1)
|
||||
@@ -53,7 +55,9 @@ func (c *Client) getTokenChain(ctx context.Context, link string, streamID int, c
|
||||
c.log.Warnf("[STREAM %d] [VK Auth] getCallPreview failed: %v", streamID, prevErr)
|
||||
}
|
||||
|
||||
vkDelayRandom(200, 400)
|
||||
if err := vkDelayRandom(ctx, 200, 400); err != nil {
|
||||
return "", "", nil, err
|
||||
}
|
||||
|
||||
// Шаг 2: анонимный call-токен (здесь может сработать captcha).
|
||||
token2, err := c.fetchCallToken(ctx, httpClient, profile, streamID, link, escapedName, token1, creds)
|
||||
@@ -61,7 +65,9 @@ func (c *Client) getTokenChain(ctx context.Context, link string, streamID int, c
|
||||
return "", "", nil, err
|
||||
}
|
||||
|
||||
vkDelayRandom(100, 150)
|
||||
if err := vkDelayRandom(ctx, 100, 150); err != nil {
|
||||
return "", "", nil, err
|
||||
}
|
||||
|
||||
// Шаг 3: ok.ru session_key.
|
||||
sessionKey, err := c.fetchOkRuSession(ctx, httpClient, profile)
|
||||
@@ -69,7 +75,9 @@ func (c *Client) getTokenChain(ctx context.Context, link string, streamID int, c
|
||||
return "", "", nil, err
|
||||
}
|
||||
|
||||
vkDelayRandom(100, 150)
|
||||
if err := vkDelayRandom(ctx, 100, 150); err != nil {
|
||||
return "", "", nil, err
|
||||
}
|
||||
|
||||
// Шаг 4: TURN-реквизиты.
|
||||
return c.fetchTurnCreds(ctx, httpClient, profile, streamID, link, token2, sessionKey)
|
||||
|
||||
@@ -6,6 +6,7 @@ package bondclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
@@ -129,7 +130,7 @@ func (h *Handler) Handle(ctx context.Context, tcpConn net.Conn, connID uint64, c
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
default:
|
||||
if err != io.EOF {
|
||||
if !errors.Is(err, io.EOF) {
|
||||
h.Deps.log().Debugf("[bond %d] session %d read frame error: %v", connID, l.ps.ID, err)
|
||||
}
|
||||
}
|
||||
@@ -178,7 +179,7 @@ func (h *Handler) copyTCPToBond(ctx context.Context, connID uint64, tcpConn net.
|
||||
seq++
|
||||
}
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
if !errors.Is(err, io.EOF) {
|
||||
h.Deps.log().Debugf("[bond %d] local TCP read finished with error: %v", connID, err)
|
||||
}
|
||||
for _, l := range lanes {
|
||||
|
||||
@@ -151,10 +151,10 @@ func (c *serverConn) addLane(l *serverLane, laneCount uint16) {
|
||||
default:
|
||||
}
|
||||
|
||||
go c.readLane(l)
|
||||
c.once.Do(func() {
|
||||
go c.run()
|
||||
})
|
||||
go c.readLane(l)
|
||||
}
|
||||
|
||||
func (c *serverConn) snapshotLanes() []*serverLane {
|
||||
@@ -207,7 +207,7 @@ func (c *serverConn) readLane(l *serverLane) {
|
||||
select {
|
||||
case <-c.ctx.Done():
|
||||
default:
|
||||
if err != io.EOF {
|
||||
if !errors.Is(err, io.EOF) {
|
||||
c.deps.log().Debugf("[bond %d] lane %d read error: %v (lanes=%d)", c.id, l.index, err, left)
|
||||
}
|
||||
if left == 0 {
|
||||
|
||||
@@ -127,6 +127,8 @@ func oneDTLS(ctx context.Context, deps *Deps, peer *net.UDPAddr, listenConn net.
|
||||
defer dtlscancel()
|
||||
|
||||
conn1, conn2 := connutil.AsyncPacketPipe()
|
||||
defer conn1.Close()
|
||||
defer conn2.Close()
|
||||
// TURNLoop может перезапускать oneTURN несколько раз в рамках одного DTLS
|
||||
// соединения, каждый раз перечитывая conn2; публикуем до завершения DTLS.
|
||||
go func() {
|
||||
@@ -177,6 +179,7 @@ func oneDTLS(ctx context.Context, deps *Deps, peer *net.UDPAddr, listenConn net.
|
||||
_, werr := dtlsConn.Write(pkt.Data[:pkt.N])
|
||||
packetPool.Put(pkt)
|
||||
if werr != nil {
|
||||
deps.log().Debugf("[STREAM %d] DTLS write error: %v", streamID, werr)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user