update vk captcha proxy

This commit is contained in:
kulikov0 committed 2026-05-29 14:08:41 +02:00
1 parent 90a506f2d1
commit dfdc494340
4 files changed
+15 -2

No files matched your search

Binary file not shown.
@@ -47,6 +47,7 @@ func StartCaptchaProxy(redirectURI string, resolveFn ResolveFunc) int {
MaxIdleConnsPerHost: 100, MaxIdleConnsPerHost: 100,
IdleConnTimeout: 90 * time.Second, IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second, TLSHandshakeTimeout: 10 * time.Second,
ForceAttemptHTTP2: false,
} }
if resolveFn != nil { if resolveFn != nil {
transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) { transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
@@ -69,6 +70,7 @@ func StartCaptchaProxy(redirectURI string, resolveFn ResolveFunc) int {
} }
req.Out.Host = targetURL.Host req.Out.Host = targetURL.Host
req.Out.Header.Del("Accept-Encoding") req.Out.Header.Del("Accept-Encoding")
req.Out.Header.Del("TE")
for _, headerName := range []string{"Origin", "Referer"} { for _, headerName := range []string{"Origin", "Referer"} {
val := req.Out.Header.Get(headerName) val := req.Out.Header.Get(headerName)
if val != "" { if val != "" {
@@ -86,16 +88,18 @@ func StartCaptchaProxy(redirectURI string, resolveFn ResolveFunc) int {
} }
contentType := res.Header.Get("Content-Type") contentType := res.Header.Get("Content-Type")
shouldInspect := strings.Contains(contentType, "text/html") || strings.Contains(res.Request.URL.Path, "captchaNotRobot.check") shouldInspect := isHTMLLike(contentType) || strings.Contains(res.Request.URL.Path, "captchaNotRobot.check")
if !shouldInspect { if !shouldInspect {
return nil return nil
} }
reader := res.Body reader := res.Body
decompressed := false
if res.Header.Get("Content-Encoding") == "gzip" { if res.Header.Get("Content-Encoding") == "gzip" {
gzReader, err := gzip.NewReader(res.Body) gzReader, err := gzip.NewReader(res.Body)
if err == nil { if err == nil {
reader = gzReader reader = gzReader
decompressed = true
defer gzReader.Close() defer gzReader.Close()
} }
} }
@@ -116,16 +120,20 @@ func StartCaptchaProxy(redirectURI string, resolveFn ResolveFunc) int {
} }
} }
if strings.Contains(contentType, "text/html") { if isHTMLLike(contentType) {
for _, h := range []string{ for _, h := range []string{
"Content-Security-Policy", "Content-Security-Policy-Report-Only", "Content-Security-Policy", "Content-Security-Policy-Report-Only",
"X-Content-Security-Policy", "X-WebKit-CSP", "X-Content-Security-Policy", "X-WebKit-CSP",
"Cross-Origin-Opener-Policy", "Cross-Origin-Embedder-Policy", "Cross-Origin-Opener-Policy", "Cross-Origin-Embedder-Policy",
"Cross-Origin-Resource-Policy", "X-Frame-Options", "Cross-Origin-Resource-Policy", "X-Frame-Options",
"Strict-Transport-Security", "Alt-Svc",
} { } {
res.Header.Del(h) res.Header.Del(h)
} }
bodyBytes = []byte(rewriteCaptchaHTML(string(bodyBytes), localOrigin, upstreamOrigin)) bodyBytes = []byte(rewriteCaptchaHTML(string(bodyBytes), localOrigin, upstreamOrigin))
}
if decompressed {
res.Header.Del("Content-Encoding") res.Header.Del("Content-Encoding")
} }
@@ -244,6 +252,11 @@ func rewriteProxyCookies(res *http.Response) {
} }
} }
func isHTMLLike(contentType string) bool {
return strings.Contains(contentType, "text/html") ||
strings.Contains(contentType, "application/xhtml+xml")
}
func extractSuccessToken(body []byte) string { func extractSuccessToken(body []byte) string {
var payload struct { var payload struct {
Response struct { Response struct {