nasa-jpl-memex / memex-explorer

Viewers for statistics and dashboarding of Domain Search Engine data
BSD 2-Clause "Simplified" License
121 stars 69 forks source link

non-SSL requests on https://explorer.continuum.io/seeds #761

Open ahmadia opened 8 years ago

ahmadia commented 8 years ago
ntent: The page at 'https://explorer.continuum.io/seeds/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://explorer.continuum.io/api/datawake/'. This request has been blocked; the content must be served over HTTPS.

Hot-fixing for now.

ahmadia commented 8 years ago

Note, I've already pulled out BasicAuthentication from the REST configuration, (using Session Authentication):

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.SessionAuthentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.AllowAny',
    ),
    'DEFAULT_FILTER_BACKENDS': ('rest_framework.filters.DjangoFilterBackend',)
}

Other parts of the REST API work, it's something specific to this page/view.

ahmadia commented 8 years ago

@brittainhard - workaround is to ensure you've got trailing slashes on Django REST endpoints:

See https://github.com/jashkenas/backbone/issues/848 for more details.

ahmadia commented 8 years ago

Please land the following patch when you get a chance:

diff --git a/source/base/static/base/js/backbone/trails_backbone.js b/source/base/static/base/js/backbone/trails_backbone.js
index 0d98dd7..867024a 100644
--- a/source/base/static/base/js/backbone/trails_backbone.js
+++ b/source/base/static/base/js/backbone/trails_backbone.js
@@ -5,7 +5,7 @@

   exports.Trail = Backbone.Model.extend({
-    urlRoot: "/api/datawake",
+    urlRoot: "/api/datawake/",
     defaults: {
       trail_id: 0,
       domain_name: "",
@@ -16,7 +16,7 @@

   exports.TrailsCollection = Backbone.Collection.extend({
-    url: "/api/datawake",
+    url: "/api/datawake/",
     model: exports.Trail,
   });
ahmadia commented 8 years ago

This is fixed in production, but not in our repository.

ahmadia commented 8 years ago

Found another one:

explorer.continuum.io/:1 Mixed Content: The page at 'https://explorer.continuum.io/seeds/datawake_import/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://explorer.continuum.io/api/seeds_list/1/'. This request has been blocked; the content must be served over HTTPS.

I'm guessing it's the same issue.

ahmadia commented 8 years ago

I've backed it out this far:

source/base/templates/base/edit_seeds.html

  <div class="col-sm-10 col-sm-offset-1 col-md-10 col-md-offset-1">
    <input id="seeds_pk" type="hidden" value="1">
    <div id="seeds"></div>
  </div>

source/base/static/base/js/backbone/edit_seeds_backbone.js

    el: "#seeds",
    form: "#editSeedsForm",
    invalidLines: [],
    template: _.template($("#editSeedsTemplate").html()),
    initialize: function(model){
      this.model = model;
      var that = this;
      this.model.set({id: $("#seeds_pk").val()}).fetch({
        success: function(){
          that.render();
          that.setEditor();
        }
      });
    },
ahmadia commented 8 years ago

https://stackoverflow.com/questions/10555962/enable-django-and-tastypie-support-for-trailing-slashes

ahmadia commented 8 years ago

https://stackoverflow.com/questions/9097404/django-is-redirecting-from-https-to-http

ahmadia commented 8 years ago

Rubber-duckied my way out of this one.

If I understand what's going on correctly:

Backbone composes an incorrect request for a given seeds list using a very slightly incorrect URL:

https://explorer.continuum.io/api/seeds_list/1 instead of https://explorer.continuum.io/api/seeds_list/1/

Now there are actually a couple of ways we should be able to fix this.

Django was sending a 301 redirect back, but it's sending using an 'http' protocol, not https. So I made sure that Django knew that it needed to send HTTPS redirect responses back. This is a two-part operation.

On the nginx configuration:

      proxy_set_header X-Forwarded-Proto $scheme;

In Django settings:

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

Note the security warnings on SECURE_PROXY_SSL_HEADER, but this all looks correct to me.

ahmadia commented 8 years ago

So the patches are to nginx and settings. I think this frees us from having to worry about trailing slashes so long as Django redirects to the correct resource.

ahmadia commented 8 years ago

I'll close this when the commits are landed to the docker branch and pushed.

ahmadia commented 8 years ago

punting to 0.5 - this is fixed on explorer.continuum.io