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

Add CSRF protection in entire application - Long term project #744

Open
lalithr95 opened this issue Aug 28, 2016 · 4 comments
Open

Add CSRF protection in entire application - Long term project #744

lalithr95 opened this issue Aug 28, 2016 · 4 comments
Labels
help wanted requires help by anyone willing to contribute Ruby

Comments

@lalithr95
Copy link
Member

lalithr95 commented Aug 28, 2016

What happened just before the problem occurred

This could be added as sub-project for next GSOC.
Most of the forms used in PublicLab doesn't contain csrf token parameter as we don't use rails form helpers form_tag form_for

It could be nice to replace <form tag with form_tag with will add csrf token automatically. Once if you can get work with one form and get it working, it would be same for other forms as well. Solving this issue could actually introduce you to different views and features of PublicLab.

Tests

As functional tests doesn't have csrf enabled. you need to add a test something like below one to test csrf protection.

  test "#generate_token ensures CSRF protection" do
    assert_raise ActionController::InvalidAuthenticityToken do
      with_forgery_protection do
        post :some_action, authenticity_token: :random
      end
  end
  private
  def with_forgery_protection
    old_value = ActionController::Base.allow_forgery_protection
    ActionController::Base.allow_forgery_protection = true
    yield
  ensure
    ActionController::Base.allow_forgery_protection = old_value
  end

PublicLab.org username

Lalithr95
(to help reproduce the issue)

cc: @jywarren

@lalithr95 lalithr95 added Ruby outreach issues involve community involvement and helping people who're stuck somewhere labels Aug 28, 2016
@jywarren
Copy link
Member

Hi, Lalith - will this be a help-wanted tag? Maybe we should add links to
CSRF token controller code. I also believe that rails.js (
https://github.com/rails/jquery-ujs) has csrf token functions built in.

Note also that a CSRF token is sent with inline image uploads on the old
system, at https://publiclab.org/post/ --

#739 shows how I'm trying to
ensure this works in the new Rich Editor as well.

On Sun, Aug 28, 2016 at 2:33 PM, Lalith Rallabhandi <
notifications@github.com> wrote:

What happened just before the problem occurred

This could be added as sub-project for next GSOC.
Most of the forms used in PublicLab doesn't contain csrf token parameter
as we don't use rails form helpers form_tag form_for

It could be nice to replace <form tag with form_tag with will add csrf
token automatically. Once if you can get work with one form and get it
working, it would be same for other forms as well. Solving this issue could
actually introduce you to different views and features of PublicLab.
Tests

As functional tests doesn't have csrf enabled. you need to add a test
something like below one to test csrf protection.

test "#generate_token ensures CSRF protection" do
assert_raise ActionController::InvalidAuthenticityToken do
with_forgery_protection do
post :some_action, authenticity_token: :random
end
end
private
def with_forgery_protection
old_value = ActionController::Base.allow_forgery_protection
ActionController::Base.allow_forgery_protection = true
yield
ensure
ActionController::Base.allow_forgery_protection = old_value
end

PublicLab.org username

Lalithr95
(to help reproduce the issue)


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#744, or mute the thread
https://github.com/notifications/unsubscribe-auth/AABfJ6SxoImyUMs0npDyKZl0sFGeFZ8eks5qkdSBgaJpZM4Ju_EV
.

@jywarren jywarren removed the outreach issues involve community involvement and helping people who're stuck somewhere label Jan 19, 2018
@grvsachdeva
Copy link
Member

@jywarren do we need this issue?

@jywarren
Copy link
Member

jywarren commented Mar 25, 2019 via email

@grvsachdeva grvsachdeva added the help wanted requires help by anyone willing to contribute label Mar 25, 2019
@stale stale bot added the stale label Oct 7, 2020
@publiclab publiclab deleted a comment from stale bot Oct 8, 2020
@stale stale bot removed the stale label Oct 8, 2020
@anirudhprabhakaran3
Copy link
Member

Isn't CSRF protection in-built to Rails?

Also, in application_controller.rb, we have

protect_from_forgery unless: -> { is_dataurl_post }

In app/views/comments/_form.html.erb, in the form we have

    <input 
      type="hidden" 
      name="authenticity_token" 
      value="<%= form_authenticity_token %>"
    />

Is this how it should be extended to other forms?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted requires help by anyone willing to contribute Ruby
Projects
None yet
Development

No branches or pull requests

4 participants