🔒 Application Security
Some notes about application security for Rails application.
What to think about when your application runs in production, things to keep in mind to prevent data leak.
Checklist
-
No usage of
.html_safeanywhere in the code. The app uses safe view helpers such assafe_join,content_tag, etc. to render html. -
Use
protect_from_forgery with: :exceptioninApplicationController. -
No reference to
skip_before_action :verify_authenticity_tokenorprotect_from_forgery except:anywhere. -
All references to
javascript_include_taginclude theintegrity: trueargument (more on SRI). You’ll also need to usecrossorigin: 'anonymous'for resources fetched from our CDN. -
config.force_ssl = trueis present inconfig/application.rborconfig/environments/production.rb. -
The session cookie has both the
secureandhttpOnlyflag (usually provided byforce_sslabove) -
The application is serving the following HTTP headers (verify names and values) secure headers configuration
-
X-Frame-Options: DENY -
X-Content-Type-Options: nosniff -
X-Download-Options: noopen -
X-Permitted-Cross-Domain-Policies: none -
X-Xss-Protection: 1; mode=block -
Referrer-Policy: origin-when-cross-origin* -
Content-Security-Policy: block-all-mixed-content;orContent-Security-Policy: upgrade-insecure-requests; -
Strict-Transport-Security: max-age=631138519; includeSubdomains(includeSubdomainsis optional,max-ageshould be at least 10 years)
-
-
Rails log scrubber is configured with sensitive parameter names:
config.filter_parameters += [:password]config.filter_parameters += [:access_token]config.filter_parameters += [:secret]- Any other sensitive params.
-
config.session_storeis configured with redis or mysql (usually inconfig/initializers/session_store.rb)
Links
If you are curious to learn more about security, I suggest you to read about the OSWAP.