Skip to content

fix: reduce false positives for non-ASCII (Chinese) usernames + add CSDN site - #2876

Merged
soxoj merged 4 commits into
soxoj:mainfrom
aznikline:fix/chinese-support-false-positives
Jul 17, 2026
Merged

soxoj merged 4 commits into
soxoj:mainfrom
aznikline:fix/chinese-support-false-positives

Conversation

@aznikline

Copy link
Copy Markdown
Contributor

Summary

Two changes to improve Chinese/Chinese username support in maigret:

1. False-positive fix for non-ASCII usernames (#2633)

When searching a non-ASCII (e.g. Chinese) username, many sites return a generic 200 page without any user-specific content. The existing message check type defaults is_presense_detected = True when no presenseStrs are defined, causing false CLAIMED results.

Fix: If the username contains any non-ASCII character AND the response body does not contain the username string at all, skip presence detection. This is a conservative heuristic: it only triggers when we can prove the page has no relation to the searched user.

2. Add CSDN (blog.csdn.net) — Chinese dev blog (#2634)

CSDN is the largest Chinese developer blog platform with 40M+ registered users and Alexa rank #45 in China. Added with checkType: message using the data-username=" attribute as presence marker, tagged ["cn", "coding", "blog"].

Testing

  • test_checking.py: 53/53 passed ✅
  • data.json validates cleanly (3189 sites)
  • CSDN page verified: existing user returns 200 with data-username="csdnnews", nonexistent returns 521 (WAF, handled by error detection → UNKNOWN)

Closes #2633
Addresses #2634

Closes soxoj#2665.

Every site results entry flows through make_site_result (checking.py:788),
which initializes results_site = {} and then unconditionally populates it
(site/username/keywords/parsing_enabled/url_main/cookies up front, checker
at the end, plus status or url_user+future on every branch). It has no
return path that yields an empty dict. check_site_for_username wraps that
result and likewise never returns a falsy entry, and maigret.py does not
construct site-result dicts by hand.

So the four downstream 'if not dictionary: continue' guards (all tagged
'# TODO: fix no site data issue') were dead code — the entries they
guarded against cannot occur. Removed:

  - maigret/maigret.py:101  (extract_ids_from_results)
  - maigret/report.py:151   — 'if not dictionary or dictionary.get("is_similar")'
                              trimmed to just the is_similar check (real logic)
  - maigret/report.py:467  (extended-report builder)
  - maigret/report.py:609  (generate_txt_report)
  - maigret/report.py:627  — 'if not site_result or not site_result.get("status")'
                              trimmed to just the status check (real logic)
  - maigret/report.py:687 (generate_json_report)

plus the four '# TODO: fix no site data issue' comments.

No behavior change for well-formed inputs; downstream .get() calls are
safe because entries are always populated dicts. 292 tests pass.
- soxoj#2633: When searching non-ASCII usernames, skip presence detection
  if the response body doesn't contain the username at all, preventing
  false positives on sites that return generic error pages.
- soxoj#2634: Add CSDN (blog.csdn.net) — major Chinese dev blog with
  40M+ users, alexa rank soxoj#45 in China.
@soxoj

soxoj commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Thank you so much for this PR — it's a really thoughtful contribution! Two small asks before merge: (1) CSDN needs "tls_fingerprint" added to protectioncustom_bot_protection is a documentation-only tag, only tls_fingerprint routes through curl_cffi (see checking.py:836), otherwise the default aiohttp checker gets 521 for real users too and the site returns UNKNOWN for everyone. (2) Please add one small test_checking.py case for the new non-ASCII branch (checkType message, empty presenseStrs, non-ASCII username absent from HTML → is_presense_detected stays False) so the behaviour is locked in.

…tive fix

Addresses PR soxoj#2876 review feedback from soxoj:
- Add tls_fingerprint to CSDN protection (curl_cffi required)
- Add 2 test cases for soxoj#2633 non-ASCII username false positive fix:
  - non-ASCII username not in response → no false CLAIMED
  - non-ASCII username in response → normal CLAIMED behavior
@aznikline

Copy link
Copy Markdown
Contributor Author

Addressed both review points:

  1. CSDN protection: Added tls_fingerprint alongside custom_bot_protection so curl_cffi is used (avoids 521 WAF for real users).

  2. Tests added in tests/test_checking.py:

    • test_process_site_result_message_non_ascii_username_no_match — non-ASCII (Chinese) username with response that does NOT contain the username → NOT CLAIMED ✅
    • test_process_site_result_message_non_ascii_username_with_match — non-ASCII username that DOES appear in response → normal CLAIMED ✅

All 55 tests pass (53 existing + 2 new).

@soxoj

soxoj commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Amazing, thanks! Great contribution! 🥰

@soxoj
soxoj merged commit caed0bf into soxoj:main Jul 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for Chinese names

2 participants