Weave 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

Laravel Force Https Laravel Package

14four/laravel-force-https

Laravel middleware package to force HTTPS across your app. Automatically redirects HTTP requests to HTTPS, with options to exclude paths or environments so you can keep local/testing flexible while enforcing secure connections in production.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Purpose Alignment: The package enforces HTTPS across all routes in a Laravel application, aligning with modern security best practices (e.g., PCI-DSS, GDPR, and browser warnings for non-HTTPS sites). This is a critical requirement for production-grade applications, especially those handling sensitive data.
  • Non-Invasive Design: Leverages Laravel’s middleware system, ensuring minimal intrusion into existing route definitions. The package’s core functionality (ForceHttpsMiddleware) integrates seamlessly with Laravel’s built-in middleware stack (e.g., web, api).
  • Configurability: Supports domain-specific HTTPS enforcement (e.g., app.example.com vs. staging.example.com), which is valuable for multi-environment deployments (dev/stage/prod). The ability to exclude routes (e.g., /health) via middleware priority or annotations is a plus.

Integration Feasibility

  • Laravel Version Compatibility: Explicitly supports Laravel 5.5+ (as inferred from middleware structure). If using Laravel 8/9/10, the package should work with minimal adjustments (e.g., middleware binding syntax).
  • Dependency Conflicts: Minimal external dependencies (only Laravel core), reducing risk of version clashes. However, potential conflicts with other middleware (e.g., TrustProxies, RedirectIfAuthenticated) should be tested for precedence issues.
  • Customization Points: Extensible via:
    • Middleware priority tweaks (e.g., web vs. api middleware groups).
    • Custom logic in Handle class (e.g., dynamic HTTPS enforcement based on request headers).
    • Service provider bootstrapping for environment-specific rules.

