Added sleep timers because cookie snatcher is solving POW and trying to log in too fast.
This commit is contained in:
@@ -291,11 +291,18 @@ func NewCookieRefreshService(username, password, domain string) (*CookieRefreshS
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add User-Agent to mimic browser
|
||||||
|
transport := &http.Transport{}
|
||||||
|
|
||||||
return &CookieRefreshService{
|
return &CookieRefreshService{
|
||||||
username: username,
|
username: username,
|
||||||
password: password,
|
password: password,
|
||||||
domain: domain,
|
domain: domain,
|
||||||
client: &http.Client{Jar: jar, Timeout: 30 * time.Second},
|
client: &http.Client{
|
||||||
|
Jar: jar,
|
||||||
|
Timeout: 30 * time.Second,
|
||||||
|
Transport: transport,
|
||||||
|
},
|
||||||
cookieReady: make(chan struct{}),
|
cookieReady: make(chan struct{}),
|
||||||
stopChan: make(chan struct{}),
|
stopChan: make(chan struct{}),
|
||||||
}, nil
|
}, nil
|
||||||
@@ -473,7 +480,8 @@ func (crs *CookieRefreshService) attemptFetchCookie() (string, error) {
|
|||||||
}
|
}
|
||||||
if clearanceToken != "" {
|
if clearanceToken != "" {
|
||||||
log.Println("✅ KiwiFlare challenge solved")
|
log.Println("✅ KiwiFlare challenge solved")
|
||||||
time.Sleep(1 * time.Second) // allow propagation
|
log.Println("⏳ Waiting 2 seconds for cookie propagation...")
|
||||||
|
time.Sleep(2 * time.Second) // Increased from 1s to 2s
|
||||||
}
|
}
|
||||||
|
|
||||||
// Force a new TLS session to avoid stale keep-alive
|
// Force a new TLS session to avoid stale keep-alive
|
||||||
@@ -485,6 +493,7 @@ func (crs *CookieRefreshService) attemptFetchCookie() (string, error) {
|
|||||||
req, _ := http.NewRequest("GET", loginURL, nil)
|
req, _ := http.NewRequest("GET", loginURL, nil)
|
||||||
req.Header.Set("Cache-Control", "no-cache")
|
req.Header.Set("Cache-Control", "no-cache")
|
||||||
req.Header.Set("Pragma", "no-cache")
|
req.Header.Set("Pragma", "no-cache")
|
||||||
|
req.Header.Set("User-Agent", "Sneedchat-Discord-Go-Bridge")
|
||||||
req.URL.RawQuery = fmt.Sprintf("r=%d", rand.Intn(999999))
|
req.URL.RawQuery = fmt.Sprintf("r=%d", rand.Intn(999999))
|
||||||
|
|
||||||
resp, err := crs.client.Do(req)
|
resp, err := crs.client.Do(req)
|
||||||
@@ -500,6 +509,10 @@ func (crs *CookieRefreshService) attemptFetchCookie() (string, error) {
|
|||||||
body, _ := io.ReadAll(resp.Body)
|
body, _ := io.ReadAll(resp.Body)
|
||||||
bodyStr := string(body)
|
bodyStr := string(body)
|
||||||
|
|
||||||
|
// Small delay after getting login page
|
||||||
|
log.Println("⏳ Waiting 1 second before processing login page...")
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
// Step 3: Extract CSRF token
|
// Step 3: Extract CSRF token
|
||||||
log.Println("Step 3: Extracting CSRF token...")
|
log.Println("Step 3: Extracting CSRF token...")
|
||||||
var csrfToken string
|
var csrfToken string
|
||||||
@@ -532,11 +545,26 @@ func (crs *CookieRefreshService) attemptFetchCookie() (string, error) {
|
|||||||
"remember": {"1"},
|
"remember": {"1"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Debug: Show cookies being sent
|
||||||
|
debugCookieURL, _ := url.Parse(fmt.Sprintf("https://%s/", crs.domain))
|
||||||
|
currentCookies := crs.client.Jar.Cookies(debugCookieURL)
|
||||||
|
log.Printf("Cookies before login POST (%d):", len(currentCookies))
|
||||||
|
for _, c := range currentCookies {
|
||||||
|
log.Printf(" - %s = %s...", c.Name, c.Value[:min(10, len(c.Value))])
|
||||||
|
}
|
||||||
|
|
||||||
crs.client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
|
crs.client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
|
||||||
return http.ErrUseLastResponse
|
return http.ErrUseLastResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
loginResp, err := crs.client.PostForm(postURL, formData)
|
// Create POST request manually to add User-Agent
|
||||||
|
postReq, _ := http.NewRequest("POST", postURL, strings.NewReader(formData.Encode()))
|
||||||
|
postReq.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
postReq.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36")
|
||||||
|
postReq.Header.Set("Referer", loginURL)
|
||||||
|
postReq.Header.Set("Origin", fmt.Sprintf("https://%s", crs.domain))
|
||||||
|
|
||||||
|
loginResp, err := crs.client.Do(postReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("login POST failed: %w", err)
|
return "", fmt.Errorf("login POST failed: %w", err)
|
||||||
}
|
}
|
||||||
@@ -544,6 +572,21 @@ func (crs *CookieRefreshService) attemptFetchCookie() (string, error) {
|
|||||||
|
|
||||||
log.Printf("Login response status: %d", loginResp.StatusCode)
|
log.Printf("Login response status: %d", loginResp.StatusCode)
|
||||||
|
|
||||||
|
// Debug: Check if we got Set-Cookie headers
|
||||||
|
setCookies := loginResp.Header.Values("Set-Cookie")
|
||||||
|
if len(setCookies) > 0 {
|
||||||
|
log.Printf("Set-Cookie headers received: %d", len(setCookies))
|
||||||
|
for _, sc := range setCookies {
|
||||||
|
log.Printf(" - %s", sc[:min(80, len(sc))])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Println("⚠️ No Set-Cookie headers in login response!")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delay before checking cookies
|
||||||
|
log.Println("⏳ Waiting 1 second for login to process...")
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
// Step 5: Extract cookies
|
// Step 5: Extract cookies
|
||||||
log.Println("Step 5: Extracting authentication cookies...")
|
log.Println("Step 5: Extracting authentication cookies...")
|
||||||
cookieURL, _ := url.Parse(fmt.Sprintf("https://%s/", crs.domain))
|
cookieURL, _ := url.Parse(fmt.Sprintf("https://%s/", crs.domain))
|
||||||
@@ -572,9 +615,17 @@ func (crs *CookieRefreshService) attemptFetchCookie() (string, error) {
|
|||||||
if !hasXfUser && loginResp.StatusCode >= 300 && loginResp.StatusCode < 400 {
|
if !hasXfUser && loginResp.StatusCode >= 300 && loginResp.StatusCode < 400 {
|
||||||
if loc := loginResp.Header.Get("Location"); loc != "" {
|
if loc := loginResp.Header.Get("Location"); loc != "" {
|
||||||
log.Printf("Following redirect to %s to check for xf_user...", loc)
|
log.Printf("Following redirect to %s to check for xf_user...", loc)
|
||||||
followResp, err := crs.client.Get(fmt.Sprintf("https://%s%s", crs.domain, loc))
|
time.Sleep(1 * time.Second) // Wait before following redirect
|
||||||
|
|
||||||
|
followURL := loc
|
||||||
|
if !strings.HasPrefix(loc, "http") {
|
||||||
|
followURL = fmt.Sprintf("https://%s%s", crs.domain, loc)
|
||||||
|
}
|
||||||
|
|
||||||
|
followResp, err := crs.client.Get(followURL)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
followResp.Body.Close()
|
followResp.Body.Close()
|
||||||
|
time.Sleep(1 * time.Second) // Wait after redirect
|
||||||
cookies = crs.client.Jar.Cookies(cookieURL)
|
cookies = crs.client.Jar.Cookies(cookieURL)
|
||||||
cookieStrs = []string{} // Reset
|
cookieStrs = []string{} // Reset
|
||||||
for _, c := range cookies {
|
for _, c := range cookies {
|
||||||
|
|||||||
Reference in New Issue
Block a user