Skip to content

Source Deduplication Doesn't Take Schemes into Account #317

Closed

Description

@belenko

SecureHeaders excessively deduplicates sources without taking schemes into account leading to removal of sources that shouldn't be removed.

I think the problem is with dedup_source_list() which relies on filesystem-like matching.

Expected Header

Content-Security-Policy: default-src 'self' wss://ws.contoso.com *.contoso.com

Actual Header

Content-Security-Policy: default-src 'self' *.contoso.com

Config

SecureHeaders::Configuration.default do |config|
  config.csp = {
    preserve_schemes: true, # this line doesn't matter, actually
    default_src: %w('self' wss://ws.contoso.com *.contoso.com)
  }
end

Activity

  1. oreoshake commented on Mar 1, 2017

    @oreoshake
    Contributor

    Welp. I'm assuming that policy mangling means your CSP is breaking functionality. The * should only apply to http/https schemes.

  2. belenko commented on Mar 1, 2017

    @belenko
    Author

    As a workaround we currently settled on %w('self' wss://*.contoso.com *.contoso.com) which works as expected, so not a deal breaker for us (though had to spend some time to figure out who eats that wss:// source :) )

  3. oreoshake commented on Mar 1, 2017

    @oreoshake
    Contributor

    I've never been a fan of the deduplication based on * anyways. Maybe we should just rip that out.

  4. oreoshake commented on Mar 1, 2017

    @oreoshake
    Contributor

    Like people trying to save a few bytes can optimize elsewhere.

  5. added a commit that references this issue on Jun 1, 2022
  6. srt32 commented on Jun 1, 2022

    @srt32
    Member

    This should be resolved by #478

  7. lgarron commented on Jan 3, 2023

    @lgarron
    Contributor

    Source deduplication was removed in #499

    Expected Header

    Content-Security-Policy: default-src 'self' wss://ws.contoso.com *.contoso.com

    I've confirmed that this is the case.

    We also have a very similar test to prevent a regression:

    csp = ContentSecurityPolicy.new(default_src: %w(*.example.org wss://example.example.org))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions