Skip to content

Filtering CSP entries to prevent bypassing rules #418

Closed
@mvgijssel

Description

@mvgijssel

Consider the following Rails controller action which overwrites the frame ancestors based on some user input:

def show
  user_input_domain1 = URI.parse "https://google.com;script-src"
  user_input_domain2 = URI.parse "https://*;.;"
  user_input_domains = [user_input_domain1, user_input_domain2]

  override_content_security_policy_directives(frame_ancestors: whitelisted_domains)
end

This results into the following response header:

frame-ancestors: https://google.com;script-src *;

This shows unexpected output, because by setting the frame ancestors the user is able to change the script-src opening possibilities for XSS.

One solution to this would be to filter out the CSP rules inside of specific CSP rules:

frame_ancestor = value.gsub('script-src','').gsub('img-src', '')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions