Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

2Fa Trusted Device Laravel Package

scheb/2fa-trusted-device

Adds trusted device support to scheb/2fa so users can skip 2FA on recognized devices for a set time. Stores trust tokens in cookies and persistence, with configurable lifetimes and validation, improving UX without removing 2FA security.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Core Use Case Alignment: The scheb/2fa-trusted-device package extends the scheb/2fa-bundle by adding trusted device management (e.g., auto-login for recognized devices, device whitelisting). This aligns well with security-sensitive Laravel applications (e.g., SaaS platforms, financial apps, or admin dashboards) where 2FA is mandatory but UX friction must be balanced.
  • Modularity: Since it’s a bundle extension, it integrates cleanly into existing Laravel auth flows (e.g., scheb/2fa-bundle for TOTP/HOTP). Minimal architectural disruption if the base 2FA system is already in place.
  • Separation of Concerns: Trusted device logic is isolated from core auth, reducing risk of bleeding into other systems (e.g., OAuth, SSO).

Integration Feasibility

  • Dependencies:
    • Hard Dependency: Requires scheb/2fa-bundle (v5+ recommended). If not already used, this adds ~10–15 hours of setup (TOTP/HOTP integration, config, middleware).
    • Soft Dependencies: Works with Laravel’s native auth system but may need adjustments for custom guard implementations (e.g., API tokens).
  • Database Schema: Adds tables for trusted_devices (device fingerprint, user association, expiry). Migration-friendly if using Laravel’s schema builder.
  • Configuration Overhead: Minimal (e.g., trusted_device_lifetime, ip_whitelist). Can be environment-agnostic (e.g., .env overrides).

Technical Risk

Risk Area Severity Mitigation Strategy
2FA Bundle Version Mismatch High Pin scheb/2fa-bundle to a stable version (e.g., ^5.0). Test against Laravel 10+ early.
Device Fingerprinting Collisions Medium Validate fingerprint uniqueness in tests. Use hash() for storage.
Session Hijacking Medium Combine with laravel-session middleware to invalidate sessions on device changes.
Performance Impact Low Device checks are O(1) (DB index on user_id). Cache TrustedDevice model if high traffic.

Key Questions

  1. Does the app already use scheb/2fa-bundle?
    • If no, assess whether trusted devices justify the additional 2FA complexity (e.g., backup codes, recovery flows).
  2. What’s the device fingerprinting strategy?
    • Default uses user_agent + IP. For mobile apps, may need custom fingerprinting (e.g., device ID).
  3. How are sessions managed?
    • Ensure trusted device logic doesn’t conflict with existing session drivers (e.g., Redis vs. database).
  4. Compliance Requirements:
    • Does the app need audit logs for trusted device additions/removals? The package lacks built-in logging.
  5. Multi-Tenant Support:
    • If using Laravel’s tenancy, verify the package’s user_id scoping works across tenants.

Integration Approach

Stack Fit

  • Laravel Version: Tested on Laravel 8–10. Use laravel/framework:^10.0 for compatibility.
  • PHP Version: Requires PHP 8.0+ (for named arguments, attributes).
  • Auth Stack:
    • Native Laravel Auth: Works out-of-the-box with web guard.
    • API Auth: May need custom middleware to bypass 2FA for trusted devices in api guard.
    • Third-Party Auth: If using Sanctum/Passport, ensure trusted device checks precede token validation.
  • Database: Supports MySQL, PostgreSQL, SQLite. No ORM-specific logic (uses Eloquent).

Migration Path

  1. Phase 1: Pre-requisite Setup (2–3 days)
    • Install scheb/2fa-bundle and configure TOTP/HOTP.
    • Set up backup codes and recovery flows (critical for user trust).
  2. Phase 2: Trusted Device Integration (1–2 days)
    • Publish and configure the package (php artisan vendor:publish --tag=2fa-trusted-device-config).
    • Run migrations (php artisan migrate).
    • Add middleware to check trusted devices before 2FA prompts (e.g., in HandleIncomingInertiaRequests for Inertia.js apps).
  3. Phase 3: Testing (2–3 days)
    • Unit Tests: Mock TrustedDevice model for fingerprint validation.
    • E2E Tests: Verify trusted device flow (e.g., auto-login on return visit, manual addition/removal).
    • Edge Cases: Test with VPNs/proxies (IP changes), incognito modes (user-agent changes).

Compatibility

  • With Existing Packages:
    • Laravel Fortify: May conflict with Fortify’s 2FA logic. Use conditional middleware.
    • Spatie Laravel-Permission: No conflicts, but ensure TrustedDevice checks run before permission gates.
  • Custom Auth: If using Breeze/Sanctum, override the login controller to integrate trusted device checks.
  • Caching: If using Redis, ensure TrustedDevice model uses cache tags to invalidate on device changes.

Sequencing

  1. Low-Risk First:
    • Start with read-only trusted device checks (no auto-login).
    • Gradually enable auto-login after validating fingerprint stability.
  2. Feature Flags:
    • Use Laravel’s config or Envoyer flags to toggle trusted device logic in staging.
  3. Rollout Strategy:
    • Pilot Group: Enable for admin users first (monitor false positives).
    • User Education: Add a tooltip explaining trusted devices to avoid support tickets.

Operational Impact

Maintenance

  • Package Updates:
    • Monitor scheb/2fa-bundle for breaking changes (e.g., v6.0+ may drop PHP 8.0 support).
    • Upgrade Path: Test updates in a staging environment with pest/phpunit suites.
  • Custom Logic:
    • Extend TrustedDevice model if additional fields are needed (e.g., device_name, last_seen_at).
    • Override TrustedDeviceService for custom fingerprinting (e.g., include Accept-Language header).

Support

  • Common Issues:
    • False Positives: Users locked out due to IP/user-agent changes (e.g., mobile data → Wi-Fi).
      • Solution: Add a "This isn’t me" link to trigger manual review.
    • Device Removal: Users unable to remove trusted devices.
      • Solution: Add a manual cleanup cron job for stale devices.
  • Documentation Gaps:
    • The package lacks troubleshooting guides for:
      • Debugging fingerprint collisions.
      • Configuring multi-factor prompts for trusted devices.
    • Mitigation: Create an internal runbook with SQL queries for auditing.

Scaling

  • Performance:
    • Trusted Device Lookup: O(1) with indexed user_id. No scaling issues expected.
    • High Traffic: Cache TrustedDevice queries in Redis (e.g., Cache::remember).
  • Database:
    • Table Growth: trusted_devices table may grow with user base. Archive old devices via partitioning (e.g., by created_at).
  • Global Apps:
    • IP Whitelisting: May not work for users behind CGNAT (e.g., mobile carriers). Use device fingerprinting only.

Failure Modes

Scenario Impact Mitigation
Database Downtime Users locked out Fallback to manual 2FA bypass (admin-only).
Fingerprint Collision False rejections Implement grace period (e.g., 5 mins) for manual override.
Session Fixation Account takeover Bind trusted devices to session ID (not just IP/user-agent).
Package Bug Broken auth flow Maintain a local fork for critical fixes.

Ramp-Up

  • Onboarding Time: 3–5 days for a mid-senior developer familiar with Laravel.
  • Key Learning Curves:
    • Middleware Order: Trusted device checks must run before 2FA middleware.
    • Fingerprinting: Understanding how user_agent/IP changes affect stability.
  • Training Needs:
    • Security Team: Review trusted device audit logs.
    • DevOps: Configure alerts for failed device checks (e.g., via Sentry).
  • **Metrics
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor