Skip to content

Replace Hashie::Mash with a small Hash-based KeyStore #1173

Description

@sferik

OmniAuth depends on Hashie only for Hashie::Mash. OmniAuth::KeyStore subclasses it, and so do OmniAuth::AuthHash, AuthHash::InfoHash, and Strategy::Options. That dependency has cost us a fair amount over the years:

#773 proposed dropping Hashie in 2014, replacing it with an OpenStruct-based class. @mbleigh pointed out that this needs a major version, because apps and strategies treat these objects as hash-like Mashes. @schneems agreed that a struct copying Mash wasn't the right replacement. This issue is the v3 follow-up.

Proposal

Make OmniAuth::KeyStore a small Hash subclass, with no Hashie, that keeps the access patterns apps and strategies actually use:

  • Method access, including chaining: auth.info.email, auth.credentials.token, options.client_options.site, and options.foo = 'bar'. A missing key returns nil.
  • Predicate methods: info.email?, options.skip_info?, and uid? all return !!value.
  • Indifferent keys: keys are stored as strings, so auth[:info], auth['info'], fetch(:uid), key?(:uid), dig(:info, :email), and so on are all equivalent.
  • Nested conversion: hashes assigned anywhere inside, including inside arrays, become KeyStores, so chaining works all the way down. AuthHash#info= still produces an InfoHash.
  • What OmniAuth itself needs:
    • merge and merge!/update, plus deep_merge and deep_merge!, which strategies use for options.
    • Deep dup, so each strategy instance gets its own options.
    • select, reject, slice, and except that keep the class.
    • to_hash (optionally with symbolize_keys: true) that converts back to plain nested Hashes.

Everything else Mash offers would go away:

  • Hashie::Mash in the ancestry, so is_a?(Hashie::Mash) becomes false.
  • Bang and underscore readers such as foo! and foo_.
  • Mash's default values and blocks.
  • Its extensions, its load method, and KeyStore.override_logging.

Plan

  1. Build it on a drop-hashie branch.
  2. Run the same downstream suites we use before releases against it: omniauth-oauth2, google-oauth2, github, saml, facebook, identity, rails_csrf_protection, and Devise. That shows what actually breaks.
  3. Decide from those results whether anything needs a deprecation in a 2.x release first, for example a warning when a Hashie::Mash-only method is called.

Activity

  1. added this to the v3 milestone on Oct 21, 2026
  2. added theissue type on Oct 21, 2026
  3. sferik commented on Oct 21, 2026

    @sferik
    ContributorAuthor

    There's a first implementation on the drop-hashie branch (2d871f0). KeyStore is now a plain Hash subclass of about 150 lines, and the hashie dependency is gone. It does everything listed above and drops the rest.

    • Specs: OmniAuth's specs pass on Rack 2 and Rack 3, and on Ruby 2.6 with and without frozen string literals. Line, branch, and method coverage is 100%.
    • Mutation testing: mutant kills all 5,028 mutations.
    • Types: Steep strict passes with the updated sig/omniauth.rbs.

    Downstream suites

    These ran against the branch, with the same counts as against master:

    Gem Result
    omniauth-oauth2 25 examples, 0 failures
    omniauth-google-oauth2 196 examples, 0 failures
    omniauth-github 23 examples, 0 failures
    omniauth-saml 80 examples, 0 failures
    omniauth-facebook 76 runs, 0 failures
    omniauth-rails_csrf_protection 5 runs, 0 failures
    devise (full suite) 878 runs, 0 failures
    omniauth-identity (Rack 2) 130 examples, 0 failures

    Notes:

    • Gone completely: saml, rails_csrf_protection, and identity no longer load Hashie at all. None of them was relying on OmniAuth to pull it in.
    • Still loaded elsewhere: the oauth2-based gems still load Hashie through oauth2 → snaky_hash. Even there, AuthHash no longer has Hashie::Mash among its ancestors.
    • No Mash-specific code: none of these gems mentions Hashie, Mash, deep_fetch, or override_logging. The one KeyStore-specific call they make is to_hash(symbolize_keys: true) (omniauth-oauth2, google-oauth2), and that still works.

    The limitation is that this only covers what these suites exercise. Less popular strategies, and app code, may still use bang readers, is_a?(Hashie::Mash), or other Mash methods. Before v3, we could ship a 2.x release that keeps Mash but warns whenever something calls a method KeyStore won't have.

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

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions