Skip to content

fix(auth): harden Telegram login, webhook secret check and setup temp keys - #1101

Open
Rerowros wants to merge 3 commits into
PasarGuard:devfrom
Rerowros:fix/auth-hardening
Open

Rerowros wants to merge 3 commits into
PasarGuard:devfrom
Rerowros:fix/auth-hardening

Conversation

@Rerowros

@Rerowros Rerowros commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Telegram Mini App login now checks the age of initData (auth_date). Data older than TELEGRAM_MINIAPP_INIT_TTL_MINUTES (default 1440 = 24 h) is rejected, as Telegram recommends.
  • The Telegram webhook secret header is compared in constant time (hmac.compare_digest), and requests are refused when no webhook secret is configured.
  • The bot ACL middleware skips updates without a sender (edited_message, channel posts and similar) instead of failing on a missing from_user.
  • Setup temp keys can be bound to one owner action: generate-temp-key --action create_owner|reset_owner|delete_owner|upgrade_owner. A bound key is accepted only by that action. Keys created without --action work as before.
  • Add an index on passkey_challenges.expires_at, which is used by the cleanup of expired challenges on every passkey options request.

Behavior change / upgrade notes

  • Mini App sessions opened with initData older than 24 hours get 403 and must be reopened from Telegram. Set TELEGRAM_MINIAPP_INIT_TTL_MINUTES to change the window; 0 turns the check off.
  • If the webhook secret is empty, webhook calls are now refused instead of being compared with an empty value.
  • generate-temp-key gets an optional --action / -a option. Without it, keys behave as before (usable for any setup action), so existing scripts keep working.
  • New migration d3f1a2b4c5e6 (index only, no data changes). It is based on the current dev head c8d2e4f6a1b3. PR fix(subscription): preserve token revocation timestamp precision #758 also adds a migration (9e0d7a1c4b52) on top of the same head: whichever of the two is merged second must change its down_revision to the other one, otherwise Alembic ends up with two heads.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Refactor
  • Documentation
  • Tests
  • CI

Tests

  • test_miniapp_rejects_stale_init_data - initData older than the TTL gets 403.
  • test_miniapp_accepts_fresh_init_data - fresh initData still logs in.
  • test_webhook_rejects_missing_or_wrong_secret - empty configured secret, missing or wrong header are refused.
  • test_webhook_accepts_the_configured_secret - the right secret is accepted.
  • test_acl_skips_updates_without_a_sender - an edited_message update and a message without from_user are skipped without an error.
  • test_bound_key_is_not_consumed_by_another_action - a key bound to one action fails for another and stays unused.
  • test_bound_key_is_consumed_by_its_own_action - a bound key works for its action.
  • test_unbound_key_is_consumed_by_any_action - keys without a binding keep the old behavior.
  • test_mark_temp_key_used_respects_the_binding - marking a key used follows the same rule.
  • test_unknown_used_and_expired_keys_keep_their_errors - existing error messages are unchanged.
  • tests/api/test_setup.py - updated for the unbound key value pending; 22 passed.

Run: pytest tests/test_miniapp_init_data_ttl.py tests/test_telegram_webhook_and_acl.py tests/test_temp_key_binding.py - 14 passed; pytest tests/api/test_setup.py - 22 passed.

Migration check

  • Ran alembic upgrade head from an empty database, downgrade -1 and upgrade head again on MySQL 8.4, MariaDB 11 and PostgreSQL 17: the ix_passkey_challenges_expires_at index is created, dropped and created again; alembic check is clean; single head.
  • cli/README.md documents the new --action option.

Checklist

  • I tested my changes locally
  • I added or updated tests where needed
  • I updated documentation, translations, or examples if needed
  • I checked database migrations when models or schema changed
  • I did not include secrets, tokens, private keys, or unrelated changes

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 68226e21-618d-40cc-b88d-5ab83dd6c6a5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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