Search results

'ActionController::InvalidAuthenticityToken'에 해당하는 글들

  1. 2008/07/10  [에러잡기] ActionController::InvalidAuthenticityToken (1)

[에러잡기] 레일스와 함께하는 애자일 웹 개발 in Rails 2.0.2

[8 장 태스크C : 장바구니 생성]에서 Rails 2.0.2를 사용하는 경우 발생하는 문제점에 대한 정리와 해결책 입니다.

발생 경위

/config/environment.rb file 42 line <책 132p>

# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with 'rake db:sessions:create')

config.action_controller.session_store = :active_record_store

데이터베이스에서 세션 두기 항목에서 세션정보의 저장소를 데이터 베이스로 지정하는 과정에서
위의 빨간부분만 주석처리를 제거할 것을 지시하고 있습니다. 책을 따라갈 경우 아래와 같은 에러 메세지를 만날 수 있습니다.
 
ActionController::InvalidAuthenticityToken

No :secret given to the #protect_from_forgery call.  Set that or use a session store capable of generating its own keys (Cookie Session Store).

비밀이 위조로부터 보호라는 요청을 했다. 가 되나요? 여기서 secret은 비밀이 아니라 secret이라는 객체를 뜻하는 것 같습니다.

해결책

이 부분은 /config/enviroment.rb 에서 해결책을 찾을 수 없고, /app/controllers/application.rb 에서 답을 찾을 수 있습니다. 몇줄안 되는 소스인데 뒤져보면 secret에 관한 주석을 찾을 수 있습니다.

/app/controllers/application.rb file 7 line

# See ActionController::RequestForgeryProtection for details
# Uncomment the :secret if you're not using the cookie session store
protect_from_forgery
  :secret => '8c0e411f8a0da1fd5e01bd72a0c3f4b7'

당신이 쿠키 세션 저장소를 사용하고 있지 않다면 :secret의 사용을 추천하지 않는다. 쿠키 세션 저장소를 사용하고 있지 않다면 :secret의 주석을 없애세요. 라고 하는것 같군요. 빨간 부분의 주석을 없애주면 위의 에러는 사라집니다. 영어가 짧고 ruby에 대한 이해도 짧은 터라 이해하기엔 많이 부족한 감이 있네요. 이유를 설명해 주실 수 있는 분 설명 부탁해요~! db에 들어간 세션값의 도용을 막기 위해 추가된 사항인 듯 합니다.


이올린에 북마크하기(0) 이올린에 추천하기(0)
2008/07/10 11:49 2008/07/10 11:49
openclose