Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class AccountsController < ApplicationController

rescue_from ActionController::ParameterMissing, with: :handle_parameter_missing

# Prevent clickjacking (CWE-1021): block account pages from being embedded in external iframes.
# Uses after_action (not content_security_policy DSL) so it runs even when a before_action redirects.
after_action :set_clickjacking_headers

Comment thread
Niharika1117 marked this conversation as resolved.
def index
@cbp_map = PeopleDecorator.new(@people).commits_by_project_map
@positions_map = Position.where(id: @cbp_map.values.map(&:first).flatten)
Expand Down Expand Up @@ -93,6 +97,15 @@ def settings; end

private

def set_clickjacking_headers
response.headers['X-Frame-Options'] = 'SAMEORIGIN'
if (policy = request.content_security_policy)
modified = policy.clone
modified.frame_ancestors :self
request.content_security_policy = modified
end
end

def find_claimed_people
total_entries = params[:query].blank? ? Person::Count.claimed : nil
@people = Person.find_claimed(params[:query], params[:sort])
Expand Down
25 changes: 25 additions & 0 deletions config/initializers/clearance_session_security.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

# CWE-1021: Prevent clickjacking on session pages.
#
# GET /sessions/new and DELETE /sessions are routed directly to
# Clearance::SessionsController (bypassing our SessionsController subclass),
# so security headers are added here via to_prepare, which re-runs on every
# code reload in development and once at boot in production.
Rails.application.config.to_prepare do
Clearance::SessionsController.class_eval do
# Uses after_action (not content_security_policy DSL) so it runs even when a before_action redirects.
after_action :set_clickjacking_headers_on_session

private
Comment thread
Niharika1117 marked this conversation as resolved.

def set_clickjacking_headers_on_session
response.headers['X-Frame-Options'] = 'SAMEORIGIN'
if (policy = request.content_security_policy)
modified = policy.clone
modified.frame_ancestors :self
request.content_security_policy = modified
end
end
end
end
Loading