Skip to content

rack-protection: change authenticity_param default to rack_csrf default #1778

Closed

Description

@HoneyryderChuck

The Authenticity Token layer aims at being rack_csrf compatible. However, its default for the form param ("authenticity_token") does not match with rack_csrf default ("_csrf").

I think this should be fixed, given that latest omniauth relies on it, and the default experience for non-rails apps (which requires a separate gem anyway, not depending on rack-protection) breaks.

Activity

  1. jkowens commented on May 10, 2022

    @jkowens
    Member

    I think this should be fixed, given that latest omniauth relies on it, and the default experience for non-rails apps (which requires a separate gem anyway, not depending on rack-protection) breaks.

    Could you elaborate?

  2. jkowens commented on May 10, 2022

    @jkowens
    Member

    It will be unlikely we'll change a long standing default. I don't think it's the form param that will matter for rack_csrf compatability, it's the session key which defaults to :csrf . In case it is helpful, the Omniauth authenticity token protection can be configured:

    OmniAuth.config.request_validation_phase = OmniAuth::AuthenticityTokenProtection.new(key: :_csrf)
    
  3. HoneyryderChuck commented on May 10, 2022

    @HoneyryderChuck
    ContributorAuthor

    I don't think it's the form param that will matter for rack_csrf compatability, it's the session key which defaults to :csrf

    That one also seems to be wrong :)

    So, both the :key and the :authenticity_param are important when verifying the csrf token from a POST form request (they both have to match).

    If rack-protection advertises rack_csrf, it should at least follow mainline. I'm not sure if keeping the default holds as an argument if the default does not reduce friction.

    FWIW this is my workaround:

    OmniAuth::AuthenticityTokenProtection.default_options(key: "csrf.token", authenticity_param: "_csrf")
  4. jkowens commented on May 10, 2022

    @jkowens
    Member

    Nice that looks even better for setting those options. I think the rack-protection documentation means to imply that it is compatible with rack_csrf in that you can configure it to use the same param names. If that needs to be made more clear, please feel free to update the documentation in a PR.

  5. HoneyryderChuck commented on May 10, 2022

    @HoneyryderChuck
    ContributorAuthor

    I think the rack-protection documentation means to imply that it is compatible with rack_csrf in that you can configure it to use the same param names.

    I'd hardly call that compatible, seems more like "it may incidentally works if you do 1 and 2". As an example of what means to be compatible, here's roda csrf plugin.

    While I understand that there may be concerns about changing this and instead removing compatibility claims, I think there's a lost opportunity for reducing friction for newcomers, given the prevalence of omniauth as a SSO solution, and its reliance on rack-protection. It took me the better part of a day to dig through this and find what the cause was, and I work with ruby for many years. I can imagine someone setting up sinatra, rack_csrf and omniauth to quickly prototype smth only to find out nothing works and moving on to something else.

    I'll close this, as it seems it's only me who finds this an issue.

  6. jkowens commented on May 10, 2022

    @jkowens
    Member

    As a maintainer of sinatra and rack-protection I have think you'd see why we wouldn't change our defaults for another library. It could potentially create a lot more problems. The beauty of open source is that you can create plugins that help automate configurations between libraries if you so please. Or you can support the community by improving documentation.

    If the language that it is compatible is confusing I'm ok with removing it all together. It was probably "more" compatible when it was first written many years ago.

  7. added a commit that references this issue on May 16, 2022
    074d2ce
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions