Skip to content
  • Prem Sichanugrist's avatar
    5109740c
    Make `AC::Params#to_h` return Hash with safe keys · 5109740c
    Prem Sichanugrist authored
    `ActionController::Parameters#to_h` now returns a `Hash` with
    unpermitted keys removed. This change is to reflect on a security
    concern where some method performed on an `ActionController::Parameters`
    may yield a `Hash` object which does not maintain `permitted?` status.
    If you would like to get a `Hash` with all the keys intact, duplicate
    and mark it as permitted before calling `#to_h`.
    
        params = ActionController::Parameters.new(name: 'Senjougahara Hitagi')
        params.to_h # => {}
    
        unsafe_params = params.dup.permit!
        unsafe_params.to_h # => {"name"=>"Senjougahara Hitagi"}
    
        safe_params = params.permit(:name)
        safe_params.to_h # => {"name"=>"Senjougahara Hitagi"}
    
    This change is consider a stopgap as we cannot chage the code to stop
    `ActionController::Parameters` to inherit from
    `HashWithIndifferentAccess` in the next minor release.
    
    Also, adding a CHANGELOG entry to mention that
    `ActionController::Parameters` will not inheriting from
    `HashWithIndifferentAccess` in the next major version.
    5109740c
    Make `AC::Params#to_h` return Hash with safe keys
    Prem Sichanugrist authored
    `ActionController::Parameters#to_h` now returns a `Hash` with
    unpermitted keys removed. This change is to reflect on a security
    concern where some method performed on an `ActionController::Parameters`
    may yield a `Hash` object which does not maintain `permitted?` status.
    If you would like to get a `Hash` with all the keys intact, duplicate
    and mark it as permitted before calling `#to_h`.
    
        params = ActionController::Parameters.new(name: 'Senjougahara Hitagi')
        params.to_h # => {}
    
        unsafe_params = params.dup.permit!
        unsafe_params.to_h # => {"name"=>"Senjougahara Hitagi"}
    
        safe_params = params.permit(:name)
        safe_params.to_h # => {"name"=>"Senjougahara Hitagi"}
    
    This change is consider a stopgap as we cannot chage the code to stop
    `ActionController::Parameters` to inherit from
    `HashWithIndifferentAccess` in the next minor release.
    
    Also, adding a CHANGELOG entry to mention that
    `ActionController::Parameters` will not inheriting from
    `HashWithIndifferentAccess` in the next major version.
To find the state of this project's repository at the time of any of these versions, check out the tags.
Loading