diff --git a/Envfile b/Envfile index 86f827aff..6e586c31b 100644 --- a/Envfile +++ b/Envfile @@ -114,7 +114,7 @@ variable :HCTI_API_KEY, :String, default: "Optional" # (https://docs.fastly.com/api/) variable :FASTLY_API_KEY, :String, default: "" variable :FASTLY_SERVICE_ID, :String, default: "" -variable :FASTLY_WHITELIST_PARAMS_SNIPPET_NAME, :String, default: "" +variable :FASTLY_SAFE_PARAMS_SNIPPET_NAME, :String, default: "" # Honeycomb for monitoring and observability # (https://www.honeycomb.io/) diff --git a/app/assets/javascripts/base.js.erb b/app/assets/javascripts/base.js.erb index 220e133cf..ecc6c5d80 100644 --- a/app/assets/javascripts/base.js.erb +++ b/app/assets/javascripts/base.js.erb @@ -56,7 +56,7 @@ var instantClick return target } - function isBlacklisted(elem) { + function isNotPreloadable(elem) { do { if (!elem.hasAttribute) { // Parent of break @@ -80,7 +80,7 @@ var instantClick || a.href.indexOf(domain + '/') != 0 // Another domain, or no href attribute || (a.href.indexOf('#') > -1 && removeHash(a.href) == $currentLocationWithoutHash) // Anchor - || isBlacklisted(a) + || isNotPreloadable(a) ) { return false } diff --git a/app/services/fastly_vcl/whitelisted_params.rb b/app/services/fastly_vcl/safe_params.rb similarity index 87% rename from app/services/fastly_vcl/whitelisted_params.rb rename to app/services/fastly_vcl/safe_params.rb index 99d36c250..365c830fa 100644 --- a/app/services/fastly_vcl/whitelisted_params.rb +++ b/app/services/fastly_vcl/safe_params.rb @@ -1,10 +1,10 @@ module FastlyVCL - # Handles updates to our VCL snippet on Fastly that whitelists params - class WhitelistedParams + # Handles updates to our VCL snippet on Fastly that lists safe params + class SafeParams VCL_DELIMITER_START = "^(".freeze VCL_DELIMITER_END = ")$".freeze - SNIPPET_NAME = ApplicationConfig["FASTLY_WHITELIST_PARAMS_SNIPPET_NAME"].freeze - FILE_PARAMS = YAML.load_file("config/fastly/whitelisted_params.yml").freeze + SNIPPET_NAME = ApplicationConfig["FASTLY_SAFE_PARAMS_SNIPPET_NAME"].freeze + FILE_PARAMS = YAML.load_file("config/fastly/safe_params.yml").freeze class << self def update @@ -60,7 +60,7 @@ module FastlyVCL "new_version:#{new_version.number}", ] - DatadogStatsClient.increment("fastly.whitelist", tags: tags) + DatadogStatsClient.increment("fastly.safelist", tags: tags) end end end diff --git a/config/fastly/whitelisted_params.yml b/config/fastly/safe_params.yml similarity index 100% rename from config/fastly/whitelisted_params.yml rename to config/fastly/safe_params.yml diff --git a/config/initializers/docker.rb b/config/initializers/docker.rb index 6bfa8ed2b..44f672d64 100644 --- a/config/initializers/docker.rb +++ b/config/initializers/docker.rb @@ -3,7 +3,7 @@ if Rails.env.development? && File.file?("/.dockerenv") # Using shell tools so we don't need to require Socket and IPAddr host_ip = `/sbin/ip route|awk '/default/ { print $3 }'`.strip logger = Logger.new(STDOUT) - logger.info "Whitelisting #{host_ip} for BetterErrors and Web Console" + logger.info "Allowing #{host_ip} for BetterErrors and Web Console" if defined?(BetterErrors::Middleware) BetterErrors::Middleware.allow_ip!(host_ip) diff --git a/config/initializers/doorkeeper.rb b/config/initializers/doorkeeper.rb index 0f21ded32..6c981cda1 100644 --- a/config/initializers/doorkeeper.rb +++ b/config/initializers/doorkeeper.rb @@ -257,7 +257,7 @@ Doorkeeper.configure do # force_ssl_in_redirect_uri { |uri| uri.host != 'localhost' } # Specify what redirect URI's you want to block during Application creation. - # Any redirect URI is whitelisted by default. + # Any redirect URI is enabled by default. # # You can use this option in order to forbid URI's with 'javascript' scheme # for example. diff --git a/docs/backend/fastly.md b/docs/backend/fastly.md index d6cb91aa8..5a808edc1 100644 --- a/docs/backend/fastly.md +++ b/docs/backend/fastly.md @@ -13,16 +13,16 @@ If you want to learn more about we use Fastly, check out this [@benhalpern](https://dev.to/ben), gave at RailsConf 2018 talking about how we made our app so fast it went viral. -## Whitelisting query string parameters +## Adding query string parameters to a safe list In the context of contributing, here's what you need to know about Fastly. In order for our servers to receive any sort of query string parameters in a -request, they must first be whitelisted in Fastly. For example, if you're +request, they must first be marked as safe in Fastly. For example, if you're creating a new API endpoint or updating an existing one to accept new parameters, you'll need to update Fastly. -The reason we whitelist parameters in Fastly this way is so we don't have to -consider junk parameters when busting the caches. Check out our +The reason we have a safe list of parameters in Fastly this way is so we don't +have to consider junk parameters when busting the caches. Check out our [`CacheBuster`](https://github.com/thepracticaldev/dev.to/blob/master/app/labor/cache_buster.rb) to see examples of this. @@ -33,8 +33,8 @@ it programmatically using the Fastly ## How it works -We created a new file, `config/fastly/whitelisted_params.yml`, to house all of -the whitelisted params in Fastly. +We created a new file, `config/fastly/safe_params.yml`, to house all of the safe +params in Fastly. If you need to update this list, simply update this file. It's as easy as that! @@ -43,13 +43,12 @@ _Fastly is not setup for development._ ## In production If you have Fastly configured in Production and have a similar custom VCL script -to whitelist query string params, make sure you've set the -`FASTLY_WHITELIST_PARAMS_SNIPPET_NAME` ENV variable with the name of the VCL -snippet you have configured in Fastly. +to list safe query string params, make sure you've set the +`FASTLY_SAFE_PARAMS_SNIPPET_NAME` ENV variable with the name of the VCL snippet +you have configured in Fastly. -Whitelisted params on Fastly are updated automatically when a production deploy -goes out unless this key is not set (i.e. you don't have a similar custom VCL -setup). +Safe params on Fastly are updated automatically when a production deploy goes +out unless this key is not set (i.e. you don't have a similar custom VCL setup). -We do this by executing `bin/rails fastly:update_whitelisted_params` in our +We do this by executing `bin/rails fastly:update_safe_params` in our `release-tasks.sh` script. diff --git a/lib/tasks/fastly.rake b/lib/tasks/fastly.rake index cd99442d4..f987f9377 100644 --- a/lib/tasks/fastly.rake +++ b/lib/tasks/fastly.rake @@ -1,17 +1,20 @@ namespace :fastly do - desc "Update VCL for whitelisted params on Fastly" - task update_whitelisted_params: :environment do + desc "Update VCL for safe params on Fastly" + task update_safe_params: :environment do fastly_credentials = %w[ FASTLY_API_KEY FASTLY_SERVICE_ID - FASTLY_WHITELIST_PARAMS_SNIPPET_NAME + FASTLY_SAFE_PARAMS_SNIPPET_NAME ] if fastly_credentials.any? { |cred| ApplicationConfig[cred].blank? } - puts "Fastly not configured. Please set #{fastly_credentials.join(", ")} in your environment." + Rails.logger.info( + "Fastly not configured. Please set #{fastly_credentials.join(", ")} in your environment." + ) + next end - FastlyVCL::WhitelistedParams.update + FastlyVCL::SafeParams.update end end diff --git a/release-tasks.sh b/release-tasks.sh index 64075daef..635500e48 100755 --- a/release-tasks.sh +++ b/release-tasks.sh @@ -17,7 +17,7 @@ set -Eex # runs migration for Postgres, setups/updates Elasticsearch # and boots the app to check there are no errors STATEMENT_TIMEOUT=180000 bundle exec rails db:migrate -bundle exec rake fastly:update_whitelisted_params +bundle exec rake fastly:update_safe_params bundle exec rake search:setup bundle exec rake data_updates:enqueue_data_update_worker bundle exec rails runner "puts 'app load success'" diff --git a/spec/services/fastly_vcl/whitelisted_params_spec.rb b/spec/services/fastly_vcl/safe_params_spec.rb similarity index 90% rename from spec/services/fastly_vcl/whitelisted_params_spec.rb rename to spec/services/fastly_vcl/safe_params_spec.rb index 3feb3daeb..cc7a6dde5 100644 --- a/spec/services/fastly_vcl/whitelisted_params_spec.rb +++ b/spec/services/fastly_vcl/safe_params_spec.rb @@ -1,12 +1,14 @@ require "rails_helper" -RSpec.describe FastlyVCL::WhitelistedParams, type: :service do +RSpec.describe FastlyVCL::SafeParams, type: :service do let(:fastly) { instance_double(Fastly) } let(:fastly_service) { instance_double(Fastly::Service) } let(:fastly_version) { instance_double(Fastly::Version) } let(:fastly_snippet) { instance_double(Fastly::Snippet) } - let(:file_params) { YAML.load_file("config/fastly/whitelisted_params.yml") } - let(:snippet_content) { "#{described_class::VCL_DELIMITER_START}#{file_params.join('|')}#{described_class::VCL_DELIMITER_END}" } + let(:file_params) { YAML.load_file("config/fastly/safe_params.yml") } + let(:snippet_content) do + "#{described_class::VCL_DELIMITER_START}#{file_params.join('|')}#{described_class::VCL_DELIMITER_END}" + end # Fastly isn't setup for test or development environments so we have to stub # quite a bit here to simulate Fastly working ¯\_(ツ)_/¯ @@ -67,7 +69,7 @@ RSpec.describe FastlyVCL::WhitelistedParams, type: :service do tags = hash_including(tags: array_including("added_params:new_param", "removed_params:#{old_param}", "new_version:#{fastly_version.number}")) - expect(DatadogStatsClient).to have_received(:increment).with("fastly.whitelist", tags) + expect(DatadogStatsClient).to have_received(:increment).with("fastly.safelist", tags) end end end diff --git a/spec/tasks/fastly_spec.rb b/spec/tasks/fastly_spec.rb index ca3be318b..26566a11b 100644 --- a/spec/tasks/fastly_spec.rb +++ b/spec/tasks/fastly_spec.rb @@ -6,14 +6,16 @@ RSpec.describe "Fastly tasks", type: :task do PracticalDeveloper::Application.load_tasks end - describe "#update_whitelisted_params" do + describe "#update_safe_params" do it "doesn't run if Fastly isn't configured" do - allow(ApplicationConfig).to receive(:[]).with("FASTLY_API_KEY").and_return(nil) - allow(ApplicationConfig).to receive(:[]).with("FASTLY_SERVICE_ID").and_return(nil) - allow(ApplicationConfig).to receive(:[]).with("FASTLY_WHITELIST_PARAMS_SNIPPET_NAME").and_return(nil) - allow(FastlyVCL::WhitelistedParams).to receive(:update) - Rake::Task["fastly:update_whitelisted_params"].invoke - expect(FastlyVCL::WhitelistedParams).not_to have_received(:update) + %w[FASTLY_API_KEY FASTLY_SERVICE_ID FASTLY_SAFE_PARAMS_SNIPPET_NAME].each do |var| + allow(ApplicationConfig).to receive(:[]).with(var).and_return(nil) + end + allow(FastlyVCL::SafeParams).to receive(:update) + + Rake::Task["fastly:update_safe_params"].invoke + + expect(FastlyVCL::SafeParams).not_to have_received(:update) end end end