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

Broken in Ember-CLI 0.2.2? #20

Closed
krzkrzkrz opened this Issue Apr 1, 2015 · 12 comments

Comments

Projects
None yet
5 participants
@krzkrzkrz

krzkrzkrz commented Apr 1, 2015

I've upgraded to Ember-CLI 0.2.2.

I am following the readme at https://github.com/abuiles/rails-csrf. i.e.

Add a meta tag like the following to your app body and the addon will do the rest:
<meta content="adfadfadsfi34/sdfadfadf=" name="csrf-token">

I refresh the page, the meta tag's content value does not change to anything. As if the plugin isn't working. I also don't see the any api attempts to the csrf api endpoint. The network tab of Ember Inspector doesn't show anything relative.

Is the readme missing a step?

@skanderm

This comment has been minimized.

Show comment
Hide comment
@skanderm

skanderm Apr 8, 2015

Same problem here. This is also with 0.2.2.

skanderm commented Apr 8, 2015

Same problem here. This is also with 0.2.2.

@skanderm

This comment has been minimized.

Show comment
Hide comment
@skanderm

skanderm Apr 9, 2015

@krzkrzkrz The addon seems to assume that the meta tag is actually provided in your Rails template via <%= csrf_meta_tags %> and no longer makes a call to a /csrf endpoint. You probably need to downgrade to a previous version to get that functionality again.

Also, https://www.npmjs.com/package/rails-csrf seems out of date.

skanderm commented Apr 9, 2015

@krzkrzkrz The addon seems to assume that the meta tag is actually provided in your Rails template via <%= csrf_meta_tags %> and no longer makes a call to a /csrf endpoint. You probably need to downgrade to a previous version to get that functionality again.

Also, https://www.npmjs.com/package/rails-csrf seems out of date.

@e-fu

This comment has been minimized.

Show comment
Hide comment
@e-fu

e-fu Apr 11, 2015

btw, <%= csrf_meta_tags %> output is similar to:

e-fu commented Apr 11, 2015

btw, <%= csrf_meta_tags %> output is similar to:

@krzkrzkrz

This comment has been minimized.

Show comment
Hide comment
@krzkrzkrz

krzkrzkrz Apr 15, 2015

@skanderm if the addon assumes that the meta tag is included in a Rails template. How is that even possible if one is using Ember CLI (Single Page Application), where the client handles all of the "templates/views" and Rails just acts as an API.

For single page applications, should we just query the API for the csrf token?

krzkrzkrz commented Apr 15, 2015

@skanderm if the addon assumes that the meta tag is included in a Rails template. How is that even possible if one is using Ember CLI (Single Page Application), where the client handles all of the "templates/views" and Rails just acts as an API.

For single page applications, should we just query the API for the csrf token?

@skanderm

This comment has been minimized.

Show comment
Hide comment
@skanderm

skanderm Apr 15, 2015

@krzkrzkrz Yeah, I went back to doing that, I'm back to v1.0.1 now.

skanderm commented Apr 15, 2015

@krzkrzkrz Yeah, I went back to doing that, I'm back to v1.0.1 now.

@samjulien

This comment has been minimized.

Show comment
Hide comment
@samjulien

samjulien Apr 17, 2015

I'm in the middle of this same problem. @krzkrzkrz, how are you querying the API for the csrf token? @skanderm, did you go back to v.1.0.1 of rails-csrf? Thanks!

samjulien commented Apr 17, 2015

I'm in the middle of this same problem. @krzkrzkrz, how are you querying the API for the csrf token? @skanderm, did you go back to v.1.0.1 of rails-csrf? Thanks!

@skanderm

This comment has been minimized.

Show comment
Hide comment
@skanderm

skanderm Apr 17, 2015

Yep @samjulien, on v1.0.1. You can create a /csrf endpoint on your API that looks like

class CsrfController < ApplicationController
  def index
    render json: { request_forgery_protection_token => form_authenticity_token }.to_json
  end
end

Check out the previous versions of the readme.

skanderm commented Apr 17, 2015

Yep @samjulien, on v1.0.1. You can create a /csrf endpoint on your API that looks like

class CsrfController < ApplicationController
  def index
    render json: { request_forgery_protection_token => form_authenticity_token }.to_json
  end
end

Check out the previous versions of the readme.

@samjulien

This comment has been minimized.

Show comment
Hide comment
@samjulien

samjulien Apr 17, 2015

@skanderm Is there something different I need to do in app.js to load the initializer or import rails-csrf? I'm getting Error while processing route: index Cannot read property 'fetchToken' of undefined TypeError: Cannot read property 'fetchToken' of undefined when I try to load the page.

All I've done in app.js is what the readme recommended (in addition to what was already there):

loadInitializers(App, config.modulePrefix, 'rails-csrf');

Thanks in advance!

samjulien commented Apr 17, 2015

@skanderm Is there something different I need to do in app.js to load the initializer or import rails-csrf? I'm getting Error while processing route: index Cannot read property 'fetchToken' of undefined TypeError: Cannot read property 'fetchToken' of undefined when I try to load the page.

All I've done in app.js is what the readme recommended (in addition to what was already there):

loadInitializers(App, config.modulePrefix, 'rails-csrf');

Thanks in advance!

@skanderm

This comment has been minimized.

Show comment
Hide comment
@skanderm

skanderm Apr 17, 2015

@samjulien Maybe try it in its own call after the first?

loadInitializers(App, config.modulePrefix);
loadInitializers(App, 'rails-csrf');

skanderm commented Apr 17, 2015

@samjulien Maybe try it in its own call after the first?

loadInitializers(App, config.modulePrefix);
loadInitializers(App, 'rails-csrf');
@samjulien

This comment has been minimized.

Show comment
Hide comment
@samjulien

samjulien Apr 21, 2015

@skanderm forgot to thank you for this - rails-csrf is working, just gotta wrestle with rack now. Cheers!

samjulien commented Apr 21, 2015

@skanderm forgot to thank you for this - rails-csrf is working, just gotta wrestle with rack now. Cheers!

@krzkrzkrz

This comment has been minimized.

Show comment
Hide comment
@krzkrzkrz

krzkrzkrz Apr 28, 2015

@samjulien at this point, I dont think querying the API for a csrf token is the best approach. It leaves the application vulnerable

krzkrzkrz commented Apr 28, 2015

@samjulien at this point, I dont think querying the API for a csrf token is the best approach. It leaves the application vulnerable

@abuiles

This comment has been minimized.

Show comment
Hide comment
@abuiles

abuiles Apr 28, 2015

Owner

As @krzkrzkrz mentioned, querying the API is not recommended because of possible vulnerabilities, the recommended way is to disable CSRF in dev and then enable in production and make sure you inject the CSRF token in the body when booting up the app

Owner

abuiles commented Apr 28, 2015

As @krzkrzkrz mentioned, querying the API is not recommended because of possible vulnerabilities, the recommended way is to disable CSRF in dev and then enable in production and make sure you inject the CSRF token in the body when booting up the app

@abuiles abuiles closed this Apr 28, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment