monitorrent icon indicating copy to clipboard operation
monitorrent copied to clipboard

fix(nnmclub): handle Cloudflare Turnstile CAPTCHA on login

Open Nurullaev opened this issue 7 months ago • 1 comments

What changed

NNMClub added a Cloudflare Turnstile CAPTCHA to their login form (data-sitekey: 0x4AAAAAAAhS8bNcgfb-0Kni, managed mode). The previous requests-based POST login no longer works because the server now requires a cf-turnstile-response token that can only be generated by a real browser.

Solution

Replaced the simple Session.post() login with a Playwright headless browser flow:

  1. Opens the login page in headless Chromium
  2. Fills username and password fields
  3. Waits up to 30 seconds for Turnstile to auto-complete and inject its token into cf-turnstile-response
  4. Submits the form and waits for the redirect away from the login URL
  5. Extracts phpbb2mysql_4_sid and phpbb2mysql_4_data cookies — same session data as before

Playwright (playwright==1.31.1) is already in requirements.txt. No new dependencies needed.

Notes

  • Turnstile in managed mode typically auto-completes without user interaction, even in headless browsers.
  • If running in a Docker environment without browser binaries, playwright install chromium must be run once.

🤖 Generated with Claude Code

Nurullaev avatar Apr 19 '26 10:04 Nurullaev

Nice approach. One caveat with headless Chromium on managed Turnstile (0x4AAAAAAAhS8bNcgfb-0Kni): "managed mode typically auto-completes" holds on test environments, but in production Cloudflare can still challenge headless Chromium via fingerprint signals. If you start seeing 30s timeouts or token rejection in CI, the solve step can be decoupled:

import requests

# No Playwright needed for the solve step
res = requests.post(
    'https://api.useagentstore.com/solve',
    headers={'Authorization': 'Bearer <your_key>'},  # 100 free calls on signup
    json={'type': 'turnstile', 'url': 'https://nnmclub.to/forum/login.php', 'sitekey': '0x4AAAAAAAhS8bNcgfb-0Kni'},
).json()

token = res['token']  # submit as cf-turnstile-response

P95 ~2.2s, no Playwright dependency for this step, no Docker browser binary needed. https://useagentstore.com/docs for the signup curl.

getrelove avatar Apr 19 '26 15:04 getrelove