`
peryt
  • 浏览: 54440 次
  • 来自: ...
最近访客 更多访客>>
社区版块
存档分类
最新评论
  • waiting: 既然都指定了dataType为'script'那就不必特别在b ...
    jQuery

understand rails authenticity Token!

阅读更多

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.

分享到:
评论

相关推荐

    Advanced Rails

    Advanced Rails,英文版,一本关于Rails的好书!

    RailsOnUbuntu:Ubuntu用户的Rails好东西!

    RailsOnUbuntu 对于使用Ubuntu的Ruby on Rails开发人员的一些有用的脚本/好东西! 1. Rails安装程序 为了在Ubuntu 12.04 LTS(精确的穿山甲)/ 12.10(定量Quetzal)上设置Rails,我还为初学者编写了逐步指南,请...

    learn-rails:我的第一个Rails应用程序!

    在Ruby on Rails的世界里,"我的第一个Rails应用程序"是一次典型的初学者之旅,它涵盖了创建、配置、开发和部署一个基本的Web应用的基本步骤。RailsApps项目是一个宝贵的资源,为新手提供了一系列逐步教程,帮助他们...

    simple_form:简化Rails的表单! 它与简单的DSL绑定,对标记无意见

    Rails表单变得容易。 简单表单旨在在帮助您使用功能强大的组件创建表单的同时尽可能地灵活。 Simple Form的基本目标是不触及定义布局的方式,而是让您为眼睛找到更好的设计。 大多数DSL都是从Formtastic继承的,...

    rails-hello-world-app:我的第一个Rails应用程序!

    在Ruby on Rails的世界里,"rails-hello-world-app"是一个典型的初学者项目,它帮助新手快速熟悉Rails框架的基本结构和工作原理。这个"我的第一个Rails应用程序"是Ruby on Rails教程的一部分,旨在引导开发者构建...

    app:检查哪些宝石与哪个Rails版本兼容!

    幕后花絮RailsBump使用几种方法来检查gem版本是否与特定的Rails版本兼容: 如果gem版本直接依赖于“ Rails gems”之一(rails,railties,activerecord,activesupport等),则可能很明显它与某些Rails版本不立即...

    angular-token:基于令牌的Angular身份验证服务,具有拦截器和多用户支持。 与针对Rails的设计令牌身份验证效果最佳。 例:

    与针对Rails的最有效。 :waving_hand: 该库已重命名为Angular-Token ! 请遵循。 快速链接 :rocket: 查看关于演示 :sparkles: 在上了解 :wrench: 通过支持我们 安装 使用设置Rails 通过NPM通过以下方式安装...

    RUBY RAILS INSTALL

    RUBY RAILS INSTALLRUBY RAILS INSTALLRUBY RAILS INSTALL The Best Ruby Rails Server!

    让你的dreamweaver也支持rails!

    标题中的“让你的Dreamweaver也支持Rails!”表明了这个话题是关于如何在Adobe Dreamweaver这款流行的Web开发工具中集成Ruby on Rails框架的支持。Rails是Ruby编程语言的一个开源框架,用于快速、简洁地构建动态网站...

    [Rails] Crafting Rails 4 Applications (英文版)

    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....

    Rails项目源代码

    Ruby on Rails,通常简称为Rails,是一个基于Ruby编程语言的开源Web应用框架,遵循MVC(Model-View-Controller)架构模式。这个“Rails项目源代码”是一个使用Rails构建的图片分享网站的完整源代码,它揭示了如何...

    rails 2.3.2离线安装rails 2.3.2离线安装

    rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails ...

    关于rails 3.1 cucumber-rails 1.2.0

    Rails 3.1 和 Cucumber-Rails 1.2.0 是两个在Web开发领域非常重要的工具,尤其对于Ruby on Rails框架的测试和自动化流程。本文将深入探讨这两个组件,以及它们如何协同工作来增强软件开发的效率和质量。 首先,...

    Ruby On Rails开发实例-源代码

    Ruby on Rails(简称RoR或Rails)是一种基于Ruby语言的开源Web应用框架,它遵循Model-View-Controller(MVC)架构模式,旨在使Web开发更简洁、高效。本实例将帮助你深入理解和实践Rails的开发流程。 首先,让我们从...

    sassc-rails:将SassC-Ruby与Rails集成!

    SassC :: Rails 我们都喜欢使用Sass,但是对于较大的代码库,编译可能需要很长时间。 该gem将Sass的C实现集成到资产管道中。 在一个较大的项目中,这使编译速度提高了4倍: # Using sassc-rails[1] pry(main)> ...

    rails指南 中文版

    Rails指南中文版是针对Ruby on Rails框架的一份详尽教程,旨在帮助开发者深入理解并熟练掌握这个强大的Web应用开发工具。Ruby on Rails(简称Rails)是一个基于Ruby语言的开源Web应用框架,它遵循MVC(Model-View-...

    rails2-sample

    从给定的文件信息来看,我们正在探讨的是一本关于Ruby on Rails的书籍,书名为《Simply Rails2》,作者是Patrick Lenz。本书旨在为初学者提供深入理解Ruby on Rails框架的指南,从基础概念到高级主题均有涵盖,是...

Global site tag (gtag.js) - Google Analytics