Comments (18)
Hi,
This is a tricky use-case, but maybe by setting the strict
option only on the second statement might work:
config.middleware.use Rack::SslEnforcer,
only_hosts: %r{api.example.com}
config.middleware.use Rack::SslEnforcer,
except_hosts: %r{api.example.com},
only: %r{/users},
ignore: %r{/assets},
strict: true
So the first statement ensures that all calls on api.example.com
will be redirected to HTTPS, and then the second statement ensures that all calls matching /users
will be redirected to HTTPS, and every other calls will be redirected to HTTP (ignoring calls matching /assets
).
I haven't actually tried this case, I'll try to add this test cases of the projects to see if that actually works.
from rack-ssl-enforcer.
nope it works the same way. /users paths works as https enabled but api.example.com ended in a redirect loop.
from rack-ssl-enforcer.
Ok, is the strict
option mandatory in your use-case then?
from rack-ssl-enforcer.
yes
from rack-ssl-enforcer.
Ok, I've added your use-case to our test suite and it works as expected...
What do you think?
from rack-ssl-enforcer.
why is except_hosts set to api.example.com and only_hosts set to api.example.org?
from rack-ssl-enforcer.
ok I forked and checked with api.example.org at both place and tests are passing fine. But in Rails app it's not working. Is there a way to define the both statements in one array (like in test case) rather than 2 different statements (like above). Something like
config.middleware.use Rack::SslEnforcer, [
{ :only_hosts => %r{api.example.org} },
{ :except_hosts => %r{api.example.org}, :only => %r{^/users}, :ignore => %r{^/assets}, :strict => true }
]
Just a silly thought.
from rack-ssl-enforcer.
@rymai I guess above isn't silly thought :), if i define 2 statements in test case, rather than one array.
setup {
mock_app :only_hosts => %r{api.example.org}
mock_app :except_hosts => %r{api.example.org}, :only => %r{^/users}, :ignore => %r{^/assets}, :strict => true
}
One Test fails (api test). And that's exactly the same thing happening in rails app. Any suggestions?
from rack-ssl-enforcer.
Sorry about the typo, but actually the :except_hosts
is actually not needed at all (I've fixed the test)!
Re. the test following setup:
setup {
mock_app :only_hosts => %r{api.example.org}
mock_app :except_hosts => %r{api.example.org}, :only => %r{^/users}, :ignore => %r{^/assets}, :strict => true
}
some tests fail because the first statement is not part of the app that's used for the tests. In fact the last call to mock_app
replaces the app you created with the first call. That's why I passed 2 hashes to mock_app
in order to define two use Rack::SslEnforcer
statements.
That all said, could you share your Rails config file where you use use Rack::SslEnforcer
? Thanks!
from rack-ssl-enforcer.
Here's my rack_ssl_config.rb from /config/initializers directory
Website::Application.configure do
if AppConfig.ssl.enabled
config.middleware.use Rack::SslEnforcer,
only_hosts: AppConfig.api.host
config.middleware.use Rack::SslEnforcer,
except_hosts: AppConfig.api.host,
only: %r{/users},
ignore: %r{/assets},
strict: true
end
end
I've no clue to pass both statements in one hash. what will be the code for it?
from rack-ssl-enforcer.
oh now i studied the mock_app method. My bad. Sorry for above. But there is one problem with tests, you've to add one more test that when someone access the https://api.example.org it shouldn't redirect and that's failing
should 'stay on HTTPS for https://api.example.org' do
get 'https://api.example.org'
assert_equal 200, last_response.status
assert_equal 'https://api.example.org/', last_response.location
end
and that's creating a redirect loop.
from rack-ssl-enforcer.
ok this hasn't solved from long time. So I guess if there's another option where I can pass a Proc or a property called ignore_hosts so that I can ignore api.example.org and manage it manually. Is that possible. I was also thinking to override the call method for middleware, but thought if ignore_hosts is there, that will be better instead overriding the call. What do you think?
from rack-ssl-enforcer.
@rymai, @thibaudgg would you take a look at branch issue62? 1c985f6 should fix this issue, but two other tests are broken now (both a comination of :strict and :except*). I believe the :except option should except specific paths, hosts or whatever from any modification - any other opinions on that?
from rack-ssl-enforcer.
@rymai could you look at it, I'm in the middle of my move, thanks!
from rack-ssl-enforcer.
I'll have a look this evening!
from rack-ssl-enforcer.
Ok, I've had a chance to review this issue. I think :except*
constraints + :strict
option make sense. Why should it be different than for :only*
constraints?
from rack-ssl-enforcer.
I face the same situation with @akashkamboj. I got redirect loop when I go http://api.example.com
config.middleware.use Rack::SslEnforcer, only_hosts: 'api.example.com'
config.middleware.use Rack::SslEnforcer,
only: ['/admin/login', %r{^/user/password}],
ignore: %r{^/assets},
strict: true
Even it still get redirect loop when I try with except_hosts
config.middleware.use Rack::SslEnforcer, only_hosts: 'api.example.com'
config.middleware.use Rack::SslEnforcer,
except_hosts: 'api.example.com',
only: ['/admin/login', %r{^/user/password}],
ignore: %r{^/assets},
strict: true
from rack-ssl-enforcer.
I'll try to take a closer look before the weekend...
from rack-ssl-enforcer.
Related Issues (20)
- Forcing HTTPS only on certain paths or methods might be a security problem
- Load balancer health check redirected; not making it to the app HOT 5
- Middleware use vs. insert_before HOT 1
- Does rack-ssl-enforcer have support for ssl client verification? HOT 1
- Increase the default HSTS max-age to 2 years
- Running code before redirect not working HOT 3
- Support for ruby 2.0 and Rails 4 HOT 2
- Release new version! <3 HOT 2
- Already encoded url parameters get encoded again when redirecting
- How to handle URI::InvalidURIError? HOT 7
- POST requests HOT 5
- Issue with IE only... strict true not working HOT 3
- Issue with Redirects HOT 3
- Infinite redirects behind AWS ELB HOT 5
- ERR_CONNECTION_REFUSED HOT 2
- use_redirect always forcing redirect, even for HTTPS HOT 2
- HSTS and secure cookies w/o redirect? HOT 2
- Does not set session cookie as secure HOT 6
- HSTS Implementation HOT 1
- Is there a changelog? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rack-ssl-enforcer.