From 647556761bf1f9fcb4885ea0cec91258a6ec8c90 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 2 Jun 2020 23:03:04 -0500 Subject: [PATCH] Fix antiproxying (again). Fuck it, just hardcode it. They rewrite certain parts of our markup so we can't rely on anything in the html. --- app/helpers/application_helper.rb | 7 ++++++- app/javascript/src/javascripts/common.js | 4 ++-- app/views/layouts/default.html.erb | 1 - config/danbooru_default_config.rb | 10 ---------- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 26d5bd370..70919e656 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -272,6 +272,8 @@ module ApplicationHelper current_item_data_attributes = data_attributes_for(current_item, model_name, model_attributes) end + config_data_attributes = data_attributes_for(Danbooru.config, "config", [:hostname, :domain]) + controller_param = params[:controller].parameterize.dasherize action_param = params[:action].parameterize.dasherize @@ -282,8 +284,11 @@ module ApplicationHelper controller: controller_param, action: action_param, layout: controller.class.send(:_layout), + "current-user-ip-addr": request.remote_ip, **current_user_data_attributes, - **current_item_data_attributes.to_h + **current_item_data_attributes.to_h, + **config_data_attributes, + "config-environment": Rails.env, } } end diff --git a/app/javascript/src/javascripts/common.js b/app/javascript/src/javascripts/common.js index 931266d8e..03563a2f9 100644 --- a/app/javascript/src/javascripts/common.js +++ b/app/javascript/src/javascripts/common.js @@ -20,8 +20,8 @@ $(function() { e.preventDefault(); }); - if (Danbooru.config["enable_antiproxying?"] && !location.hostname.endsWith(Danbooru.config.domain)) { - location.hostname = Danbooru.config.hostname; + if (location.hostname.endsWith("danbooru.me")) { + location.hostname = "danbooru.donmai.us"; } }); diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb index c82b3ad4e..bf1a94442 100644 --- a/app/views/layouts/default.html.erb +++ b/app/views/layouts/default.html.erb @@ -120,7 +120,6 @@ window.Danbooru = {}; } - window.Danbooru.config = <%= [:hostname, :domain, :enable_antiproxying?].map { |opt| [opt, Danbooru.config.send(opt)] }.to_h.to_json.html_safe %>; window.Danbooru.notice = Danbooru.Utility.notice; window.Danbooru.error = Danbooru.Utility.error; diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index 73b5df007..516533b0f 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -30,11 +30,6 @@ module Danbooru Socket.gethostname end - # The canonical base domain for the site, e.g. donmai.us. - def domain - hostname - end - # Contact email address of the admin. def contact_email "webmaster@#{hostname}" @@ -472,11 +467,6 @@ module Danbooru def redis_url "redis://localhost:6379" end - - # Try to prevent copycat sites from proxying our site and inserting ads or phishing passwords. - def enable_antiproxying? - Rails.env.production? - end end class EnvironmentConfiguration