Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blacklist "original_script_name" get param #1020

Merged
merged 1 commit into from May 16, 2020

Conversation

viseztrance
Copy link
Contributor

@viseztrance viseztrance commented Apr 21, 2020

I was looking over the source code, and I noticed that the get param black list was incomplete. Passing the original_script_name param will redirect to other domains.

@amatsuda amatsuda merged commit 674aeec into kaminari:master May 16, 2020
@dee-see
Copy link

dee-see commented May 20, 2020

Hi @amatsuda, given that this has security implications, would you consider a 1.2.1 release that contains this fix? Thanks!

@olliebennett
Copy link

The changelog suggests this corresponds to CVE-2020-11082. Is that still to be published?

Are any more details available explaining the potential impact of this?

I see mention of original_script_name in Rails' UrlFor module, but little context or documentation.

Thanks

@hsbt
Copy link
Collaborator

hsbt commented May 28, 2020

@olliebennett see GHSA-r5jw-62xg-j433

@JamesChevalier
Copy link

Is there a workaround that will work with version 0.17.0?
It doesn't appear that PARAM_KEY_EXCEPT_LIST is defined in that version of the gem.

https://github.com/kaminari/kaminari/blob/0-17-stable/lib/kaminari/helpers/tags.rb#L1-L15

@utkarsh2102
Copy link

Same question as above for 0.16.0^
Is it even affected?

CC: @amatsuda, @yuki24, @hsbt

@yuki24
Copy link
Member

yuki24 commented May 31, 2020

For those of you who are still using a version below 1.0.0, please use the following patch to mitigate the security risk:

# config/initializers/kaminari.rb
module KaminariSecurityPatch
  prepend_features Kaminari::Helpers::Tag

  PARAM_KEY_DENIED_LIST = %w[ authenticity_token commit utf8 method script_name original_script_name ].freeze

  def page_url_for(page)
    params = @params
               .merge(@param_name => (page <= 1 ? nil : page), only_path: true)
               .except(*PARAM_KEY_DENIED_LIST)

    @template.url_for(params)
  end
end

Edit: The script has been updated to use string keys as @params has string keys, not symbol keys. Thanks to @JamesChevalier for pointing that out.

@utkarsh2102
Copy link

You're awesome, thanks! ❤️

@JamesChevalier
Copy link

Seems like @params is a Hash with string keys, so the except(*PARAM_KEY_DENIED_LIST) didn't find/remove :original_script_name because it existed in the hash as "original_script_name"

I think I have two options to adjust your code:

Change the constant:

PARAM_KEY_DENIED_LIST = ["authenticity_token", "commit", "utf8", "_method", "script_name", "original_script_name"].freeze

Or symbolize the keys:

params = @params.merge(@param_name => (page <= 1 ? nil : page), only_path: true).symbolize_keys.except(*PARAM_KEY_DENIED_LIST)

Thanks!

@yuki24
Copy link
Member

yuki24 commented Jun 1, 2020

@JamesChevalier Thanks for pointing that out. You are right that they are in fact string objects. We should use string keys as symbols could exhaust the GC in versions older than 2.2. I have just updated the snippet above.

esparta added a commit to esparta/rubygems.org that referenced this pull request Jun 17, 2020
Kaminari released version 1.2.1 fixing CVE-2020-11082, where an attacker
would be eable to inject arbitrary code into pages with pagination
links. Proof:

kaminari/kaminari#1020
https://my.diffend.io/gems/kaminari/1.2.0/1.2.1

The changes for Kaminari 1.2.1 makes the patching on the
config/initializer/kaminari_config.rb not longer needed.
esparta added a commit to esparta/rubygems.org that referenced this pull request Jun 17, 2020
Kaminari released version 1.2.1 fixing CVE-2020-11082, where an attacker
would be able to inject arbitrary code into pages with pagination
links. Proof:

kaminari/kaminari#1020
https://my.diffend.io/gems/kaminari/1.2.0/1.2.1

The changes for Kaminari 1.2.1 makes the patching on the
config/initializer/kaminari_config.rb not longer needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants