Fix: trailing-slash 301 redirects downgrading https to http (#217)#219
Merged
Fix: trailing-slash 301 redirects downgrading https to http (#217)#219
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #217. Behind a TLS-terminating proxy under Rack 3,
request.schemereturnshttpbecauseX-Forwarded-Protois no longer auto-trusted. Sinatra'sredirecthelper was expanding the relative target to an absolute URL using that scheme, sohttps://requests with a trailing slash gotLocation: http://...and were blocked as mixed content by browsers (e.g. biomixer's/paths_to_root/calls from bioportal.bioontology.org).X-Forwarded-Protofor the scheme and falling back torequest.schemewhen the header is absent or nothttp/https.request.host_with_port.X-Forwarded-Hostis not read — it isn't needed for the fix, and trusting it would widen the open-redirect surface if a proxy ever passed client-supplied values through.Gemfile.lockbump forncbo_cronandontologies_linked_data(unrelated to this fix; carried over from the branch base).Test plan
Regression tests in
test/controllers/test_home_controller.rbcover:httpsscheme is preserved inLocationX-Forwarded-Protofalls back torequest.schemeX-Forwarded-Proto(e.g.javascript) falls back torequest.schemeX-Forwarded-Proto: https, httpuses the leftmost (client-facing) value%3A/%2Fin the class IRI from the issue's repro) round-trip through the redirect unchangedVerify in staging by curling a trailing-slash URL through the proxy and confirming
location: https://...in the 301 response.