program story

레일 3에서 CSRF 토큰 끄기

inputbox 2020. 8. 21. 07:40
반응형

레일 3에서 CSRF 토큰 끄기


iPhone 응용 프로그램에 일부 API를 제공하는 레일 앱이 있습니다. 올바른 csrf 토큰을 얻지 않고 리소스에 간단히 게시 할 수 있기를 원합니다. 여기 stackoverflow에서 볼 수있는 몇 가지 방법을 시도했지만 더 이상 레일 3에서 작동하지 않는 것 같습니다. 도와 주셔서 감사합니다.


CSRF를 비활성화하려는 컨트롤러에서 다음을 확인하십시오.

skip_before_action :verify_authenticity_token

또는 몇 가지 방법을 제외한 모든 항목에 대해 비활성화하려면 :

skip_before_action :verify_authenticity_token, :except => [:update, :create]

또는 지정된 방법 만 비활성화하려면 :

skip_before_action :verify_authenticity_token, :only => [:custom_auth, :update]

추가 정보 : RoR 요청 위조 방지


Rails3에서는 컨트롤러에서 특정 메소드에 대해 csrf 토큰을 비활성화 할 수 있습니다.

protect_from_forgery :except => :create 

레일 4, 당신은 지금 쓸 수있는 옵션이 skip_before_action대신을 skip_before_filter.

# Works in Rails 4 and 5
skip_before_action :verify_authenticity_token

또는

# Works in Rails 3 and 4 (deprecated in Rails 4 and removed in Rails 5)
skip_before_filter :verify_authenticity_token

참고 URL : https://stackoverflow.com/questions/5669322/turn-off-csrf-token-in-rails-3

반응형