Commit c33a5906 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #4040 from smashwilson/generate-secret

Security: keep the Rails secret token out of version control.
parents c5de01f8 e444c7f6
...@@ -29,3 +29,4 @@ db/data.yml ...@@ -29,3 +29,4 @@ db/data.yml
vendor/bundle/* vendor/bundle/*
rails_best_practices_output.html rails_best_practices_output.html
doc/code/* doc/code/*
.secret
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
require 'securerandom'
# Your secret key for verifying the integrity of signed cookies. # Your secret key for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid! # If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random, # Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks. # no regular words or you'll be exposed to dictionary attacks.
Gitlab::Application.config.secret_token = '0a38e9a40ca5d66d7002a6ade0ed0f8b71058c820163f66cf65d91521ab55255ff708b9909b138008a7f13d68fec575def1dc3ff7200cd72b065896315e0bed2'
def find_secure_token
token_file = Rails.root.join('.secret')
if File.exist? token_file
# Use the existing token.
File.read(token_file).chomp
else
# Generate a new token of 64 random hexadecimal characters and store it in token_file.
token = SecureRandom.hex(64)
File.write(token_file, token)
token
end
end
Gitlab::Application.config.secret_token = find_secure_token
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment