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

SSL :ignore ignored for routable addresses, but works for static addresses #43

Closed
mattheworiordan opened this issue Nov 28, 2012 · 5 comments

Comments

@mattheworiordan
Copy link

Hi

I have set up Rack::SslEnforcer as follows:

use Rack::SslEnforcer, :ignore => [/^\/assets/, '/crossdomain', '/test']

As expected, any assets are served with both SSL and not SSL. /test which serves the static HTML file /public/test.html, also supports both SSL & non-SSL requests.

However, the reference to crossdomain is in fact a Rails route which points to a standard view that is rendered. Oddly, no matter what I do, it appears crossdomain requires SSL, whereas for any static assets the :ignore option is working.

Example of failure:

$ curl http://localhost:3000/crossdomain.xml
<html><body>You are being <a href="https://localhost/crossdomain.xml">redirected</a>.</body></html>

Example of expected behaviour:

$ curl http://localhost:3000//test.html
<html>test</html>

I have tried loading the middleware in application.rb, in the config environment file, and even in config.ru, and it makes no difference. No matter what I do, all Rails routable addresses always require SSL, whereas static files respect the :ignore option. I have also tried removing Rack::SslEnforcer altogether, and /crossdomain.xml works on both HTTP and HTTPS.

Am I missing something obvious here?

Thanks for your help.

@tobmatth
Copy link
Owner

Your setup should be fine and in fact it shouldn't matter whether a static asset or some Rails controller is called in the end. Just a shot in the dark: did you try some other way to force ssl before, maybe a forgotten before filter or something?

@mattheworiordan
Copy link
Author

Well to be honest I am working with someone else's code base, so there is a possibility there is something hidden away that I am not aware of. Oddly though SSL is not required when Rack::SslEnforcer is not required, so it does make me wonder how anything could be hidden away. I also thought that it should not make any difference whether the URL matches a Rails route or not, but clearly it is somehow.

I will explore further and report back.

@tobmatth
Copy link
Owner

Meh, my fault. Static assets are served by ActionDispatch::Static, which kicks in before Rack::SslEnforcer unless you explicitly insert it at a specific position (see rake middleware), so that's why your static assets work. In addition, you are using a String path constraint, which will match explicitly /crossdomain, but won't match crossdomain.xml.

So just use a Regex and you should be good to go...

@tobmatth
Copy link
Owner

I'm closing here, feel free to reopen if you run into further problems.

@mattheworiordan
Copy link
Author

Thanks for your help @tobmatth, the issue was related to the Rack load order, so I am now using this instead:

config.middleware.insert_before ActionDispatch::Static, Rack::SslEnforcer, except: [ %r{^/assets/}, %r{^/crossdomain} ], strict: true

I realised the string crossdomain would not work, but I was getting desperate and trying all sorts of stuff! BTW. I found the :ignore statement didn't behave as expected, hence why I went with the above.

Thanks again, all sorted.

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

No branches or pull requests

2 participants