Add antiproxying protection.

Try to prevent malicious sites like danbooru.me or idanbooru.com from
proxying our site and inserting ads. If we detect that we're not running
on the real site, then we redirect to the real site.
This commit is contained in:
evazion
2020-06-01 13:41:15 -05:00
parent 6b490cacba
commit 8b46d00b9b
2 changed files with 19 additions and 1 deletions

View File

@@ -19,6 +19,14 @@ $(function() {
$('#notice').fadeOut("fast");
e.preventDefault();
});
const CANONICAL_DOMAIN = <%= Danbooru.config.domain.to_json.html_safe %>;
const CANONICAL_HOSTNAME = <%= Danbooru.config.hostname.to_json.html_safe %>;
const ENABLE_ANTIPROXYING = <%= Danbooru.config.enable_antiproxying?.to_json.html_safe %>;
if (ENABLE_ANTIPROXYING && !location.hostname.endsWith(CANONICAL_DOMAIN)) {
location.hostname = CANONICAL_HOSTNAME;
}
});
window.submitInvisibleRecaptchaForm = function () {

View File

@@ -25,11 +25,16 @@ module Danbooru
"Danbooru"
end
# The canonical hostname of the site.
# The canonical hostname for the site, e.g. danbooru.donmai.us.
def hostname
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}"
@@ -551,6 +556,11 @@ 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