Technical Risk

  • Middleware Precedence: Risk of incorrect HTTPS redirects if this middleware is not the last to run in the stack (e.g., conflicting with RedirectIfAuthenticated). Requires testing with existing middleware.
  • Performance Overhead: Minimal, as the package only adds a single middleware check per request. However, in high-traffic APIs, ensure the 301 redirect logic doesn’t bottleneck response times.
  • Edge Cases:
    • Mixed HTTP/HTTPS subdomains (e.g., http://api.example.com vs. https://app.example.com).
    • Reverse proxy setups (e.g., Nginx/Apache) where X-Forwarded-Proto must be trusted. The package supports this via TrustProxies integration, but misconfiguration could lead to infinite redirects.
    • Local development environments (e.g., localhost) where HTTPS enforcement may break tools like Laravel Valet or Docker.

Key Questions

  1. Environment-Specific Rules:
    • How will you handle HTTPS enforcement for staging vs. production? (e.g., config/force_https.php overrides).
  2. Middleware Conflicts:
    • Are there existing middleware (e.g., TrustProxies, Subdomain) that could interfere with this package’s redirects?
  3. Reverse Proxy Trust:
    • Is TrustProxies configured correctly to avoid redirect loops in cloud environments (e.g., AWS ALB, Heroku)?
  4. Route Exclusions:
    • Which routes (e.g., /health, /webhooks) should bypass HTTPS enforcement, and how will they be excluded?
  5. Testing Strategy:
    • How will you validate HTTPS enforcement across all environments (e.g., automated tests for 301 redirects)?
  6. Legacy Support:
    • If migrating from a custom HTTPS solution, what deprecation or cleanup steps are needed?

Integration Approach

Stack Fit

  • Laravel Ecosystem: Native integration with Laravel’s middleware and service provider systems. No additional frameworks or libraries required.
  • PHP Version: Compatible with PHP 7.2+ (Laravel 5.5+ requirement). Ensure your PHP version aligns with Laravel’s supported matrix.
  • Web Server Compatibility:
    • Works with any web server (Nginx, Apache, Caddy) as long as HTTPS termination is handled at the server level or via Laravel’s TrustProxies.
    • For self-managed HTTPS (e.g., Let’s Encrypt), ensure the package’s redirects don’t conflict with server-level redirects (e.g., Nginx return 301).
  • Cloud/Hosting Providers:
    • Ideal for platforms with built-in HTTPS (e.g., Heroku, Vercel, AWS Elastic Beanstalk).
    • For platforms requiring custom HTTPS (e.g., DigitalOcean Droplets), ensure the package’s logic aligns with your TLS setup.

Migration Path

  1. Assessment Phase:
    • Audit existing middleware (e.g., app/Http/Kernel.php) for HTTPS-related logic.
    • Identify routes/subdomains requiring HTTPS enforcement or exclusion.
  2. Installation:
    composer require 14four/laravel-force-https
    
    • Publish the config (if customization is needed):
      php artisan vendor:publish --provider="14four\ForceHttps\ForceHttpsServiceProvider"
      
  3. Configuration:
    • Update app/Http/Kernel.php to include the middleware in the appropriate groups (e.g., $middlewareGroups['web']).
    • Configure config/force_https.php for environment-specific rules (e.g., exclude localhost).
  4. Testing:
    • Validate redirects using:
      • Browser dev tools (Network tab for 301 status codes).
      • CLI tools (e.g., curl -v http://example.com).
      • Automated tests (e.g., Laravel Dusk or Pest).
  5. Deployment:
    • Roll out in stages (e.g., staging first) to monitor for redirect loops or performance issues.

Compatibility

  • Laravel Versions:
    • Tested on Laravel 5.5+; may require minor adjustments for Laravel 10+ (e.g., middleware binding syntax).
    • For Laravel 8/9, ensure compatibility with the Illuminate\Foundation\Application middleware binding changes.
  • Package Dependencies:
    • No hard dependencies beyond Laravel core. Soft dependencies (e.g., illuminate/support) are version-locked to Laravel’s requirements.
  • Third-Party Middleware:
    • Potential conflicts with middleware that modify the request/response cycle (e.g., TrustProxies, Localization). Test precedence by adjusting middleware order in Kernel.php.

Sequencing

  1. Order of Operations:
    • Place ForceHttpsMiddleware after TrustProxiesMiddleware (if used) to ensure correct protocol detection.
    • Place before middleware that might short-circuit the request (e.g., RedirectIfAuthenticated).
  2. Environment-Specific Setup:
    • Development: Exclude localhost and internal domains from HTTPS enforcement.
    • Staging/Production: Enforce HTTPS for all domains except explicitly whitelisted routes.
  3. Fallback Handling:
    • If HTTPS enforcement fails (e.g., due to misconfigured proxies), implement a graceful fallback (e.g., log the event and continue without redirecting).

Operational Impact

Maintenance

  • Configuration Drift:
    • Risk: Changes to middleware order or environment-specific rules may break HTTPS enforcement.
    • Mitigation: Document middleware precedence in Kernel.php and use feature flags for environment-specific configs.
  • Dependency Updates:
    • Low maintenance burden; updates to Laravel core will likely handle compatibility.
    • Monitor for breaking changes in Laravel’s middleware system (e.g., new middleware binding methods).
  • Logging:
    • Add logging for failed HTTPS redirects (e.g., Monolog) to detect misconfigurations early.
    • Example log entry:
      \Log::debug('HTTPS redirect failed for ' . request()->fullUrl(), ['user_agent' => request()->userAgent()]);
      

Support

  • Troubleshooting Common Issues:
    • Infinite Redirects: Verify TrustProxies is configured correctly and that the package isn’t running in a loop with server-level redirects.
    • Mixed Content Warnings: Ensure all assets (CSS/JS) are loaded via HTTPS; use Laravel’s Asset helper or mix-manifest.json.
    • Performance Degradation: Profile the middleware to ensure it’s not blocking the request pipeline.
  • Documentation Gaps:
    • The package lacks detailed docs on customization (e.g., dynamic enforcement rules). Supplement with internal runbooks for:
      • Middleware precedence examples.
      • Environment-specific config templates.
      • Debugging redirect loops.

Scaling

  • Performance:
    • Negligible overhead; the middleware adds a single conditional check per request.
    • In high-traffic APIs, ensure the 301 redirect doesn’t become a bottleneck (unlikely, but test under load).
  • Horizontal Scaling:
    • Stateless middleware; scales seamlessly with Laravel’s stateless architecture.
    • No database or external service dependencies.
  • Edge Cases at Scale:
    • High Redirect Volume: Monitor for excessive 301 redirects (e.g., from crawlers). Consider rate-limiting or caching redirect responses.
    • Global Load Balancers: Ensure load balancers (e.g., Cloudflare, ALB) aren’t double-redirecting with the package.

**

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.
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel