What happens: When the user views a form to create, update, or destroy a resource, the rails app would create a random authenticity_token, store this token in the session, and place it in a hidden field in the form. When the user submits the form, rails would look for the authenticity_token, compare it to the one stored in the session, and if they match the request is allowed to continue. Why this happens: Since the authenticity token is stored in the session, the client can not know its value. This prevents people from submitting forms to a rails app without viewing the form within that app itself. Imagine that you are using service A, you logged into the service and everything is ok. Now imagine that you went to use service B, and you saw a picture you like, and pressed on the picture to view a larger size of it. Now, if some evil code was there at service B, it might send a request to service A (which you are logged into), and ask to delete your account, by sending a request tohttp://service%5FA.com/close%5Faccount. This is what is known as CSRF (Cross Site Request Forgery). If service A is using authenticity tokens, this attack vector is no longer applicable, since the request from service B would not contain the correct authenticity token, and will not be allowed to continue. Notes: Keep in mind, rails only checks POST, PUT, and DELETE requests. GET request are not checked for authenticity token. Why? because the HTTP specification states that GET requests should NOT create, alter, or destroy resources at the server, and the request should be idempotent (if you run the same command multiple times, you should get the same result every time). Lessons: Use authenticity_token to protect your POST, PUT, and DELETE requests. Also make sure not to make any GET requests that could potentially modify resources on the server.
发表评论
-
12.3.3 scaling issue of the status feed
2011-10-30 17:54 831the problem of the implementati ... -
12.3 the status feed
2011-10-30 15:34 8691. we need to get all the micro ... -
12.2 a working follow button with Ajax
2011-10-29 18:10 9221. in the last chapter, in the ... -
12.2 a web interface for following and followers.
2011-10-28 22:14 8911.before we do the UI, we need ... -
12. following user, 12.1 relationship model
2011-10-18 14:29 7611. we need to use a relationshi ... -
11.3 manipulating microposts.
2011-10-17 15:31 9091. since all micropost actions ... -
11.2 show microposts.
2011-10-17 12:01 7121. add test to test the new use ... -
11.1 user micropost -- a micropost model.
2011-10-17 10:43 11181. we will first generate a mic ... -
10.4 destroying users.
2011-10-16 15:47 756in this chapter, we will add de ... -
10.3 showing users list
2011-10-15 20:41 785in this chapter, we will do use ... -
10.2 protect pages.
2011-10-15 15:11 678again, we will start from TD ... -
10.1 updating users.
2011-10-14 18:30 7181. git checkout -b updating-use ... -
9.4 sign out
2011-10-13 15:21 745whew!!!, last chapter is a long ... -
9.3 sign in success.
2011-10-12 15:39 7601. we will first finish the cre ... -
9.1 about flash.now[:error] vs flash[:error]
2011-10-12 15:37 737There’s a subtle difference ... -
9.2 sign in failure
2011-10-12 12:19 671start from TDD!!! 1. requir ... -
9.1 sessions
2011-10-12 10:00 651a session is a semi-permanent c ... -
what test framework should you use?
2011-10-11 16:56 0for integration test, i have no ... -
what test framework should you use?
2011-10-11 16:56 0<p>for integration test, ... -
8.4 rspec integration tests
2011-10-11 16:53 735in integration test, you can te ...
相关推荐
Advanced Rails,英文版,一本关于Rails的好书!
RailsOnUbuntu 对于使用Ubuntu的Ruby on Rails开发人员的一些有用的脚本/好东西! 1. Rails安装程序 为了在Ubuntu 12.04 LTS(精确的穿山甲)/ 12.10(定量Quetzal)上设置Rails,我还为初学者编写了逐步指南,请...
在Ruby on Rails的世界里,"我的第一个Rails应用程序"是一次典型的初学者之旅,它涵盖了创建、配置、开发和部署一个基本的Web应用的基本步骤。RailsApps项目是一个宝贵的资源,为新手提供了一系列逐步教程,帮助他们...
Rails表单变得容易。 简单表单旨在在帮助您使用功能强大的组件创建表单的同时尽可能地灵活。 Simple Form的基本目标是不触及定义布局的方式,而是让您为眼睛找到更好的设计。 大多数DSL都是从Formtastic继承的,...
在Ruby on Rails的世界里,"rails-hello-world-app"是一个典型的初学者项目,它帮助新手快速熟悉Rails框架的基本结构和工作原理。这个"我的第一个Rails应用程序"是Ruby on Rails教程的一部分,旨在引导开发者构建...
幕后花絮RailsBump使用几种方法来检查gem版本是否与特定的Rails版本兼容: 如果gem版本直接依赖于“ Rails gems”之一(rails,railties,activerecord,activesupport等),则可能很明显它与某些Rails版本不立即...
与针对Rails的最有效。 :waving_hand: 该库已重命名为Angular-Token ! 请遵循。 快速链接 :rocket: 查看关于演示 :sparkles: 在上了解 :wrench: 通过支持我们 安装 使用设置Rails 通过NPM通过以下方式安装...
RUBY RAILS INSTALLRUBY RAILS INSTALLRUBY RAILS INSTALL The Best Ruby Rails Server!
标题中的“让你的Dreamweaver也支持Rails!”表明了这个话题是关于如何在Adobe Dreamweaver这款流行的Web开发工具中集成Ruby on Rails框架的支持。Rails是Ruby编程语言的一个开源框架,用于快速、简洁地构建动态网站...
Eight different test-driven tutorials will help you understand Rails' inner workings and prepare you to tackle complicated projects with solutions that are well-tested, modular, and easy to maintain....
Ruby on Rails,通常简称为Rails,是一个基于Ruby编程语言的开源Web应用框架,遵循MVC(Model-View-Controller)架构模式。这个“Rails项目源代码”是一个使用Rails构建的图片分享网站的完整源代码,它揭示了如何...
《Rails101_by_rails4.0》是一本专注于Rails 4.0.0版本和Ruby 2.0.0版本的自学教程书籍,它定位于中文读者,旨在成为学习Rails框架的参考教材。Rails(Ruby on Rails)是一个采用Ruby语言编写的开源Web应用框架,它...
Rails 3.1 和 Cucumber-Rails 1.2.0 是两个在Web开发领域非常重要的工具,尤其对于Ruby on Rails框架的测试和自动化流程。本文将深入探讨这两个组件,以及它们如何协同工作来增强软件开发的效率和质量。 首先,...
Ruby on Rails(简称RoR或Rails)是一种基于Ruby语言的开源Web应用框架,它遵循Model-View-Controller(MVC)架构模式,旨在使Web开发更简洁、高效。本实例将帮助你深入理解和实践Rails的开发流程。 首先,让我们从...
SassC :: Rails 我们都喜欢使用Sass,但是对于较大的代码库,编译可能需要很长时间。 该gem将Sass的C实现集成到资产管道中。 在一个较大的项目中,这使编译速度提高了4倍: # Using sassc-rails[1] pry(main)> ...
Rails指南中文版是针对Ruby on Rails框架的一份详尽教程,旨在帮助开发者深入理解并熟练掌握这个强大的Web应用开发工具。Ruby on Rails(简称Rails)是一个基于Ruby语言的开源Web应用框架,它遵循MVC(Model-View-...
从给定的文件信息来看,我们正在探讨的是一本关于Ruby on Rails的书籍,书名为《Simply Rails2》,作者是Patrick Lenz。本书旨在为初学者提供深入理解Ruby on Rails框架的指南,从基础概念到高级主题均有涵盖,是...
Slackr是由Rails和React / Redux开发的Slack的Web应用程序克隆。 功能与实现 用户认证 slackr允许用户使用BCrypt实施安全地登录/注销,以根据用户密码生成加盐的哈希值,因为此类用户的密码未存储在数据库中。 此外...