RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

ActionController::Redirecting::UnsafeRedirectError

in Rails 7 if you get ActionController::Redirecting::UnsafeRedirectError

it just means you try to redirect_to url that don’t match your app host url so instead of:

     external_url = 'https://www.eq8.eu' 
     redirect_to  external_url

do

     external_url = 'https://www.eq8.eu' 
     redirect_to  external_url, allow_other_host: true

full example:

class MyController < ApplicationController
  # ...
  def show
      external_url = 'https://www.eq8.eu' 
      redirect_to  external_url, allow_other_host: true
  end
end

also the redirect_back option is affected

redirect_back(fallback_path: "/", allow_other_host: false)

related articles:

Comments

If you need to change default behavior of your rails 7 app, set <pre>config.action_controller.raise_on_open_redirects = false</pre> in your application.rb.

It might be useful, if there are an external redirect in a gem. (Eg : sorcery)

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in