-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure browser-side CSPs and security headers
- Loading branch information
Showing
8 changed files
with
96 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative './app' | ||
require 'roda' | ||
require 'rack/ssl-enforcer' | ||
require 'secure_headers' | ||
|
||
module Credence | ||
# Configuration for the API | ||
class App < Roda | ||
plugin :environments | ||
plugin :multi_route | ||
|
||
FONT_SRC = %w[https://cdn.jsdelivr.net].freeze | ||
SCRIPT_SRC = %w[https://cdn.jsdelivr.net].freeze | ||
STYLE_SRC = %w[https://bootswatch.com https://cdn.jsdelivr.net].freeze | ||
|
||
configure :production do | ||
use Rack::SslEnforcer, hsts: true | ||
end | ||
|
||
## Uncomment to drop the login session in case of any violation | ||
# use Rack::Protection, reaction: :drop_session | ||
use SecureHeaders::Middleware | ||
|
||
SecureHeaders::Configuration.default do |config| | ||
config.cookies = { | ||
secure: true, | ||
httponly: true, | ||
samesite: { | ||
strict: true | ||
} | ||
} | ||
|
||
config.x_frame_options = 'DENY' | ||
config.x_content_type_options = 'nosniff' | ||
config.x_xss_protection = '1' | ||
config.x_permitted_cross_domain_policies = 'none' | ||
config.referrer_policy = 'origin-when-cross-origin' | ||
|
||
# note: single-quotes needed around 'self' and 'none' in CSPs | ||
# rubocop:disable Lint/PercentStringArray | ||
config.csp = { | ||
report_only: false, | ||
preserve_schemes: true, | ||
default_src: %w['self'], | ||
child_src: %w['self'], | ||
connect_src: %w[wws:], | ||
img_src: %w['self'], | ||
font_src: %w['self'] + FONT_SRC, | ||
script_src: %w['self'] + SCRIPT_SRC, | ||
style_src: %W['self'] + STYLE_SRC, | ||
form_action: %w['self'], | ||
frame_ancestors: %w['none'], | ||
object_src: %w['none'], | ||
block_all_mixed_content: true, | ||
report_uri: %w[/security/report_csp_violation] | ||
} | ||
# rubocop:enable Lint/PercentStringArray | ||
end | ||
|
||
route('security') do |routing| | ||
# POST security/report_csp_violation | ||
routing.post 'report_csp_violation' do | ||
App.logger.warn "CSP VIOLATION: #{request.body.read}" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ html | |
/ Themed Bootstrap CSS (Cerulean Theme) - see bootswatch.com for more themes | ||
/ - default Bootstrap CSS: https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css | ||
link rel="shortcut icon" href="#" | ||
link rel="stylesheet" href="https://bootswatch.com/5/cerulean/bootstrap.min.css" integrity="sha384-QIHD79FAZ7/24rhhTveEfwJuiAeoPTOQpcVTWsfuPqh3JhPaV6LW8H0cTshmT0Jn" crossorigin="anonymous" | ||
link rel="stylesheet" href="https://bootswatch.com/5/cerulean/bootstrap.min.css" integrity="sha384-6PpWmaLt7GOhVYBzVUBXgwhaV2S6iHthYodyuX2lCQlqAmt6RHXOh+wbLF6hunfO" crossorigin="anonymous" | ||
link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/FortAwesome/[email protected]/css/all.min.css" integrity="sha384-SZXxX4whJ79/gErwcOYf+zWLeJdY/qpuqC4cAa9rOGUstPomtqpuNWT9wdPEn2fk" crossorigin="anonymous" | ||
|
||
/ Custom CSS | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters