Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Prevent request deauthorization when loading assets #641

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

iberianpig
Copy link

@iberianpig iberianpig commented Feb 12, 2025

Description

This PR fixes the problem described in Issue #613, where requests to the /assets/ directory caused the __profilin cookie to be deleted, which in turn deactivated the client-side profiler.

Changes Made

  • Prevent Cookie Deletion:

    • Updated the handle_cookie method to stop cookie deletion for asset requests by using preserve_cookie: true. This keeps the profiler's state when loading assets.
    • The commit in this PR is based on the work done by @Blayr
  • Skip Asset Requests:

    • Added Rack::MiniProfiler.config.skip_paths = ['/assets'] to ignore asset requests during profiling checks. This is important because requests to /assets can still happen even if Rails.config.public_file_server.enabled is false.
    • When an asset is not found, the config.assets.unknown_asset_fallback option allows fallback handling, which can lead to extra requests to /assets. These paths were not fully considered in the dynamic skip paths configuration.
  • Rails Version Handling:

    • Updated the condition to check which asset server configuration to use for different Rails versions. For Rails 5.1.0 and later, the code checks both public_file_server.enabled and unknown_asset_fallback.

With these changes, the unwanted cookie deletion that caused the error ActionController::RoutingError (No route matches [POST] "/mini-profiler-resources/results") no longer happens.

Blayr and others added 2 commits May 2, 2024 14:34
- Modified the condition for enabling the asset server to check for `::Rails.configuration.public_file_server.enabled` or `::Rails.configuration.assets.unknown_asset_fallback` for Rails versions 5.1.0 and above.
- The `unknown_asset_fallback` option allows for fallback handling when an asset is not found, which can lead to additional requests to the `/assets` path when assets are missing.
@iberianpig iberianpig marked this pull request as ready for review February 12, 2025 16:37
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.

2 participants