Skip to content

Fix: whitelist own username in bio link detection - #52

Open
TayoBus wants to merge 1 commit into
rezhajulio:mainfrom
TayoBus:fix/bio-self-link-whitelist
Open

TayoBus wants to merge 1 commit into
rezhajulio:mainfrom
TayoBus:fix/bio-self-link-whitelist

Conversation

@TayoBus

@TayoBus TayoBus commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Problem

A user was hit by a false positive from the bio-link spam detector: their Telegram profile bio contained a link to their own profile (t.me/<their-username>), and has_suspicious_bio_links flagged it as a promo link because the function never knew whose bio it was checking.

Fix

Dynamic per-user self-whitelist in src/bot/handlers/bio_bait.py:

  • has_suspicious_bio_links(bio) now accepts an optional username parameter (the bio owner's Telegram username).
  • t.me/<own-username> / telegram.me/<own-username> links (any scheme, case-insensitive) are treated as self-references and skipped.
  • Bare @<own-username> mentions are excluded from the suspicious-mention count.
  • handle_bio_bait_spam passes user.username from the message sender through to the check.
  • The static community whitelists (WHITELISTED_TELEGRAM_PATHS, is_url_whitelisted) are untouched — the self-whitelist is dynamic per user and applies only to the bio check.

Edge cases preserved

  • Users without a username (username=None): behavior unchanged.
  • Bio with own link plus another channel link: still flagged (only self-references are skipped).
  • Private invite links (t.me/+hash): always flagged — they can never be a self-reference.
  • Single @own-username + promo hint word: no longer flagged (mention count drops to 0).

Verification

  • ruff check: clean
  • mypy src/bot/handlers/bio_bait.py: clean
  • pytest tests/test_bio_bait.py: 112 passed (10 new tests for the self-whitelist)
  • Full suite: 1309 passed

has_suspicious_bio_links now accepts the bio owner's username and treats
t.me/<own-username> links and @<own-username> mentions as self-references
instead of promo links. Fixes false positives for users whose bio links
to their own profile.
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.

1 participant