Browse Source

chore: fix: resolve golangci-lint errcheck and govet/shadow warnings

pull/181/head
Moroka8 2 months ago
parent
commit
2fed5c8399
  1. 2
      client/main.go
  2. 11
      client/manual_captcha.go
  3. 26
      client/slider_captcha.go
  4. 14
      server/main.go

2
client/main.go

@ -384,7 +384,7 @@ func ParseVkCaptchaError(errData map[string]interface{}) *VkCaptchaError {
} }
// Fallback to top-level session_token field if not in redirect_uri // Fallback to top-level session_token field if not in redirect_uri
if sessionToken == "" { if sessionToken == "" {
if st, ok := errData["session_token"].(string); ok { if st, stOk := errData["session_token"].(string); stOk {
sessionToken = st sessionToken = st
} }
} }

11
client/manual_captcha.go

@ -562,7 +562,11 @@ func (t *loggingTransport) RoundTrip(req *http.Request) (*http.Response, error)
isCaptchaRequest := req.Body != nil && (strings.Contains(req.URL.Path, "captchaNotRobot.check") || strings.Contains(req.URL.Path, "captchaNotRobot.componentDone")) isCaptchaRequest := req.Body != nil && (strings.Contains(req.URL.Path, "captchaNotRobot.check") || strings.Contains(req.URL.Path, "captchaNotRobot.componentDone"))
if isCaptchaRequest { if isCaptchaRequest {
b, _ := io.ReadAll(req.Body) b, err := io.ReadAll(req.Body)
if err != nil {
log.Printf("[Captcha Proxy] Failed to read request body: %v", err)
b = nil
}
req.Body = io.NopCloser(bytes.NewReader(b)) req.Body = io.NopCloser(bytes.NewReader(b))
if isDebug { if isDebug {
@ -573,7 +577,10 @@ func (t *loggingTransport) RoundTrip(req *http.Request) (*http.Response, error)
} }
if strings.Contains(req.URL.Path, "captchaNotRobot.componentDone") || strings.Contains(req.URL.Path, "captchaNotRobot.check") { if strings.Contains(req.URL.Path, "captchaNotRobot.componentDone") || strings.Contains(req.URL.Path, "captchaNotRobot.check") {
parsedBody, _ := neturl.ParseQuery(string(b)) parsedBody, err := neturl.ParseQuery(string(b))
if err != nil {
log.Printf("[Captcha Proxy] Failed to parse request body: %v", err)
}
device := parsedBody.Get("device") device := parsedBody.Get("device")
browserFp := parsedBody.Get("browser_fp") browserFp := parsedBody.Get("browser_fp")

26
client/slider_captcha.go

@ -170,8 +170,8 @@ func (s *captchaNotRobotSession) requestComponentDone() error {
respObj, ok := resp["response"].(map[string]interface{}) respObj, ok := resp["response"].(map[string]interface{})
if ok { if ok {
if status, _ := respObj["status"].(string); status != "" && status != "OK" { if statusVal, ok := respObj["status"].(string); ok && statusVal != "" && statusVal != "OK" {
return fmt.Errorf("componentDone status: %s", status) return fmt.Errorf("componentDone status: %s", statusVal)
} }
} }
@ -294,7 +294,8 @@ func callCaptchaNotRobotWithSliderPOC(
time.Sleep(200 * time.Millisecond) time.Sleep(200 * time.Millisecond)
log.Printf("[STREAM %d] [Captcha] Step 2/4: componentDone", streamID) log.Printf("[STREAM %d] [Captcha] Step 2/4: componentDone", streamID)
if err := session.requestComponentDone(); err != nil { err = session.requestComponentDone()
if err != nil {
return "", err return "", err
} }
@ -337,7 +338,8 @@ func callCaptchaNotRobotWithSliderPOC(
// VK refuses getContent with ERROR because it expects the widget lifecycle. // VK refuses getContent with ERROR because it expects the widget lifecycle.
log.Printf("[STREAM %d] [Captcha] Re-registering slider component before getContent...", streamID) log.Printf("[STREAM %d] [Captcha] Re-registering slider component before getContent...", streamID)
time.Sleep(300 * time.Millisecond) time.Sleep(300 * time.Millisecond)
if err := session.requestComponentDone(); err != nil { err = session.requestComponentDone()
if err != nil {
// Non-fatal: log and continue — getContent may still succeed. // Non-fatal: log and continue — getContent may still succeed.
log.Printf("[STREAM %d] [Captcha] Warning: slider componentDone failed: %v", streamID, err) log.Printf("[STREAM %d] [Captcha] Warning: slider componentDone failed: %v", streamID, err)
} }
@ -401,7 +403,7 @@ func parseCaptchaSettingsResponse(resp map[string]interface{}) (*captchaSettings
settings := &captchaSettingsResponse{ settings := &captchaSettingsResponse{
SettingsByType: make(map[string]string), SettingsByType: make(map[string]string),
} }
settings.ShowCaptchaType, _ = respObj["show_captcha_type"].(string) settings.ShowCaptchaType, _ = respObj["show_captcha_type"].(string) //nolint:errcheck
rawSettings, ok := expandCaptchaSettings(respObj["captcha_settings"]) rawSettings, ok := expandCaptchaSettings(respObj["captcha_settings"])
if !ok { if !ok {
@ -414,7 +416,7 @@ func parseCaptchaSettingsResponse(resp map[string]interface{}) (*captchaSettings
continue continue
} }
captchaType, _ := item["type"].(string) captchaType, _ := item["type"].(string) //nolint:errcheck
if captchaType == "" { if captchaType == "" {
continue continue
} }
@ -580,9 +582,9 @@ func parseCaptchaCheckResult(resp map[string]interface{}) (*captchaCheckResult,
} }
result := &captchaCheckResult{} result := &captchaCheckResult{}
result.Status, _ = respObj["status"].(string) result.Status, _ = respObj["status"].(string) //nolint:errcheck
result.SuccessToken, _ = respObj["success_token"].(string) result.SuccessToken, _ = respObj["success_token"].(string) //nolint:errcheck
result.ShowCaptchaType, _ = respObj["show_captcha_type"].(string) result.ShowCaptchaType, _ = respObj["show_captcha_type"].(string) //nolint:errcheck
if result.Status == "" { if result.Status == "" {
return nil, fmt.Errorf("check status missing: %v", resp) return nil, fmt.Errorf("check status missing: %v", resp)
} }
@ -596,7 +598,7 @@ func parseSliderCaptchaContentResponse(resp map[string]interface{}) (*sliderCapt
return nil, fmt.Errorf("invalid slider content response: %v", resp) return nil, fmt.Errorf("invalid slider content response: %v", resp)
} }
status, _ := respObj["status"].(string) status, _ := respObj["status"].(string) //nolint:errcheck
if status != "OK" { if status != "OK" {
// Log all fields from the response to help diagnose why VK rejected getContent. // Log all fields from the response to help diagnose why VK rejected getContent.
var debugFields []string var debugFields []string
@ -610,13 +612,13 @@ func parseSliderCaptchaContentResponse(resp map[string]interface{}) (*sliderCapt
return nil, fmt.Errorf("slider getContent status: %s", status) return nil, fmt.Errorf("slider getContent status: %s", status)
} }
extension, _ := respObj["extension"].(string) extension, _ := respObj["extension"].(string) //nolint:errcheck
extension = strings.ToLower(extension) extension = strings.ToLower(extension)
if extension != "jpeg" && extension != "jpg" { if extension != "jpeg" && extension != "jpg" {
return nil, fmt.Errorf("unsupported slider image format: %s", extension) return nil, fmt.Errorf("unsupported slider image format: %s", extension)
} }
rawImage, _ := respObj["image"].(string) rawImage, _ := respObj["image"].(string) //nolint:errcheck
if rawImage == "" { if rawImage == "" {
return nil, fmt.Errorf("slider image missing") return nil, fmt.Errorf("slider image missing")
} }

14
server/main.go

@ -224,8 +224,8 @@ func handleVLESSConnection(ctx context.Context, dtlsConn net.Conn, connectAddr s
return return
} }
defer func() { defer func() {
if err := kcpSess.Close(); err != nil { if closeErr := kcpSess.Close(); closeErr != nil {
log.Printf("failed to close KCP session: %v", err) log.Printf("failed to close KCP session: %v", closeErr)
} }
}() }()
log.Printf("KCP session established (server)") log.Printf("KCP session established (server)")
@ -318,7 +318,11 @@ func pipeConn(ctx context.Context, c1, c2 net.Conn) {
wg.Wait() wg.Wait()
// Reset deadlines // Reset deadlines (best-effort; connection may already be closed)
_ = c1.SetDeadline(time.Time{}) if err := c1.SetDeadline(time.Time{}); err != nil {
_ = c2.SetDeadline(time.Time{}) log.Printf("pipeConn: failed to reset deadline c1: %v", err)
}
if err := c2.SetDeadline(time.Time{}); err != nil {
log.Printf("pipeConn: failed to reset deadline c2: %v", err)
}
} }

Loading…
Cancel
Save